container: Build static executable

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.

Reimplementing this change because this image is no longer the base for
*infra/cfg*.  That image is now based on Alpine and copies in the `tmpl`
executable.
master
Dustin 2024-01-19 10:04:26 -06:00
parent 1c33dfa4a4
commit d25d876df5
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 \ RUN --mount=type=cache,target=/var/cache \
microdnf install -y \ apk add \
--setopt install_weak_deps=0 \ musl-dev \
cargo\
&& : && :
COPY . /src COPY . /src
WORKDIR /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' \ LABEL name='tmpl' \
vendor='Dustin C. Hatch' \ vendor='Dustin C. Hatch' \