feat(ci): make executable static and make final image be from scratch to make container as small as possible

This commit is contained in:
DJMrTV 2025-03-07 17:19:47 +01:00
commit 3b7881a496
2 changed files with 7 additions and 8 deletions

View file

@ -1,2 +1,2 @@
[target.'cfg(target_arch = "x86_64")'] [target.'cfg(target_arch = "x86_64")']
rustflags = ["-C", "target-feature=+aes,+sse2,-crt-static"] rustflags = ["-C", "target-feature=+aes,+sse2"]

View file

@ -1,25 +1,24 @@
FROM rust:alpine as builder 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 WORKDIR /app
COPY . . 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 RUN rm .env
FROM rust:alpine AS final FROM scratch AS final
WORKDIR /app WORKDIR /app
# Copy the compiled binary from the builder stage # 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 # Set executable permissions
RUN chmod +x /app/account # RUN chmod +x /account
# Command to run the application # Command to run the application
CMD ["ls /app"] ENTRYPOINT ["/account"]
CMD ["/app/account"]