Add a production docker image build

This commit is contained in:
kaiyou 2023-07-13 21:29:45 +02:00
parent 000006d689
commit 1d4f2e53d6

View file

@ -1,7 +1,30 @@
FROM scratch
# This Dockerfile is meant for production use only, binaries
# are built against release targets and stripped of symbols.
# First build stage, bluntly building a release target
FROM rust:1.70.0-alpine as builder
COPY ./Cargo.toml ./Cargo.lock ./
COPY src ./src
# Copy the git repository so that git_version can properly
# guess the package version. This is not perfectly idiomatic.
COPY .git ./.git
ENV RUSTFLAGS='-C target-feature=+crt-static'
ENV FEATURES=k2v,sled,lmdb,sqlite,consul-discovery,kubernetes-discovery,metrics,telemetry-otlp,bundled-libs
ENV TARGET=x86_64-unknown-linux-musl
RUN apk add --no-cache musl-dev make git file protoc
RUN cargo fetch
RUN cargo build --release --features $FEATURES --target $TARGET \
&& mv target/$TARGET/release/garage ./garage \
&& strip ./garage
# Second clean stage just copying over the static binary
FROM scratch
ENV RUST_BACKTRACE=1
ENV RUST_LOG=garage=info
COPY --from=builder ./garage /garage
# Configuration is not included in the image and should be
# mounted as a volume. No volume is explicitely declared for
# this as there is no container-level persistence need.
CMD /garage server -c /config.toml
COPY result-bin/bin/garage /
CMD [ "/garage", "server"]