nit/Containerfile

79 lines
2.1 KiB
Docker

# A hello-world example.
ARG DOMAIN_NAME
FROM stagex/pallet-rust:sx2025.06.1 AS pallet-rust
FROM stagex/user-eif_build:sx2025.06.1 AS eif_build
FROM stagex/user-gen_initramfs:sx2025.06.1 AS gen_initramfs
FROM stagex/user-linux-nitro:sx2025.06.1 AS linux-nitro
FROM scratch as base
ENV TARGET=x86_64-unknown-linux-musl
ENV RUSTFLAGS="-C target-feature=+crt-static"
ENV CARGOFLAGS="--locked --all-features --release --target ${TARGET}"
ENV OPENSSL_STATIC=true
COPY --from=pallet-rust . /
COPY --from=gen_initramfs . /
COPY --from=eif_build . /
COPY --from=linux-nitro /bzImage .
COPY --from=linux-nitro /linux.config .
ADD . /src
FROM base as build
WORKDIR /src
RUN cargo build ${CARGOFLAGS}
WORKDIR /build_cpio
RUN cp /src/target/${TARGET}/release/nit init
RUN cp /src/target/${TARGET}/release/hello hello
ENV KBUILD_BUILD_TIMESTAMP=1
ARG DOMAIN_NAME
COPY <<EOF Caddyfile
${DOMAIN_NAME} {
respond "HTTPS, World!"
}
EOF
COPY <<-EOF initramfs.list
file /init init 0755 0 0
dir /run 0755 0 0
dir /tmp 0755 0 0
dir /etc 0755 0 0
dir /etc/caddy 0755 0 0
file /etc/caddy/Caddyfile Caddyfile 0755 0 0
dir /bin 0755 0 0
dir /sbin 0755 0 0
dir /proc 0755 0 0
dir /sys 0755 0 0
dir /usr 0755 0 0
dir /usr/bin 0755 0 0
file /usr/bin/hello hello 0755 0 0
dir /usr/sbin 0755 0 0
dir /dev 0755 0 0
dir /dev/shm 0755 0 0
dir /dev/pts 0755 0 0
nod /dev/console 0600 0 0 c 5 1
EOF
RUN <<-EOF
find . -exec touch -hcd "@0" "{}" +
gen_init_cpio -t 1 initramfs.list > rootfs.cpio
touch -hcd "@0" rootfs.cpio
EOF
WORKDIR /build_eif
RUN eif_build \
--kernel /bzImage \
--kernel_config /linux.config \
--ramdisk /build_cpio/rootfs.cpio \
--pcrs_output /nitro.pcrs \
--output /nitro.eif \
--cmdline 'reboot=k initrd=0x2000000,3228672 root=/dev/ram0 panic=1 pci=off nomodules console=ttyS0 i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd'
FROM base as install
WORKDIR /rootfs
COPY --from=build /nitro.eif .
COPY --from=build /nitro.pcrs .
FROM scratch as package
COPY --from=install /rootfs .