Skip to content

Commit

Permalink
moving apptron vm definition here with gh actions builder
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Sep 3, 2024
1 parent 83b2c14 commit 2204d72
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vm/image
/dist
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions vm/Dockerfile
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions vm/guest86.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/sbin/openrc-run
command="/bin/guest86"
command_background="yes"
pidfile="/var/run/guest86.pid"

0 comments on commit 2204d72

Please sign in to comment.