From 5924705b24c8dee510203eed4cfe5bcd998e6ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Mon, 4 Nov 2024 22:06:48 +0100 Subject: [PATCH] shrink exec --- Dockerfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index d5cacc2..0881909 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ from golang:1.23.2-alpine3.20 as build -run apk add --no-cache gcc musl-dev linux-headers eudev-dev +run apk add --no-cache gcc musl-dev linux-headers eudev-dev upx workdir /src @@ -10,7 +10,9 @@ run \ --mount=type=cache,id=gomod,target=/go/pkg/mod \ --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ go test ./... \ -&& go build -o /go/bin/init -trimpath . +&& go build -ldflags "-s -w" -o /go/bin/init -trimpath . + +run upx /go/bin/init # ------------------------------------------------------------------------ from alpine:3.20.3 as initrd @@ -21,7 +23,7 @@ workdir /layer run . /etc/os-release \ && wget -O- https://dl-cdn.alpinelinux.org/alpine/v${VERSION_ID%.*}/releases/x86_64/alpine-minirootfs-${VERSION_ID}-x86_64.tar.gz |tar zxv -run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk +run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs lsblk run rm -rf usr/share/apk var/cache/apk copy --from=build /go/bin/init .