Skip to content

Commit

Permalink
static docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
caipira113 committed Mar 19, 2024
1 parent 9ac6a10 commit afef29a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ RUN cargo chef prepare --recipe-path recipe.json

FROM base AS builder

ARG TARGETPLATFORM
ARG RUSTFLAGS='-C target-feature=+crt-static'

COPY --from=planner /app/recipe.json ./
RUN cargo chef cook --release --recipe-path recipe.json
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then TARGET=x86_64-unknown-linux-gnu; elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then TARGET=aarch64-unknown-linux-gnu; fi \
&& cargo chef cook --release --target $TARGET --recipe-path recipe.json

COPY . .
RUN cargo build --release
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then TARGET=x86_64-unknown-linux-gnu; elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then TARGET=aarch64-unknown-linux-gnu; fi \
&& cargo build --release --target $TARGET \
&& cp -r target/$TARGET/release/conex target/release/conex

FROM alpine:latest AS packer

RUN apk add --no-cache upx

COPY --from=builder /app/target/release/conex /app/conex
RUN upx --brute /app/conex

FROM gcr.io/distroless/cc-debian12:nonroot AS runtime
FROM gcr.io/distroless/static-debian12:nonroot AS runtime
WORKDIR /app

COPY --from=builder /app/target/release/conex ./
COPY --from=packer /app/conex ./
CMD ["./conex"]

0 comments on commit afef29a

Please sign in to comment.