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 20, 2024
1 parent 054c28a commit 9715c8d
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/mk-meili-mgn target/release/mk-meili-mgn

FROM alpine:latest AS packer

RUN apk add --no-cache upx

COPY --from=builder /app/target/release/mk-meili-mgn /app/mk-meili-mgn
RUN upx --brute /app/mk-meili-mgn

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/mk-meili-mgn ./
COPY --from=packer /app/mk-meili-mgn ./
CMD ["./mk-meili-mgn"]

0 comments on commit 9715c8d

Please sign in to comment.