From 3b7881a49687270cd7cf0928f5fb7798e2e9ff43 Mon Sep 17 00:00:00 2001 From: DJMrTV Date: Fri, 7 Mar 2025 17:19:47 +0100 Subject: [PATCH] feat(ci): make executable static and make final image be from scratch to make container as small as possible --- .cargo/config.toml | 2 +- Dockerfile | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index b521c53..c615b9f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [target.'cfg(target_arch = "x86_64")'] -rustflags = ["-C", "target-feature=+aes,+sse2,-crt-static"] \ No newline at end of file +rustflags = ["-C", "target-feature=+aes,+sse2"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ba283ca..1641a84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,24 @@ FROM rust:alpine as builder -RUN apk add --no-cache musl-dev openssl-dev musl openssl libcrypto3 +RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static protobuf-dev lld WORKDIR /app COPY . . -RUN cargo build --profile prod +RUN OPENSSL_LIB_DIR=/usr/lib OPENSSL_INCLUDE_DIR=/usr/include/openssl OPENSSL_STATIC=1 RUSTFLAGS="-C target-feature=+aes,+sse -C relocation-model=static -C linker=ld.lld" cargo build --profile prod --target x86_64-unknown-linux-musl RUN rm .env -FROM rust:alpine AS final +FROM scratch AS final WORKDIR /app # Copy the compiled binary from the builder stage -COPY --from=builder /app/target/prod/account /app/account +COPY --from=builder /app/target/x86_64-unknown-linux-musl/prod/account /account # Set executable permissions -RUN chmod +x /app/account +# RUN chmod +x /account # Command to run the application -CMD ["ls /app"] -CMD ["/app/account"] +ENTRYPOINT ["/account"]