Browse Source

added dockerfile and changed build-container.sh

(from tools/docker/debian)
SuperMaxusa 1 month ago
parent
commit
2f24859bce
2 changed files with 69 additions and 0 deletions
  1. 42 0
      tools/docker/alpine/Dockerfile
  2. 27 0
      tools/docker/alpine/build-container.sh

+ 42 - 0
tools/docker/alpine/Dockerfile

@@ -0,0 +1,42 @@
+FROM i386/alpine:3.18.6
+
+ENV KERNEL=lts
+ENV HOSTNAME=localhost
+ENV ROOT_PASSWORD='root'
+ENV ADDPKGS=''
+
+RUN apk add openrc \ 
+            alpine-base \
+            agetty \
+            alpine-conf \ 
+            $ADDPKGS
+
+# Install mkinitfs from edge (todo: remove this when 3.19+ has worked properly with 9pfs)
+RUN apk add mkinitfs --no-cache --allow-untrusted --repository https://dl-cdn.alpinelinux.org/alpine/edge/main/ 
+
+RUN if [ "$KERNEL" == "lts" ]; then \
+    apk add linux-lts \
+            linux-firmware-none \
+            linux-firmware-sb16; \
+else \
+    apk add linux-$KERNEL; \
+fi
+
+RUN sed -i 's/getty 38400 tty1/agetty --autologin root tty1 linux/' /etc/inittab && \
+    echo "root:$ROOT_PASSWORD" | chpasswd
+
+RUN setup-hostname $HOSTNAME
+
+# Adding networking.sh script (works only on lts kernel yet)
+RUN if [ "$KERNEL" == "lts" ]; then \ 
+    echo -e "rmmod ne2k-pci && modprobe ne2k-pci\nhwclock -s\nsetup-interfaces -a -r" > /root/networking.sh && \ 
+    chmod +x /root/networking.sh; \ 
+fi
+
+# https://wiki.alpinelinux.org/wiki/Alpine_Linux_in_a_chroot#Preparing_init_services
+RUN for i in devfs dmesg mdev hwdrivers; do rc-update add $i sysinit; done
+RUN for i in hwclock modules sysctl hostname syslog bootmisc; do rc-update add $i boot; done
+RUN rc-update add killprocs shutdown
+
+# Generate initramfs with 9p modules
+RUN mkinitfs -F "ata base ide scsi virtio ext4 9p" $(cat /usr/share/kernel/$KERNEL/kernel.release)

+ 27 - 0
tools/docker/alpine/build-container.sh

@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+set -veu
+
+IMAGES="$(dirname "$0")"/../../../images
+OUT_ROOTFS_TAR="$IMAGES"/alpine-rootfs.tar
+OUT_ROOTFS_FLAT="$IMAGES"/alpine-rootfs-flat
+OUT_FSJSON="$IMAGES"/alpine-fs.json
+CONTAINER_NAME=alpine-v86
+IMAGE_NAME=i386/alpine-v86
+
+mkdir -p "$IMAGES"
+docker build . --platform linux/386 --rm --tag "$IMAGE_NAME"
+docker rm "$CONTAINER_NAME" || true
+docker create --platform linux/386 -t -i --name "$CONTAINER_NAME" "$IMAGE_NAME"
+
+docker export "$CONTAINER_NAME" -o "$OUT_ROOTFS_TAR"
+
+# https://github.com/iximiuz/docker-to-linux/issues/19#issuecomment-1242809707
+tar -f "$OUT_ROOTFS_TAR" --delete ".dockerenv"
+
+"$(dirname "$0")"/../../../tools/fs2json.py --out "$OUT_FSJSON" "$OUT_ROOTFS_TAR"
+
+# Note: Not deleting old files here
+mkdir -p "$OUT_ROOTFS_FLAT"
+"$(dirname "$0")"/../../../tools/copy-to-sha256.py "$OUT_ROOTFS_TAR" "$OUT_ROOTFS_FLAT"
+
+echo "$OUT_ROOTFS_TAR", "$OUT_ROOTFS_FLAT" and "$OUT_FSJSON" created.