40 lines
1.1 KiB
Docker
40 lines
1.1 KiB
Docker
from golang:1.23.2-alpine3.20 as build
|
|
run apk add --no-cache gcc musl-dev linux-headers eudev-dev upx
|
|
|
|
workdir /src
|
|
|
|
copy . .
|
|
|
|
env CGO_ENABLED=1
|
|
run \
|
|
--mount=type=cache,id=gomod,target=/go/pkg/mod \
|
|
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
|
|
go test ./... \
|
|
&& go build -ldflags "-s -w" -o /go/bin/init -trimpath .
|
|
|
|
run upx /go/bin/init
|
|
|
|
# ------------------------------------------------------------------------
|
|
from alpine:3.20.3 as initrd
|
|
|
|
run apk add --no-cache xz
|
|
|
|
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 lsblk
|
|
run rm -rf usr/share/apk var/cache/apk
|
|
|
|
copy --from=build /go/bin/init .
|
|
|
|
# check viability
|
|
run chroot /layer /init hello
|
|
|
|
run find |cpio -H newc -o >/initrd
|
|
|
|
# ------------------------------------------------------------------------
|
|
from alpine:3.20.3
|
|
copy --from=initrd /initrd /
|
|
entrypoint ["base64","/initrd"]
|