Skip to content

Commit

Permalink
make rootfsbuilder nicer to use
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandzelter committed Mar 26, 2024
1 parent 99a955c commit 12519f0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 59 deletions.
31 changes: 24 additions & 7 deletions builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
65 changes: 26 additions & 39 deletions builder/build-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 0 additions & 13 deletions builder/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# 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
Expand Down

0 comments on commit 12519f0

Please sign in to comment.