2024-06-28 19:54:17 +00:00
|
|
|
# ------------------------------------------------------------------------
|
|
|
|
from rust:1.79.0-alpine3.20 as rust
|
2024-05-14 22:59:57 +00:00
|
|
|
|
|
|
|
run apk add --no-cache musl-dev # pkgconfig cryptsetup-dev lvm2-dev clang-dev clang-static
|
|
|
|
|
|
|
|
workdir /src
|
|
|
|
copy Cargo.* .
|
|
|
|
copy src src
|
2024-06-28 19:54:17 +00:00
|
|
|
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
|
2024-05-14 22:59:57 +00:00
|
|
|
|
2024-06-28 19:54:17 +00:00
|
|
|
# ------------------------------------------------------------------------
|
|
|
|
from golang:1.22.4-alpine3.20 as build
|
2023-11-27 13:40:15 +00:00
|
|
|
|
|
|
|
workdir /src
|
|
|
|
|
|
|
|
copy . .
|
2024-01-20 15:41:54 +00:00
|
|
|
|
|
|
|
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 .
|
2023-11-27 13:40:15 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------
|
2024-06-28 19:54:17 +00:00
|
|
|
from alpine:3.20.0 as initrd
|
2023-12-17 13:28:32 +00:00
|
|
|
|
|
|
|
run apk add --no-cache xz
|
2023-11-27 13:40:15 +00:00
|
|
|
|
|
|
|
workdir /layer
|
2024-01-21 14:26:00 +00:00
|
|
|
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
|
2023-11-27 13:40:15 +00:00
|
|
|
|
2024-06-28 19:54:17 +00:00
|
|
|
run apk add --no-cache -p . musl coreutils lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk
|
2023-11-27 13:40:15 +00:00
|
|
|
run rm -rf usr/share/apk var/cache/apk
|
|
|
|
|
2024-05-14 22:59:57 +00:00
|
|
|
#copy --from=build /go/bin/init .
|
2024-06-28 19:54:17 +00:00
|
|
|
copy --from=rust /init /layer/init
|
2023-11-27 13:40:15 +00:00
|
|
|
|
|
|
|
# check viability
|
2024-06-28 19:54:17 +00:00
|
|
|
run chroot . /init hello
|
2023-11-27 13:40:15 +00:00
|
|
|
|
2023-12-17 13:28:32 +00:00
|
|
|
run find |cpio -H newc -o >/initrd
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------
|
2024-06-28 19:54:17 +00:00
|
|
|
from alpine:3.20.0
|
2023-12-17 13:28:32 +00:00
|
|
|
copy --from=initrd /initrd /
|
|
|
|
entrypoint ["base64","/initrd"]
|