initrd/Dockerfile
Mikaël Cluseau bce1ec14f1 wip
2024-06-29 09:25:11 +02:00

51 lines
1.5 KiB
Docker

# ------------------------------------------------------------------------
from rust:1.79.0-alpine3.20 as rust
run apk add --no-cache musl-dev # pkgconfig cryptsetup-dev lvm2-dev clang-dev clang-static
workdir /src
copy Cargo.* .
copy src src
run --mount=type=cache,id=novit-rs,target=/usr/local/cargo/registry \
--mount=type=cache,id=novit-rs-target,sharing=private,target=/src/target \
cargo build --release && cp target/release/init / \
&& strip /init
# ------------------------------------------------------------------------
from golang:1.22.4-alpine3.20 as build
workdir /src
copy . .
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 .
# ------------------------------------------------------------------------
from alpine:3.20.0 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 coreutils lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk
run rm -rf usr/share/apk var/cache/apk
#copy --from=build /go/bin/init .
copy --from=rust /init /layer/init
# check viability
run chroot . /init hello
run find |cpio -H newc -o >/initrd
# ------------------------------------------------------------------------
from alpine:3.20.0
copy --from=initrd /initrd /
entrypoint ["base64","/initrd"]