From d25d876df5e82c8fd3603c3dc85d2a1ae4681f2c Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Fri, 19 Jan 2024 10:04:26 -0600 Subject: [PATCH] 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. --- Containerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Containerfile b/Containerfile index a561900..30487c3 100644 --- a/Containerfile +++ b/Containerfile @@ -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' \