Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try snapshot building #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,43 @@ 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
with:
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' ||
matrix.architecture == 'arm64' && 'aarch64' ||
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
Expand Down
15 changes: 15 additions & 0 deletions create_vars.sh
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 17 additions & 1 deletion openbsd.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
}

Expand All @@ -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 = [
Expand All @@ -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<enter>"
]
Expand Down Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions resources/install.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions resources/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions resources/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > /etc/sudoers
#includedir /etc/sudoers.d
Expand Down
1 change: 1 addition & 0 deletions var_files/6.8/common.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
os_version = "6.8"
os_number = "68"
sudo_version = "1.9.5.2p0"
rsync_version = "3.2.3"
1 change: 1 addition & 0 deletions var_files/6.9/common.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
os_version = "6.9"
os_number = "69"
sudo_version = "1.9.6.1"
rsync_version = "3.2.3p0"
1 change: 1 addition & 0 deletions var_files/7.1/common.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
os_version = "7.1"
os_number = "71"
sudo_version = "1.9.10"
rsync_version = "3.2.3p1"
1 change: 1 addition & 0 deletions var_files/snapshots/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checksum = "sha256:XXXX"
3 changes: 3 additions & 0 deletions var_files/snapshots/common.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
os_version = "snapshots"
sudo_version = "1.9.11.2"
rsync_version = "3.2.5pl0"
2 changes: 2 additions & 0 deletions var_files/snapshots/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
checksum = "sha256:XXXX"
os_number = "72"