From 2204d7259b80260a986c5749890900203bd8e76b Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Tue, 3 Sep 2024 14:01:36 -0700 Subject: [PATCH] moving apptron vm definition here with gh actions builder --- .github/workflows/build-image.yml | 40 ++++++++++++++++++++++++++++ .gitignore | 2 ++ Makefile | 8 ++++++ vm/Dockerfile | 44 +++++++++++++++++++++++++++++++ vm/guest86.service | 4 +++ 5 files changed, 98 insertions(+) create mode 100644 .github/workflows/build-image.yml create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 vm/Dockerfile create mode 100755 vm/guest86.service diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..fb32a9d --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,40 @@ +name: Build Image + +on: + push: + branches: + - main + +defaults: + run: + # GitHub Actions run without a TTY device. This is a workaround to get one, + # based on https://github.com/actions/runner/issues/241#issuecomment-2019042651 + shell: 'script --return --quiet --log-out /dev/null --command "sh -e {0}"' + +jobs: + build-image: + runs-on: ubuntu-latest + permissions: + contents: write + services: + docker: + image: docker:dind + options: --privileged --shm-size=2g + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + container: + image: progrium/env86:latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Create image + run: | + make vm + tar -czf apptron-vm.tgz -C dist . + + - uses: ncipollo/release-action@v1 + with: + tag: "release" + allowUpdates: true + artifacts: "apptron-vm.tgz" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cc625f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vm/image +/dist diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7d53a42 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +.PHONY: vm + +vm: + rm -rf ./vm/image + env86 create --with-guest --from-docker ./vm/Dockerfile ./vm/image + env86 boot --cold --ttyS0 --save --no-console --exit-on="localhost:~#" ./vm/image + rm -rf ./dist + env86 prepare ./vm/image ./dist \ No newline at end of file diff --git a/vm/Dockerfile b/vm/Dockerfile new file mode 100644 index 0000000..384f8a0 --- /dev/null +++ b/vm/Dockerfile @@ -0,0 +1,44 @@ +FROM i386/alpine:3.18.6 + +ENV KERNEL=lts +ENV HOSTNAME=localhost +ENV PASSWORD='root' + +RUN apk add openrc \ + alpine-base \ + agetty \ + alpine-conf + +# 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 + +# Adding networking.sh script (works only on lts kernel yet) +RUN if [ "$KERNEL" == "lts" ]; then \ + echo -e "echo '127.0.0.1 localhost' >> /etc/hosts && rmmod ne2k-pci && modprobe ne2k-pci\nhwclock -s\nsetup-interfaces -a -r" > /root/networking.sh && \ + chmod +x /root/networking.sh; \ +fi + +RUN sed -i 's/getty 38400 tty1/agetty --autologin root tty1 linux/' /etc/inittab +RUN echo 'ttyS0::once:/sbin/agetty --autologin root -s ttyS0 115200 vt100' >> /etc/inittab +RUN echo "root:$PASSWORD" | chpasswd + +# assume env86 will add /bin/guest86 +COPY ./guest86.service /etc/init.d/guest86 +# there is a bug where it always crashes on first run +RUN echo "rc-service guest86 start && rc-service guest86 stop && rc-service guest86 start" > /root/.profile + +# 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 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) diff --git a/vm/guest86.service b/vm/guest86.service new file mode 100755 index 0000000..664a1e7 --- /dev/null +++ b/vm/guest86.service @@ -0,0 +1,4 @@ +#!/sbin/openrc-run +command="/bin/guest86" +command_background="yes" +pidfile="/var/run/guest86.pid"