From 12519f01f936aa6223007cbbaba446ac204d3163 Mon Sep 17 00:00:00 2001 From: Tobias Pfandzelter Date: Tue, 26 Mar 2024 11:39:56 +0100 Subject: [PATCH] make rootfsbuilder nicer to use --- builder/Dockerfile | 31 +++++++++++++++----- builder/build-script.sh | 65 +++++++++++++++++------------------------ builder/prepare.sh | 13 --------- 3 files changed, 50 insertions(+), 59 deletions(-) diff --git a/builder/Dockerfile b/builder/Dockerfile index 15eca66..d96d0e1 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -36,17 +36,34 @@ RUN wget http://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION_MAJOR}.${ALPINE_ cd minirootfs && \ tar xzf ../alpine-minirootfs-${ALPINE_VERSION}-${ALPINE_ARCH}.tar.gz && \ cd .. && \ - rm alpine-minirootfs-${ALPINE_VERSION}-${ALPINE_ARCH}.tar.gz + rm alpine-minirootfs-${ALPINE_VERSION}-${ALPINE_ARCH}.tar.gz && \ + mkdir -p ./rootfs && \ + cp -r minirootfs/* ./rootfs/ && \ + rm -rf minirootfs + +# install dependencies in minirootfs +RUN cp /etc/resolv.conf ./rootfs/etc/resolv.conf && \ + chroot ./rootfs/ apk -X "http://dl-5.alpinelinux.org/alpine/latest-stable/main" -U --allow-untrusted --root / --initdb add \ + openrc \ + ca-certificates \ + alpine-base \ + util-linux \ + iptables \ + iproute2 \ + strace \ + attr \ + grep \ + chrony COPY fcinit.c fcinit.c -RUN gcc -static -O3 -o ./fcinit fcinit.c && \ +RUN gcc -static -O3 -o ./rootfs/sbin/fcinit fcinit.c && \ rm fcinit.c -COPY inittab inittab -COPY interfaces interfaces -COPY run-user-script run-user-script -COPY prepare.sh prepare.sh -COPY ceinit ceinit +COPY inittab ./rootfs/etc/inittab +COPY interfaces ./rootfs/etc/network/interfaces +COPY run-user-script ./rootfs/sbin/run-user-script +COPY prepare.sh ./rootfs/prepare.sh +COPY ceinit ./rootfs/sbin/ceinit COPY build-script.sh /build-script.sh diff --git a/builder/build-script.sh b/builder/build-script.sh index 7a6b593..dca79db 100644 --- a/builder/build-script.sh +++ b/builder/build-script.sh @@ -21,59 +21,46 @@ set -ex -mkdir -p ./tmp - -cp -r minirootfs/* ./tmp/ - -# if you don't do this, apk can't access its repositories -cp /etc/resolv.conf ./tmp/etc/resolv.conf # mount /dev/random and /dev/urandom (needed for some operations, such as git) -mkdir -p ./tmp/dev -touch ./tmp/dev/random -mount --rbind /dev/random ./tmp/dev/random -mount --make-rslave ./tmp/dev/random -touch ./tmp/dev/urandom -mount --rbind /dev/urandom ./tmp/dev/urandom -mount --make-rslave ./tmp/dev/urandom +mkdir -p ./rootfs/dev +touch ./rootfs/dev/random +mount --rbind /dev/random ./rootfs/dev/random +mount --make-rslave ./rootfs/dev/random +touch ./rootfs/dev/urandom +mount --rbind /dev/urandom ./rootfs/dev/urandom +mount --make-rslave ./rootfs/dev/urandom -# copy the necessary files -cp interfaces ./tmp/etc/network/interfaces -cp inittab ./tmp/etc/inittab -cp run-user-script ./tmp/sbin/run-user-script -cp fcinit ./tmp/sbin/fcinit -cp ceinit ./tmp/sbin/ceinit -cp /app.sh ./tmp/app.sh +# # copy the necessary files +cp /app.sh ./rootfs/app.sh if [ -d "/files" ]; then - cp -rv /files/* ./tmp/ + cp -rv /files/* ./rootfs/ fi -cp prepare.sh ./tmp/prepare.sh -chroot ./tmp/ /bin/sh /prepare.sh +chroot ./rootfs/ /bin/sh /prepare.sh +rm ./rootfs/prepare.sh if [ -f "/base.sh" ]; then - cp /base.sh ./tmp/base.sh - chroot ./tmp/ /bin/sh base.sh - rm ./tmp/base.sh + cp /base.sh ./rootfs/base.sh + chroot ./rootfs/ /bin/sh base.sh + rm ./rootfs/base.sh fi # these are the mount points we need to create -mkdir -p ./tmp/overlay/root \ - ./tmp/overlay/work \ - ./tmp/mnt \ - ./tmp/rom +mkdir -p ./rootfs/overlay/root \ + ./rootfs/overlay/work \ + ./rootfs/mnt \ + ./rootfs/rom # now delete the nameserver config again -rm ./tmp/etc/resolv.conf -ln -s /proc/net/pnp ./tmp/etc/resolv.conf +rm ./rootfs/etc/resolv.conf +ln -s /proc/net/pnp ./rootfs/etc/resolv.conf # and unmount the devices -umount ./tmp/dev/random -rm ./tmp/dev/random -umount ./tmp/dev/urandom -rm ./tmp/dev/urandom - -rm ./tmp/prepare.sh +umount ./rootfs/dev/random +rm ./rootfs/dev/random +umount ./rootfs/dev/urandom +rm ./rootfs/dev/urandom -mksquashfs ./tmp rootfs.img -noappend +mksquashfs ./rootfs rootfs.img -noappend mv rootfs.img /opt/code/"$1" diff --git a/builder/prepare.sh b/builder/prepare.sh index d765796..1475529 100755 --- a/builder/prepare.sh +++ b/builder/prepare.sh @@ -16,19 +16,6 @@ # along with this program. If not, see . # -# install dependencies -apk -X "http://dl-5.alpinelinux.org/alpine/latest-stable/main" -U --allow-untrusted --root / --initdb add \ - openrc \ - ca-certificates \ - alpine-base \ - util-linux \ - iptables \ - iproute2 \ - strace \ - attr \ - grep \ - chrony - # link rc services ln -sf /etc/init.d/devfs /etc/runlevels/boot/devfs ln -sf /etc/init.d/procfs /etc/runlevels/boot/procfs