-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
41 lines (30 loc) · 1.15 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Stage 1: Build stage
FROM rust:1.76-bullseye as builder
ENV CARGO_TARGET_AARCH_64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
ENV CC=aarch64-linux-gnu-gcc
RUN apt-get update && apt-get install -y \
musl-tools \
&& apt-get clean
ENV SQLX_OFFLINE true
ENV OPENSSL_STATIC=1
ENV RUSTFLASGS="-C target-feature=-crt-static"
ENV CARGO_TARGET=aarch64-unknown-linux-musl
# Set work directory inside the container
WORKDIR /usr/src/app
# Copy Cargo.toml and Cargo.lock for dependency resolution
COPY Cargo.toml Cargo.lock ./
# Pre-build dependencies to cache them for faster builds
RUN rustup target add aarch64-unknown-linux-musl
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo check --release
# Copy the actual source code
COPY . .
# Build the actual application with static linking
RUN cargo build --release --target aarch64-unknown-linux-musl
# Stage 2: Runtime stage
FROM scratch
# Copy the static binary from the build stage
COPY --from=builder /usr/src/app/target/aarch64-unknown-linux-musl/release/incosense_class /
COPY --from=builder /usr/src/app/configuration.yaml /
# Set the binary as the entry point
ENTRYPOINT ["/incosense_class"]