From 8d74d48cde3dbb3c1e5c799491c8651fa36dbfa8 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 17 Feb 2023 01:34:01 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=9A=A7=20=E2=9C=A8=20First=20working?= =?UTF-8?q?=20version=20of=20VM.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + base/Dockerfile | 3 +- basevm/Dockerfile | 120 ++++++++++++++++++++++++++++++++++++++++ basevm/make-vm-image.sh | 94 +++++++++++++++++++++++++++++++ k3s/Dockerfile | 3 +- 5 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 basevm/Dockerfile create mode 100755 basevm/make-vm-image.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7a5304 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +alpinevm.* diff --git a/base/Dockerfile b/base/Dockerfile index 6d4a1c5..a7bc2e4 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -23,7 +23,8 @@ RUN git clone --quiet --depth 1 https://github.com/ohmyzsh/ohmyzsh.git /usr/shar # OpenRC stuff RUN mkdir -p /lib/rc/init.d && \ ln -s /lib/rc/init.d /run/openrc && \ - touch /lib/rc/init.d/softlevel + touch /lib/rc/init.d/softlevel && \ + cp /etc/rc.conf /etc/rc.conf.orig ADD rc.conf /etc/rc.conf diff --git a/basevm/Dockerfile b/basevm/Dockerfile new file mode 100644 index 0000000..6362cc0 --- /dev/null +++ b/basevm/Dockerfile @@ -0,0 +1,120 @@ +# syntax=docker/dockerfile:1.3-labs +ARG BASE_IMAGE=alpine:3.17 +FROM $BASE_IMAGE + +# TODO: move this into a base image -- start -- + +# Add the dependencies +RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ + apk update --quiet && \ + apk add --no-progress --no-cache openrc zsh git curl doas && \ + rm -rf `find /var/cache/apk/ -type f` + +# Change root shell +RUN sed -ie '/^root:/ s#:/bin/.*$#:/bin/zsh#' /etc/passwd + +# Add Oh-my-zsh +RUN git clone --quiet --depth 1 https://github.com/ohmyzsh/ohmyzsh.git /usr/share/oh-my-zsh && \ + sed -i -e 's#^export ZSH=.*#export ZSH=/usr/share/oh-my-zsh#g' /usr/share/oh-my-zsh/templates/zshrc.zsh-template && \ + git clone --quiet --depth=1 https://github.com/zsh-users/zsh-autosuggestions "/usr/share/oh-my-zsh/custom/plugins/zsh-autosuggestions" && \ + mkdir -p /etc/skel && \ + install -m 700 -o root -g root /usr/share/oh-my-zsh/templates/zshrc.zsh-template /etc/skel/.zshrc && \ + install --directory -o root -g root -m 0700 /etc/skel/.ssh && \ + sed -ie '/^plugins=/ s#.*#plugins=(git zsh-autosuggestions)#' /etc/skel/.zshrc && \ + sed -ie '/^ZSH_THEME=/ s#.*#ZSH_THEME="amuse"#' /etc/skel/.zshrc + +# Configure root user +USER root +RUN install -m 700 -o root -g root /etc/skel/.zshrc /root/.zshrc && \ + install --directory -o root -g root -m 0700 /root/.ssh + +# Add user alpine +RUN adduser -s /bin/zsh -g alpine -D alpine && \ + addgroup alpine wheel && \ + echo "permit nopass keepenv :wheel" >> /etc/doas.d/doas.conf + +# Configure user alpine +USER alpine + +# Run shell by default. Allows using the docker image +CMD /bin/zsh + +# TODO: move this into a base image -- end -- + + +USER root + +RUN apk add --no-progress --no-cache \ + alpine-base \ + less \ + logrotate \ + openssh \ + openntpd \ + acpi \ + e2fsprogs-extra \ + linux-virt \ + cloud-init \ + py3-pyserial \ + py3-netifaces \ + syslinux + +RUN for s in cgroups devfs dmesg hwdrivers mdev; do ln -s /etc/init.d/$s /etc/runlevels/sysinit/$s; done \ + && \ + for s in bootmisc hostname hwclock loadkmap modules networking swap sysctl syslog termencoding; do ln -s /etc/init.d/$s /etc/runlevels/boot/$s; done \ + && \ + for s in killprocs mount-ro savecache; do ln -s /etc/init.d/$s /etc/runlevels/shutdown/$s; done \ + && \ + for s in acpid crond openntpd sshd cloud-init cloud-config cloud-final; do ln -s /etc/init.d/$s /etc/runlevels/default/$s; done \ + && \ + setup-hostname alpinevm \ + && \ + setup-timezone -z Europe/Paris \ + && \ + setup-keymap fr fr-azerty \ + && \ + printf '\ +auto lo\n\ +iface lo inet loopback\n\ +\n\ +auto eth0\n\ +iface eth0 inet dhcp\n\ + hostname alpinevm\n\ +' > /etc/network/interfaces \ + && \ + sed -e '/disable_root:/ s/true/false/' \ + -e '/ssh_pwauth:/ s/0/no/' \ + -e '/name: alpine/a \ passwd: "*"' \ + -e '/lock_passwd:/ s/True/False/' \ + -e '/shell:/ s#/bin/ash#/bin/zsh#' \ + -i /etc/cloud/cloud.cfg \ + && \ + sed -e '/PermitRootLogin yes/d' \ + -e 's/^#PasswordAuthentication yes/PasswordAuthentication no/' \ + -e 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' \ + -i /etc/ssh/sshd_config \ + && \ + echo "PubkeyAcceptedKeyTypes=+ssh-rsa" >> /etc/ssh/sshd_config \ + && \ + sed -Ei \ + -e 's/^[# ](rc_depend_strict)=.*/\1=NO/' \ + -e 's/^[# ](rc_logger)=.*/\1=YES/' \ + -e 's/^[# ](unicode)=.*/\1=YES/' \ + -e 's/^[# ](rc_sys)=.*/\1=""/' \ + /etc/rc.conf \ + && \ + sed -Ei \ + -e 's/^[# ]*(features)=.*/\1="base ext4 scsi virtio"/' \ + /etc/mkinitfs/mkinitfs.conf \ + && \ + sed -Ei \ + -e "s|^[# ]*(default_kernel_opts)=.*|\1=\"\"|" \ + -e "s|^[# ]*(modules)=.*|\1=\"ext4\"|" \ + "$mnt"/etc/update-extlinux.conf \ + && \ + echo "iso9660" >> /etc/filesystems \ + && \ + usermod -p '*' root \ + && \ + usermod -p '*' alpine + +USER alpine diff --git a/basevm/make-vm-image.sh b/basevm/make-vm-image.sh new file mode 100755 index 0000000..a98122d --- /dev/null +++ b/basevm/make-vm-image.sh @@ -0,0 +1,94 @@ +#!/bin/bash +set -e pipefail + + +ebegin() { + echo -e -n '\e[s\e[1;32m* \e[0m' + echo -e -n "$@" + echo -e -n '...' +} + +eend() { + echo -e -n '\e[u\e[120C' + echo -e -n '\e[7D' + echo -e -n '\e[1;34m[ \e[0m' + if [ $1 -eq 0 ]; then + echo -e -n '\e[1;32mok\e[0m' + else + echo -e -n '\e[1;31m!!\e[0m' + fi + echo -e '\e[1;34m ]\e[0m' + + if [ $1 -ne 0 ]; then + exit $1 + fi +} + +vmname="alpinevm" +imgname="${vmname}.img" +vhdxname="${vmname}.vhdx" +qcowname="${vmname}.qcow2" + +mntdir=$( mktemp -d ) + + +ebegin "Creating image" +dd if=/dev/zero of=$imgname bs=1G count=1 >/dev/null 2>&1 +eend $? + +ebegin "Setting parition table" +echo "type=83,bootable" | sfdisk $imgname >/dev/null 2>&1 +eend $? + +ebegin "Creating loop device" +losetup -D && losetup -o 1048576 /dev/loop0 $imgname +eend $? + +ebegin "Creating ext4 filesystem" +mkfs.ext4 -O ^64bit /dev/loop0 >/dev/null 2>&1 +eend $? + +ebegin "Building docker image" +docker buildx build -t basevm --load --quiet ./basevm >/dev/null 2>&1 && ID=$(docker create basevm) +eend $? + +ebegin "Dumping image into partition" +mount /dev/loop0 $mntdir && \ + docker export $ID | tar x --numeric-owner -C $mntdir && \ + docker rm $ID >/dev/null 2>&1 && \ + dd if=$mntdir/usr/share/syslinux/mbr.bin of=$imgname bs=440 count=1 conv=notrunc >/dev/null 2>&1 +eend $? + +ebegin "Preparing chroot" +uuid=$(blkid -s UUID -o value /dev/loop0) && \ + mount -t proc none $mntdir/proc && \ + mount --bind /dev $mntdir/dev && \ + mount --bind /sys $mntdir/sys && \ + mount --make-private $mntdir/sys && \ + mount --make-private $mntdir/dev +eend $? + +ebegin "Updating boot information" +echo "UUID=$uuid / ext4 noatime 0 1" > $mntdir/etc/fstab +sed -Ei \ + -e "s|^[# ]*(root)=.*|\1=UUID=$uuid|" \ + $mntdir/etc/update-extlinux.conf && \ + chroot $mntdir mkinitfs >/dev/null 2>&1 || /bin/true && \ + chroot $mntdir extlinux --install /boot >/dev/null 2>&1 && \ + chroot $mntdir update-extlinux --warn-only >/dev/null 2>&1 +eend $? + +ebegin "Cleaning chroot" +umount $mntdir/dev $mntdir/sys $mntdir/proc && umount $mntdir +eend $? + +losetup -D +rm -rf $mntdir + +ebegin "Converting image to VHDX" +qemu-img convert $imgname -O vhdx $vhdxname +eend $? + +ebegin "Converting image to QCOW2" +qemu-img convert -c $imgname -O qcow2 $qcowname +eend $? diff --git a/k3s/Dockerfile b/k3s/Dockerfile index 2e57034..4cb6fb8 100644 --- a/k3s/Dockerfile +++ b/k3s/Dockerfile @@ -4,6 +4,7 @@ FROM ghcr.io/kaweezle/alpine-boxes-base:${BASE_VERSION} USER root -RUN apk add --no-cache curl && \ +RUN apk add --no-cache curl openntpd && \ + rc-update add openntpd default && \ curl -sfL https://get.k3s.io | sed -e 's/sourcex/./g' | INSTALL_K3S_SKIP_START="true" sh - From c2dfb1f9b1c7c9ebc9d5fa4c72e1c017f331cd38 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 17 Feb 2023 11:21:57 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20Improved=20the=20base=20vm=20sc?= =?UTF-8?q?ript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basevm/make-vm-image.sh | 161 +++++++++++++++++++++++++++++++++------- 1 file changed, 133 insertions(+), 28 deletions(-) diff --git a/basevm/make-vm-image.sh b/basevm/make-vm-image.sh index a98122d..6046414 100755 --- a/basevm/make-vm-image.sh +++ b/basevm/make-vm-image.sh @@ -1,6 +1,45 @@ -#!/bin/bash -set -e pipefail - +#!/bin/sh +#---help--- +# Usage: make-vm-image.sh [options] [--] [] +# +# This script creates an Alpine linux VM image from an OCI image. +# +# Arguments: +# +# The OCI image to export. +# +# Base name of the image. alpinevm by default. +# +# Options and Environment Variables: +# -f --image-format IMAGE_FORMAT Format of the disk image (see qemu-img --help). +# +# -s --image-size IMAGE_SIZE Size of the disk image to create in bytes or with suffix +# (e.g. 1G, 1024M). Default is 2G. +# +# --rootfs ROOTFS Filesystem to create on the image. Default is ext4. +# +# -C --no-cleanup (CLEANUP) Don't cleanup in case of error. +# +# -h --help Show this help message and exit. +# +# -v --version Print version and exit. +# +# Each option can be also provided by environment variable. If both option and +# variable is specified and the option accepts only one argument, then the +# option takes precedence. +# +# https://github.com/kaweezle/alpine-boxes +#---help--- + +set -eu + +readonly PROGNAME='make-vm-image.sh' +readonly VERSION='0.0.1' + +die() { + echo -e '\e[1;31mERROR:\e[0m ' "$@" >&2 # bold red + exit 1 +} ebegin() { echo -e -n '\e[s\e[1;32m* \e[0m' @@ -24,43 +63,112 @@ eend() { fi } +help() { + sed -En '/^#---help---/,/^#---help---/p' "$0" | sed -E 's/^# ?//; 1d;$d;' + exit ${1:-0} +} + +umount_recursively() { + local mount_point="$1" + test -n "$mount_point" || return 1 + + cat /proc/mounts \ + | cut -d ' ' -f 2 \ + | grep "^$mount_point" \ + | sort -r \ + | xargs umount -rn +} + +cleanup() { + set +eu + trap '' EXIT HUP INT TERM # unset trap to avoid loop + + if [ "$mntdir" ]; then + umount_recursively "$mntdir" \ + || die "Failed to unmount $mntdir; unmount it and delete $root_dev manually" + rm -Rf "$mntdir" + fi + if [ "$root_dev" ]; then + losetup -d $root_dev + fi + + [ -z "$ID" ] || docker rm $ID >/dev/null 2>&1 +} + + + +opts=$(getopt -n $PROGNAME -o f:s:hVC \ + -l image-format:,image-size:,rootfs:,help,version,no-cleanum \ + -- "$@") || help 1 >&2 + +eval set -- "$opts" +while [ $# -gt 0 ]; do + n=2 + case "$1" in + -f | --image-format) IMAGE_FORMAT="$2";; + -s | --image-size) IMAGE_SIZE="$2";; + --rootfs) ROOTFS="$2";; + -C | --no-cleanup) CLEANUP='no'; n=1;; + -h | --help) help 0;; + -V | --version) echo "$PROGNAME $VERSION"; exit 0;; + --) shift; break;; + esac + shift $n +done + +: ${CLEANUP:="yes"} +: ${IMAGE_FORMAT:="vhdx qcow2"} +: ${IMAGE_SIZE:="1G"} +: ${ROOTFS:="ext4"} +[ "$ROOTFS" = ext4 ] && mkfs_args='-O ^64bit -E nodiscard' || mkfs_args='-K' + +[ $# -ne 0 ] || help 1 >&2 + +DOCKER_IMAGE="$1"; shift + vmname="alpinevm" -imgname="${vmname}.img" -vhdxname="${vmname}.vhdx" -qcowname="${vmname}.qcow2" -mntdir=$( mktemp -d ) +[ $# -eq 0 ] || { vmname="$1"; shift; } + +[ "$CLEANUP" = no ] || trap cleanup EXIT HUP INT TERM + +imgname="${vmname}.img" +[ -f $imgname ] && die "Image fille $imgname already exist." ebegin "Creating image" -dd if=/dev/zero of=$imgname bs=1G count=1 >/dev/null 2>&1 +dd if=/dev/zero of=$imgname bs=${IMAGE_SIZE} count=1 >/dev/null 2>&1 eend $? ebegin "Setting parition table" echo "type=83,bootable" | sfdisk $imgname >/dev/null 2>&1 eend $? -ebegin "Creating loop device" -losetup -D && losetup -o 1048576 /dev/loop0 $imgname +root_dev=$(losetup -f) + +ebegin "Creating loop device on $root_dev" +losetup -o 1048576 $root_dev $imgname eend $? ebegin "Creating ext4 filesystem" -mkfs.ext4 -O ^64bit /dev/loop0 >/dev/null 2>&1 +mkfs.$ROOTFS -L root $mkfs_args $root_dev >/dev/null 2>&1 eend $? -ebegin "Building docker image" -docker buildx build -t basevm --load --quiet ./basevm >/dev/null 2>&1 && ID=$(docker create basevm) -eend $? +# ebegin "Building docker image" +# docker buildx build -t basevm --load --quiet ./basevm >/dev/null 2>&1 +# eend $? + +mntdir=$(mktemp -d /tmp/$PROGNAME.XXXXXX) +uuid=$(blkid -s UUID -o value $root_dev) ebegin "Dumping image into partition" -mount /dev/loop0 $mntdir && \ +mount $root_dev $mntdir && \ + ID=$(docker create basevm) && \ docker export $ID | tar x --numeric-owner -C $mntdir && \ - docker rm $ID >/dev/null 2>&1 && \ dd if=$mntdir/usr/share/syslinux/mbr.bin of=$imgname bs=440 count=1 conv=notrunc >/dev/null 2>&1 eend $? ebegin "Preparing chroot" -uuid=$(blkid -s UUID -o value /dev/loop0) && \ mount -t proc none $mntdir/proc && \ mount --bind /dev $mntdir/dev && \ mount --bind /sys $mntdir/sys && \ @@ -79,16 +187,13 @@ sed -Ei \ eend $? ebegin "Cleaning chroot" -umount $mntdir/dev $mntdir/sys $mntdir/proc && umount $mntdir +cleanup eend $? -losetup -D -rm -rf $mntdir - -ebegin "Converting image to VHDX" -qemu-img convert $imgname -O vhdx $vhdxname -eend $? - -ebegin "Converting image to QCOW2" -qemu-img convert -c $imgname -O qcow2 $qcowname -eend $? +for format in $IMAGE_FORMAT; do + qemu_opts="" + [ $format == "qcow" -o $format == "qcow2" ] && qemu_opts="-c" + ebegin "Converting image to $format" + qemu-img convert $qemu_opts $imgname -O $format ${vmname}.${format} + eend $? +done From a563507508ad48f5f9c5146059ed8b7787936574 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 17 Feb 2023 12:15:10 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Rework=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- realbase/Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 realbase/Dockerfile diff --git a/realbase/Dockerfile b/realbase/Dockerfile new file mode 100644 index 0000000..b76af90 --- /dev/null +++ b/realbase/Dockerfile @@ -0,0 +1,41 @@ +# syntax=docker/dockerfile:1.3-labs +ARG BASE_IMAGE=alpine:3.17 +FROM $BASE_IMAGE + +# Add the dependencies +RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ + apk update --quiet && \ + apk add --no-progress --no-cache openrc zsh doas + +# Change root shell +RUN sed -ie '/^root:/ s#:/bin/.*$#:/bin/zsh#' /etc/passwd + +# Add Oh-my-zsh +RUN apk add --no-progress --no-cache --virtual ohmy git && \ + git clone --quiet --depth 1 https://github.com/ohmyzsh/ohmyzsh.git /usr/share/oh-my-zsh && \ + sed -i -e 's#^export ZSH=.*#export ZSH=/usr/share/oh-my-zsh#g' /usr/share/oh-my-zsh/templates/zshrc.zsh-template && \ + git clone --quiet --depth=1 https://github.com/zsh-users/zsh-autosuggestions "/usr/share/oh-my-zsh/custom/plugins/zsh-autosuggestions" && \ + mkdir -p /etc/skel && \ + install -m 700 -o root -g root /usr/share/oh-my-zsh/templates/zshrc.zsh-template /etc/skel/.zshrc && \ + install --directory -o root -g root -m 0700 /etc/skel/.ssh && \ + sed -ie '/^plugins=/ s#.*#plugins=(git zsh-autosuggestions)#' /etc/skel/.zshrc && \ + sed -ie '/^ZSH_THEME=/ s#.*#ZSH_THEME="amuse"#' /etc/skel/.zshrc && \ + apk del ohmy + +# Configure root user +USER root +RUN install -m 700 -o root -g root /etc/skel/.zshrc /root/.zshrc && \ + install --directory -o root -g root -m 0700 /root/.ssh + +# Add user +ARG USERNAME=alpine +RUN adduser -s /bin/zsh -g alpine -D $USERNAME && \ + addgroup $USERNAME wheel && \ + echo "permit nopass keepenv :wheel" >> /etc/doas.d/doas.conf + +# Configure user +USER $USERNAME + +# Run shell by default. Allows using the docker image +CMD /bin/zsh + From 6b6ced9e5554b15d3f5294b91a8d1b533db3447f Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 17 Feb 2023 14:18:49 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=91=B7=20Base=20build=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/base.yml | 112 ------------------------------- .github/workflows/build-box.yml | 4 ++ .github/workflows/build.yml | 89 ++++++++++++++++++++++++ base/Dockerfile | 4 +- basevm/Dockerfile | 50 ++------------ k3s/Dockerfile | 5 +- {realbase => minimal}/Dockerfile | 7 +- podman/Dockerfile | 5 +- 8 files changed, 112 insertions(+), 164 deletions(-) delete mode 100644 .github/workflows/base.yml create mode 100644 .github/workflows/build.yml rename {realbase => minimal}/Dockerfile (91%) diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml deleted file mode 100644 index 8fc75f6..0000000 --- a/.github/workflows/base.yml +++ /dev/null @@ -1,112 +0,0 @@ -# cSpell: disable -name: Build base image and RootFS -on: - workflow_dispatch: - push: - branches: - - "main" - tags: - - "v*" - pull_request: - branches: - - "main" - -jobs: - build-base: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - driver-opts: | - image=moby/buildkit:master - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{ github.repository }}-base - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: ./base - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Export as root fs - uses: docker/build-push-action@v3 - with: - context: ./base - push: false - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - outputs: type=tar,dest=alpine-boxes-base.rootfs.tar - - - name: Compress root filesystem and compute checksum - run: | - gzip alpine-boxes-base.rootfs.tar - sha256sum alpine-boxes-base.rootfs.tar.gz >> SHA256SUMS - - - name: Upload root fs artifact - uses: actions/upload-artifact@v3 - with: - name: rootfs - path: | - alpine-boxes-base.rootfs.tar.gz - - - name: Upload shasums artifact - uses: actions/upload-artifact@v3 - with: - name: shasums - path: | - SHA256SUMS - - build-docker: - needs: [build-base] - uses: ./.github/workflows/build-box.yml - with: - context: docker - secrets: inherit - - build-podman: - needs: [build-base] - uses: ./.github/workflows/build-box.yml - with: - context: podman - secrets: inherit - - build-k3s: - needs: [build-base] - uses: ./.github/workflows/build-box.yml - with: - context: k3s - secrets: inherit - - release-rootfses: - needs: [build-base, build-docker, build-podman, build-k3s] - runs-on: ubuntu-latest - if: contains(github.ref, 'refs/tags/v') && !github.event.release.prerelease - steps: - - name: Get Root File Systems - uses: actions/download-artifact@v3 - - - name: release - uses: softprops/action-gh-release@v1 - with: - files: | - rootfs/alpine-boxes-*.rootfs.tar.gz - shasums/SHA256SUMS - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build-box.yml b/.github/workflows/build-box.yml index 7a1a219..8dc17cf 100644 --- a/.github/workflows/build-box.yml +++ b/.github/workflows/build-box.yml @@ -43,6 +43,8 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + build-args: | + BASE_VERSION=${{ steps.meta.outputs.version }} - name: Export as root fs uses: docker/build-push-action@v3 @@ -54,6 +56,8 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max outputs: type=tar,dest=alpine-boxes-${{ inputs.context }}.rootfs.tar + build-args: | + BASE_VERSION=${{ steps.meta.outputs.version }} - name: Get distributions uses: actions/download-artifact@v3 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..93ef35c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,89 @@ +# cSpell: disable +name: Build base image and RootFS +on: + workflow_dispatch: + push: + branches: + - "main" + tags: + - "v*" + pull_request: + branches: + - "main" + +jobs: + prepare-artifacts: + runs-on: ubuntu-latest + steps: + - run: touch SHA256SUMS + - name: shasums artifact + uses: actions/upload-artifact@v3 + with: + name: shasums + path: | + SHA256SUMS + + build-base: + needs: [prepare-artifacts] + uses: ./.github/workflows/build-box.yml + with: + context: base + secrets: inherit + + build-minimal: + needs: [prepare-artifacts] + uses: ./.github/workflows/build-box.yml + with: + context: minimal + secrets: inherit + + build-docker: + needs: [build-base] + uses: ./.github/workflows/build-box.yml + with: + context: docker + secrets: inherit + + build-podman: + needs: [build-base] + uses: ./.github/workflows/build-box.yml + with: + context: podman + secrets: inherit + + build-k3s: + needs: [build-base] + uses: ./.github/workflows/build-box.yml + with: + context: k3s + secrets: inherit + + build-basevm: + needs: [build-minimal] + uses: ./.github/workflows/build-box.yml + with: + context: basevm + secrets: inherit + + release-rootfses: + needs: + - build-base + - build-minimal + - build-docker + - build-podman + - build-k3s + - build-basevm + runs-on: ubuntu-latest + if: contains(github.ref, 'refs/tags/v') && !github.event.release.prerelease + steps: + - name: Get Root File Systems + uses: actions/download-artifact@v3 + + - name: release + uses: softprops/action-gh-release@v1 + with: + files: | + rootfs/alpine-boxes-*.rootfs.tar.gz + shasums/SHA256SUMS + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/base/Dockerfile b/base/Dockerfile index a7bc2e4..485d147 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -1,5 +1,7 @@ # syntax=docker/dockerfile:1.3-labs -FROM alpine:3.17 +ARG ALPINE_VERSION=3.17 +ARG ALPINE_IMAGE=alpine +FROM ${ALPINE_IMAGE}:${ALPINE_VERSION} # Add the dependencies diff --git a/basevm/Dockerfile b/basevm/Dockerfile index 6362cc0..fceccca 100644 --- a/basevm/Dockerfile +++ b/basevm/Dockerfile @@ -1,47 +1,9 @@ # syntax=docker/dockerfile:1.3-labs -ARG BASE_IMAGE=alpine:3.17 -FROM $BASE_IMAGE - -# TODO: move this into a base image -- start -- - -# Add the dependencies -RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ - apk update --quiet && \ - apk add --no-progress --no-cache openrc zsh git curl doas && \ - rm -rf `find /var/cache/apk/ -type f` - -# Change root shell -RUN sed -ie '/^root:/ s#:/bin/.*$#:/bin/zsh#' /etc/passwd - -# Add Oh-my-zsh -RUN git clone --quiet --depth 1 https://github.com/ohmyzsh/ohmyzsh.git /usr/share/oh-my-zsh && \ - sed -i -e 's#^export ZSH=.*#export ZSH=/usr/share/oh-my-zsh#g' /usr/share/oh-my-zsh/templates/zshrc.zsh-template && \ - git clone --quiet --depth=1 https://github.com/zsh-users/zsh-autosuggestions "/usr/share/oh-my-zsh/custom/plugins/zsh-autosuggestions" && \ - mkdir -p /etc/skel && \ - install -m 700 -o root -g root /usr/share/oh-my-zsh/templates/zshrc.zsh-template /etc/skel/.zshrc && \ - install --directory -o root -g root -m 0700 /etc/skel/.ssh && \ - sed -ie '/^plugins=/ s#.*#plugins=(git zsh-autosuggestions)#' /etc/skel/.zshrc && \ - sed -ie '/^ZSH_THEME=/ s#.*#ZSH_THEME="amuse"#' /etc/skel/.zshrc - -# Configure root user -USER root -RUN install -m 700 -o root -g root /etc/skel/.zshrc /root/.zshrc && \ - install --directory -o root -g root -m 0700 /root/.ssh - -# Add user alpine -RUN adduser -s /bin/zsh -g alpine -D alpine && \ - addgroup alpine wheel && \ - echo "permit nopass keepenv :wheel" >> /etc/doas.d/doas.conf - -# Configure user alpine -USER alpine - -# Run shell by default. Allows using the docker image -CMD /bin/zsh - -# TODO: move this into a base image -- end -- - +ARG BASE_VERSION=latest +ARG BASE_IMAGE=ghcr.io/kaweezle/alpine-boxes-minimal +FROM ${BASE_IMAGE}:${BASE_VERSION} +ARG USERNAME=alpine USER root RUN apk add --no-progress --no-cache \ @@ -115,6 +77,6 @@ iface eth0 inet dhcp\n\ && \ usermod -p '*' root \ && \ - usermod -p '*' alpine + usermod -p '*' $USERNAME -USER alpine +USER $USERNAME diff --git a/k3s/Dockerfile b/k3s/Dockerfile index 4cb6fb8..590d29d 100644 --- a/k3s/Dockerfile +++ b/k3s/Dockerfile @@ -1,6 +1,7 @@ +# syntax=docker/dockerfile:1.3-labs ARG BASE_VERSION=latest - -FROM ghcr.io/kaweezle/alpine-boxes-base:${BASE_VERSION} +ARG BASE_IMAGE=ghcr.io/kaweezle/alpine-boxes-base +FROM ${BASE_IMAGE}:${BASE_VERSION} USER root diff --git a/realbase/Dockerfile b/minimal/Dockerfile similarity index 91% rename from realbase/Dockerfile rename to minimal/Dockerfile index b76af90..503a43e 100644 --- a/realbase/Dockerfile +++ b/minimal/Dockerfile @@ -1,6 +1,7 @@ # syntax=docker/dockerfile:1.3-labs -ARG BASE_IMAGE=alpine:3.17 -FROM $BASE_IMAGE +ARG ALPINE_VERSION=3.17 +ARG ALPINE_IMAGE=alpine +FROM ${ALPINE_IMAGE}:${ALPINE_VERSION} # Add the dependencies RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ @@ -29,7 +30,7 @@ RUN install -m 700 -o root -g root /etc/skel/.zshrc /root/.zshrc && \ # Add user ARG USERNAME=alpine -RUN adduser -s /bin/zsh -g alpine -D $USERNAME && \ +RUN adduser -s /bin/zsh -g $USERNAME -D $USERNAME && \ addgroup $USERNAME wheel && \ echo "permit nopass keepenv :wheel" >> /etc/doas.d/doas.conf diff --git a/podman/Dockerfile b/podman/Dockerfile index ab7b84e..f8c6a36 100644 --- a/podman/Dockerfile +++ b/podman/Dockerfile @@ -1,6 +1,7 @@ +# syntax=docker/dockerfile:1.3-labs ARG BASE_VERSION=latest - -FROM ghcr.io/kaweezle/alpine-boxes-base:${BASE_VERSION} +ARG BASE_IMAGE=ghcr.io/kaweezle/alpine-boxes-base +FROM ${BASE_IMAGE}:${BASE_VERSION} USER root From a82d40b32286a7d88238c416c43e0e278b8105c8 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 2 May 2024 06:40:04 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=9A=A7=20Added=20fetcher=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fetcher/Dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 fetcher/Dockerfile diff --git a/fetcher/Dockerfile b/fetcher/Dockerfile new file mode 100644 index 0000000..1977abd --- /dev/null +++ b/fetcher/Dockerfile @@ -0,0 +1,12 @@ +# syntax=docker/dockerfile:1.3-labs +ARG ALPINE_VERSION=3.17 +ARG ALPINE_IMAGE=alpine +FROM ${ALPINE_IMAGE}:${ALPINE_VERSION} + +# Add the dependencies +RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ + apk update --quiet && \ + apk add --no-progress --no-cache podman + +CMD /bin/sh +