introduce rust

This commit is contained in:
Mikaël Cluseau
2024-04-29 12:54:25 +02:00
parent 6e1cb57e03
commit d6dca03df1
38 changed files with 1589 additions and 30 deletions

View File

@ -1,39 +1,37 @@
from golang:1.23.2-alpine3.20 as build
run apk add --no-cache gcc musl-dev linux-headers eudev-dev upx
from rust:1.87.0-alpine as rust
run apk add --no-cache git musl-dev libudev-zero-dev # pkgconfig cryptsetup-dev lvm2-dev clang-dev clang-static
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
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 /
# ------------------------------------------------------------------------
from alpine:3.20.3 as initrd
run apk add --no-cache xz
from alpine:3.22.0 as initrd
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
run apk add --no-cache --update -p . musl coreutils \
lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup \
e2fsprogs lsblk openssh-server \
&& rm -rf usr/share/apk var/cache/apk etc/motd
copy --from=build /go/bin/init .
copy etc/sshd_config etc/ssh/sshd_config
copy --from=rust /init init
run cd bin && for cmd in init-version connect-boot bootstrap; do ln -s ../init $cmd; done
# check viability
run chroot /layer /init hello
run chroot . init-version
run find |cpio -H newc -o >/initrd
# ------------------------------------------------------------------------
from alpine:3.20.3
from alpine:3.22.0
copy --from=initrd /initrd /
entrypoint ["base64","/initrd"]