container: Build static executable
dustin/tmpl/pipeline/head This commit looks good Details

Building a static executable and distributing it in a "from scratch"
container image dramatically reduces the image size: down to 8 MB from
102 MB.
master
Dustin 2024-01-18 19:53:52 -06:00
parent 09bd82d1df
commit 554c1e9cf4
1 changed files with 8 additions and 8 deletions

View File

@ -1,23 +1,23 @@
FROM registry.fedoraproject.org/fedora-minimal:39 AS build
FROM docker.io/library/rust:1.73-alpine AS build
RUN --mount=type=cache,target=/var/cache \
microdnf install -y \
--setopt install_weak_deps=0 \
cargo\
apk add \
musl-dev \
&& :
COPY . /src
WORKDIR /src
RUN cargo build --release --locked
RUN cargo build --release --locked \
&& strip target/release/tmpl
FROM registry.fedoraproject.org/fedora-minimal:39
FROM scratch
COPY --from=build /src/target/release/tmpl /usr/local/bin
COPY --from=build /src/target/release/tmpl /tmpl
ENTRYPOINT ["/usr/local/bin/tmpl"]
ENTRYPOINT ["/tmpl"]
LABEL name='tmpl' \
vendor='Dustin C. Hatch' \