From c27b2f070ef2ea5e1620f184f924487005f4089e Mon Sep 17 00:00:00 2001 From: Aisha Tammy Date: Mon, 19 Sep 2022 00:15:38 +0000 Subject: [PATCH] try snapshot building Signed-off-by: Aisha Tammy --- .github/workflows/build.yml | 18 ++++++++++++++++-- create_vars.sh | 15 +++++++++++++++ openbsd.pkr.hcl | 18 +++++++++++++++++- resources/install.conf | 1 + resources/install.sh | 1 + resources/provision.sh | 13 +++++++++---- var_files/6.8/common.pkrvars.hcl | 1 + var_files/6.9/common.pkrvars.hcl | 1 + var_files/7.1/common.pkrvars.hcl | 1 + var_files/snapshots/arm64.pkrvars.hcl | 1 + var_files/snapshots/common.pkrvars.hcl | 3 +++ var_files/snapshots/x86-64.pkrvars.hcl | 2 ++ 12 files changed, 68 insertions(+), 7 deletions(-) create mode 100755 create_vars.sh create mode 100644 var_files/snapshots/arm64.pkrvars.hcl create mode 100644 var_files/snapshots/common.pkrvars.hcl create mode 100644 var_files/snapshots/x86-64.pkrvars.hcl diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed29d57..211c905 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,14 +17,15 @@ jobs: fail-fast: false matrix: version: + - snapshots - 6.8 - 6.9 - 7.1 + architecture: - x86-64 - arm64 - steps: - name: Clone Repository uses: actions/checkout@v2 @@ -32,7 +33,7 @@ jobs: persist-credentials: false - name: Install Dependecies - run: apt update && apt install curl unzip "qemu-system-$QEMU_ARCHITECTURE" -y + run: apt update && apt install curl unzip "qemu-system-${QEMU_ARCHITECTURE}" -y env: QEMU_ARCHITECTURE: ${{ matrix.architecture == 'x86-64' && 'x86' || @@ -40,6 +41,19 @@ jobs: matrix.architecture }} + - name: Find snapshot variables + if: ${{ matrix.version == 'snapshots' }} + run: | + bash create_vars.sh ${OBSD_ARCH} ${LOCAL_ARCH} + echo "SNAP_SUM=$(cat checksum)" >> ${GITHUB_ENV} + env: + OBSD_ARCH: ${{ + matrix.architecture == 'x86-64' && 'amd64' || + matrix.architecture == 'arm64' && 'arm64' || + matrix.architecture + }} + LOCAL_ARCH: ${{ matrix.architecture }} + - name: Install Packer run: | curl -o packer.zip -L https://releases.hashicorp.com/packer/1.7.1/packer_1.7.1_linux_amd64.zip diff --git a/create_vars.sh b/create_vars.sh new file mode 100755 index 0000000..5f2b0c9 --- /dev/null +++ b/create_vars.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -xeuo pipefail + +OBSD_ARCH="${1:-amd64}" +LOCAL_ARCH="${2:-x86-64}" + +snap_line="$(curl https://cdn.openbsd.org/pub/OpenBSD/snapshots/${OBSD_ARCH}/SHA256.sig 2>/dev/null | grep miniroot)" +snap_sum="$(echo $snap_line | awk '{ print $NF; }')" +snap_num="$(echo $snap_line | grep -Po 'miniroot\K(\d{2})')" + +echo "${snap_sum}" > checksum + +echo "checksum = \"sha256:${snap_sum}\"" > "var_files/snapshots/${LOCAL_ARCH}.pkrvars.hcl" +echo "os_number = \"${snap_num}\"" >> "var_files/snapshots/${LOCAL_ARCH}.pkrvars.hcl" diff --git a/openbsd.pkr.hcl b/openbsd.pkr.hcl index 23a0794..abcb1c1 100644 --- a/openbsd.pkr.hcl +++ b/openbsd.pkr.hcl @@ -3,6 +3,11 @@ variable "os_version" { description = "The version of the operating system to download and install" } +variable "os_number" { + type = string + description = "The version suffix for minirootXX.img from upstream" +} + variable "architecture" { default = "x86-64" type = string @@ -33,6 +38,11 @@ variable "cpus" { description = "The number of cpus to use when building the VM" } +variable "vnc_bind_address" { + default = "127.0.0.1" + type = string +} + variable "disk_size" { default = "12G" type = string @@ -118,7 +128,7 @@ variable "rsync_version" { locals { image_architecture = var.architecture == "x86-64" ? "amd64" : var.architecture - image = "miniroot${replace(var.os_version, ".", "")}.img" + image = "miniroot${var.os_number}.img" vm_name = "openbsd-${var.os_version}-${var.architecture}.qcow2" iso_target_extension = "img" @@ -129,6 +139,8 @@ locals { var.architecture == "x86-64" ? "x86_64" : var.architecture ) + obsd_architecture = var.architecture == "x86-64" ? "amd64" : "arm64" + readonly_boot_media = var.readonly_boot_media ? "on" : "off" } @@ -150,6 +162,8 @@ source "qemu" "qemu" { qemu_binary = "qemu-system-${local.qemu_architecture}" firmware = var.firmware + vnc_bind_address = var.vnc_bind_address + boot_wait = "30s" boot_command = [ @@ -160,6 +174,7 @@ source "qemu" "qemu" { "SECONDARY_USER_USERNAME=${var.secondary_user_username} ", "SECONDARY_USER_PASSWORD=${var.secondary_user_password} ", "ROOT_PASSWORD=${var.root_password} ", + "SERVER_DIRECTORY=pub/OpenBSD/${var.os_version}/${local.obsd_architecture} ", "DISKLABEL_TEMPLATE='http://{{ .HTTPIP }}:{{ .HTTPPort }}/resources/template.disklabel' ", "sh install.sh && reboot" ] @@ -198,6 +213,7 @@ build { provisioner "shell" { script = "resources/provision.sh" environment_vars = [ + "OS_VERSION=${var.os_version}", "SECONDARY_USER=${var.secondary_user_username}", "SUDO_VERSION=${var.sudo_version}", "RSYNC_VERSION=${var.rsync_version}" diff --git a/resources/install.conf b/resources/install.conf index 917dfc0..e7ac5b4 100644 --- a/resources/install.conf +++ b/resources/install.conf @@ -11,5 +11,6 @@ Use (W)hole disk MBR, whole disk (G)PT or (E)dit = g Location of sets = http URL to autopartitioning template for disklabel = {{ DISKLABEL_TEMPLATE }} Http Server = cdn.openbsd.org +Server directory = {{ SERVER_DIRECTORY }} Set name(s) = -game* -man* Directory does not contain SHA256.sig. Continue without verification = yes diff --git a/resources/install.sh b/resources/install.sh index 122afce..1813352 100755 --- a/resources/install.sh +++ b/resources/install.sh @@ -5,6 +5,7 @@ set -exu sed -i'' "s/{{ SECONDARY_USER_USERNAME }}/$SECONDARY_USER_USERNAME/" /install.conf sed -i'' "s/{{ SECONDARY_USER_PASSWORD }}/$SECONDARY_USER_PASSWORD/" /install.conf sed -i'' "s/{{ ROOT_PASSWORD }}/$ROOT_PASSWORD/" /install.conf +sed -i'' "s:{{ SERVER_DIRECTORY }}:$SERVER_DIRECTORY:" /install.conf # Use # instead of / because the URL to the templates contains / sed -i'' "s#{{ DISKLABEL_TEMPLATE }}#$DISKLABEL_TEMPLATE#" /install.conf diff --git a/resources/provision.sh b/resources/provision.sh index 28644ae..38b9b0e 100755 --- a/resources/provision.sh +++ b/resources/provision.sh @@ -2,14 +2,19 @@ set -exu +PKG_ADD="pkg_add" +if [ "${OS_VERSION}" = "snapshots" ]; then + PKG_ADD="pkg_add -Dsnap" +fi + install_extra_packages() { - pkg_add bash - pkg_add curl - pkg_add "rsync-$RSYNC_VERSION" + ${PKG_ADD} bash + ${PKG_ADD} curl + ${PKG_ADD} rsync-- } setup_sudo() { - pkg_add "sudo-$SUDO_VERSION" + ${PKG_ADD} sudo-- cat < /etc/sudoers #includedir /etc/sudoers.d diff --git a/var_files/6.8/common.pkrvars.hcl b/var_files/6.8/common.pkrvars.hcl index 8a20875..652f0a1 100644 --- a/var_files/6.8/common.pkrvars.hcl +++ b/var_files/6.8/common.pkrvars.hcl @@ -1,3 +1,4 @@ os_version = "6.8" +os_number = "68" sudo_version = "1.9.5.2p0" rsync_version = "3.2.3" diff --git a/var_files/6.9/common.pkrvars.hcl b/var_files/6.9/common.pkrvars.hcl index ad0c4d1..8a697db 100644 --- a/var_files/6.9/common.pkrvars.hcl +++ b/var_files/6.9/common.pkrvars.hcl @@ -1,3 +1,4 @@ os_version = "6.9" +os_number = "69" sudo_version = "1.9.6.1" rsync_version = "3.2.3p0" diff --git a/var_files/7.1/common.pkrvars.hcl b/var_files/7.1/common.pkrvars.hcl index b243121..ff4b958 100644 --- a/var_files/7.1/common.pkrvars.hcl +++ b/var_files/7.1/common.pkrvars.hcl @@ -1,3 +1,4 @@ os_version = "7.1" +os_number = "71" sudo_version = "1.9.10" rsync_version = "3.2.3p1" diff --git a/var_files/snapshots/arm64.pkrvars.hcl b/var_files/snapshots/arm64.pkrvars.hcl new file mode 100644 index 0000000..b5a6b0b --- /dev/null +++ b/var_files/snapshots/arm64.pkrvars.hcl @@ -0,0 +1 @@ +checksum = "sha256:XXXX" diff --git a/var_files/snapshots/common.pkrvars.hcl b/var_files/snapshots/common.pkrvars.hcl new file mode 100644 index 0000000..50039da --- /dev/null +++ b/var_files/snapshots/common.pkrvars.hcl @@ -0,0 +1,3 @@ +os_version = "snapshots" +sudo_version = "1.9.11.2" +rsync_version = "3.2.5pl0" diff --git a/var_files/snapshots/x86-64.pkrvars.hcl b/var_files/snapshots/x86-64.pkrvars.hcl new file mode 100644 index 0000000..8b77462 --- /dev/null +++ b/var_files/snapshots/x86-64.pkrvars.hcl @@ -0,0 +1,2 @@ +checksum = "sha256:XXXX" +os_number = "72"