Add virtualbox-iso target

Lots of other, small quality of life improvements to build process
Output of build serial console to artifacts upon failure
Reducing verbosity of Packer, now that serial output is captured
Fixed sizing problems with the boot partitions of Ubuntu versions
Use of Mac builders for Virtualbox targets
Updating Ubuntu builders to 22.04, as well
This commit is contained in:
Greg Hellings
2022-06-08 01:39:37 -05:00
committed by GitHub
parent 288b91a797
commit dea5487a3c
29 changed files with 175 additions and 68 deletions
+4 -3
View File
@@ -17,8 +17,10 @@ runs:
if: runner.os == 'Linux' if: runner.os == 'Linux'
run: | run: |
set -exo pipefail set -exo pipefail
# Install virtualbox
sudo apt-get update sudo apt-get update
sudo apt-get install -y unzip python3-{virtualenv,yaml} cloud-utils qemu-system-{x86,ppc} # Install QEmu, etc
sudo apt-get install -y unzip python3-{virtualenv,yaml} cloud-utils xorriso qemu-system-{x86,ppc}
# Install packer.io # Install packer.io
curl -O https://releases.hashicorp.com/packer/${{ inputs.version }}/packer_${{ inputs.version }}_linux_amd64.zip curl -O https://releases.hashicorp.com/packer/${{ inputs.version }}/packer_${{ inputs.version }}_linux_amd64.zip
unzip -o packer_${{ inputs.version }}_linux_amd64.zip -d /usr/local/bin unzip -o packer_${{ inputs.version }}_linux_amd64.zip -d /usr/local/bin
@@ -31,6 +33,5 @@ runs:
if: runner.os == 'macOS' if: runner.os == 'macOS'
run: | run: |
set -exo pipefail set -exo pipefail
brew install qemu brew install pup dvdrtools xorriso coreutils gsed
brew install pup
# Packer is already installed # Packer is already installed
+20 -10
View File
@@ -25,12 +25,15 @@ jobs:
build: build:
name: Build box name: Build box
runs-on: ubuntu-22.04 runs-on: ${{ matrix.builder == 'virtualbox-iso.x86_64' && 'macOS-12' || 'ubuntu-22.04' }}
needs: needs:
- collect - collect
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
builder:
- virtualbox-iso.x86_64
- qemu.x86_64
distro: ${{ fromJson( needs.collect.outputs.distros ) }} distro: ${{ fromJson( needs.collect.outputs.distros ) }}
needs_timeout: needs_timeout:
- distros/ubuntu-20.04-x86_64.pkrvars.hcl - distros/ubuntu-20.04-x86_64.pkrvars.hcl
@@ -39,28 +42,35 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
- uses: ./.github/actions/setup - name: Setup system dependnecies
uses: ./.github/actions/setup
with: with:
ansible: true ansible: true
- uses: ./.github/actions/install_packer - name: Install Packer and related tools
- uses: greg-hellings/make-space@main uses: ./.github/actions/install_packer
- name: modify build timeouts, if necessary - name: Clear disk space
uses: greg-hellings/make-space@main
- name: Modify build timeouts, if necessary
if: contains(matrix.needs_timeout, matrix.distro) if: contains(matrix.needs_timeout, matrix.distro)
shell: bash shell: bash
run: ./modify_timeout.sh "${{ matrix.distro }}" run: ./modify_timeout.sh "${{ matrix.distro }}"
- name: Run generator, if necessary - name: Run generator, if necessary
if: endsWith(matrix.distro, '.sh') if: endsWith(matrix.distro, '.sh')
run: "${{ matrix.distro }}" run: "${{ matrix.distro }}"
- name: try build - name: Build
shell: bash shell: bash
run: | run: |
set -e set -e
# Strip .sh if it is a dynamic one # Strip .sh if it is a dynamic one
file="$(printf "${{ matrix.distro }}" | sed -E -e 's/^(.*).sh$/\1/')" file="$(printf "${{ matrix.distro }}" | sed -E -e 's/^(.*).sh$/\1/')"
# Add a retry in case something bogus like a network failure happens # Add a retry in case something bogus like a network failure happens
until packer build -var-file="${file}" -var "qemu_accelerator=tcg" ${{ github.event_name != 'release' && '-except=upload' || '' }} sources; do packer build -only="${{ matrix.builder }}" -var-file="${file}" -var "qemu_accelerator=tcg" ${{ github.event_name != 'release' && '-except=upload' || '' }} sources
sleep 1
done
env: env:
VAGRANT_CLOUD_TOKEN: ${{ secrets.VAGRANT_CLOUD_TOKEN }} VAGRANT_CLOUD_TOKEN: ${{ secrets.VAGRANT_CLOUD_TOKEN }}
PACKER_LOG: ${{ contains(matrix.needs_timeout, matrix.distro) && '1' || '1' }} PACKER_LOG: ${{ contains(matrix.needs_timeout, matrix.distro) && '0' || '0' }}
- name: Upload artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: serial-output
path: serial-output*
+3
View File
@@ -2,6 +2,9 @@ output_*
*.box *.box
*.iso *.iso
.vagrant .vagrant
serial-output
grub.cfg
isolinux.cfg
# Generated distros # Generated distros
distros/fedora-rawhide-*.hcl distros/fedora-rawhide-*.hcl
+6 -2
View File
@@ -1,18 +1,22 @@
- name: install guest additions - name: install guest additions
hosts: default hosts: default
pre_tasks: pre_tasks:
- name: update all the things - name: Update all the things
become: true become: true
ansible.builtin.package: # noqa package-latest ansible.builtin.package: # noqa package-latest
name: "*" name: "*"
state: latest state: latest
when: ansible_facts.pkg_mgr not in ['atomic_container'] when: ansible_facts.pkg_mgr not in ['atomic_container']
- name: update atomic things - name: Update atomic things
become: true become: true
ansible.builtin.command: rpm-ostree upgrade ansible.builtin.command: rpm-ostree upgrade
when: ansible_facts.pkg_mgr in ['atomic_container'] when: ansible_facts.pkg_mgr in ['atomic_container']
changed_when: false changed_when: false
- name: Restart the machine
become: true
ansible.builtin.reboot:
roles: roles:
- role: virtualbox - role: virtualbox
when: packer_builder_type == 'virtualbox-iso' when: packer_builder_type == 'virtualbox-iso'
@@ -0,0 +1,3 @@
- hosts: all
roles:
- virtualbox
@@ -0,0 +1,8 @@
driver:
name: containers
provider:
name: libvirt
platforms:
- name: test-ubuntu18-init
image: ubuntu:18.04
box: generic/ubuntu1804
@@ -0,0 +1,8 @@
driver:
name: containers
provider:
name: libvirt
platforms:
- name: test-ubuntu20-init
image: ubuntu:20.04
box: generic/ubuntu2004
+26 -8
View File
@@ -1,10 +1,23 @@
- name: install build deps for virtualbox addons - name: Load version information
ansible.builtin.include_vars: "{{ item }}"
loop:
- "{{ role_path }}/vars/{{ ansible_facts['os_family'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml"
when: item is file
- name: Install build deps for virtualbox addons
become: true become: true
ansible.builtin.package: ansible.builtin.package:
name: "{{ virtualbox_packages }}" name: "{{ virtualbox_packages }}"
state: present state: present
update_cache: true
register: _pkg_install
retries: 3
until: _pkg_install is success
- name: start services - name: Start services
become: true become: true
ansible.builtin.service: ansible.builtin.service:
name: "{{ item }}" name: "{{ item }}"
@@ -12,16 +25,21 @@
enabled: true enabled: true
loop: "{{ virtualbox_services }}" loop: "{{ virtualbox_services }}"
- name: mount iso file - when: virtualbox_from_iso
block:
- name: Mount iso file
become: true become: true
ansible.builtin.command: "{{ item }}" ansible.builtin.command: "{{ item }}"
changed_when: false changed_when: false
failed_when: _cmd.rc not in [0, 2]
register: _cmd
loop: loop:
- mount -o loop,ro {{ ansible_user_dir }}/VBoxGuestAdditions.iso /mnt - mount -o loop,ro {{ virtualbox_iso_location }} /mnt
- /mnt/VBoxLinuxAdditions.run - /mnt/VBoxLinuxAdditions.run --nox11
- umount /mnt - umount /mnt
- name: remove iso - name: Remove packages
ansible.builtin.file: become: true
name: "{{ ansible_user_dir }}/VBoxGuestAdditions.iso" ansible.builtin.package:
name: "{{ virtualbox_remove_packages | default([]) }}"
state: absent state: absent
+1
View File
@@ -6,3 +6,4 @@ virtualbox_packages:
- perl - perl
virtualbox_services: virtualbox_services:
- dkms - dkms
virtualbox_from_iso: true
+11 -2
View File
@@ -1,7 +1,16 @@
virtualbox_packages: virtualbox_packages:
- kernel
- kernel-devel
- kernel-headers
- gcc
- make
- perl
- elfutils-libelf-devel
- tar
- bzip2 - bzip2
- dkms - dkms
- kernel-devel
- make
virtualbox_services: virtualbox_services:
- dkms - dkms
virtualbox_iso_location: "{{ ansible_user_dir }}/VBoxGuestAdditions.iso"
virtualbox_from_iso: true
virtualbox_pre_commands: []
+3 -3
View File
@@ -1,5 +1,5 @@
virtualbox_packages: virtualbox_packages:
- dkms - dkms
- make - virtualbox-guest-dkms
virtualbox_services: virtualbox_services: []
- dkms virtualbox_from_iso: false
@@ -0,0 +1,9 @@
virtualbox_packages:
- virtualbox-guest-utils
- bzip2
- tar
- build-essential
virtualbox_services: []
virtualbox_from_iso: true
virtualbox_iso_location: /home/vagrant/VBoxGuestAdditions.iso
virtualbox_remove_packages: []
+1 -1
View File
@@ -6,5 +6,5 @@ iso = {
} }
boot_command = [ boot_command = [
"<up><tab><bs><bs><bs><bs><bs>", "<up><tab><bs><bs><bs><bs><bs>",
"net.ifnames=0 biosdevnames=0 inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/fedora/36-x86_64.ks console=ttyS0 <enter><wait>" "net.ifnames=0 biosdevnames=0 inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/fedora/36-x86_64.ks console=ttyS0 console=tty0<enter><wait>"
] ]
+1 -1
View File
@@ -35,7 +35,7 @@ iso = {
} }
boot_command = [ boot_command = [
"<up><tab><bs><bs><bs><bs><bs>", "<up><tab><bs><bs><bs><bs><bs>",
"net.ifnames=0 biosdevnames=0 inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/fedora/rawhide-x86_64.ks console=ttyS0 <enter><wait>" "edd=off net.ifnames=0 biosdevnames=0 inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/fedora/rawhide-x86_64.ks console=ttyS0 <enter><wait>"
] ]
EOF EOF
+1
View File
@@ -14,5 +14,6 @@ boot_command = [
"preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/ubuntu/18.04/preseed.cfg ", "preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/ubuntu/18.04/preseed.cfg ",
"fsck.mode=skip ", "fsck.mode=skip ",
"console=ttyS0 ", "console=ttyS0 ",
"console=tty0 ",
"<enter><wait1>" "<enter><wait1>"
] ]
+1
View File
@@ -8,6 +8,7 @@ boot_wait = "3s"
boot_command = [ boot_command = [
"<enter><enter><wait1><f6><esc><wait><bs><bs><bs><bs>", "<enter><enter><wait1><f6><esc><wait><bs><bs><bs><bs>",
"console=ttyS0 ", "console=ttyS0 ",
"console=tty0 ",
"fsck.mode=skip ", "fsck.mode=skip ",
"autoinstall ds=nocloud-net;s=http://{{.HTTPIP}}:{{.HTTPPort}}/ubuntu/20.04/<enter><wait>" "autoinstall ds=nocloud-net;s=http://{{.HTTPIP}}:{{.HTTPPort}}/ubuntu/20.04/<enter><wait>"
] ]
+4
View File
@@ -8,4 +8,8 @@ ks=$(printf "${cmdline}" | sed -E -e 's/.*inst\.ks=([^ ]*).*/\1/')
mkdir -p /tmp/packer_ks mkdir -p /tmp/packer_ks
cd /tmp/packer_ks cd /tmp/packer_ks
wget -m -nH "$(dirname "${ks}")" wget -m -nH "$(dirname "${ks}")"
if [ ! -e /dev/vda ]; then
ln -s /dev/sda /dev/vda
fi
%end %end
+4
View File
@@ -16,4 +16,8 @@ ks=$(printf "${cmdline}" | sed -E -e 's/.*inst\.ks=([^ ]*).*/\1/')
mkdir -p /tmp/packer_ks mkdir -p /tmp/packer_ks
cd /tmp/packer_ks cd /tmp/packer_ks
wget -m -nH "$(dirname "${ks}")" wget -m -nH "$(dirname "${ks}")"
if [ ! -e /dev/vda ]; then
ln -s /dev/sda /dev/vda
fi
%end %end
+4
View File
@@ -16,4 +16,8 @@ ks=$(printf "${cmdline}" | sed -E -e 's/.*inst\.ks=([^ ]*).*/\1/')
mkdir -p /tmp/packer_ks mkdir -p /tmp/packer_ks
cd /tmp/packer_ks cd /tmp/packer_ks
wget -m -nH "$(dirname "${ks}")" wget -m -nH "$(dirname "${ks}")"
if [ ! -e /dev/vda ]; then
ln -s /dev/sda /dev/vda
fi
%end %end
+4
View File
@@ -16,4 +16,8 @@ ks=$(printf "${cmdline}" | sed -E -e 's/.*inst\.ks=([^ ]*).*/\1/')
mkdir -p /tmp/packer_ks mkdir -p /tmp/packer_ks
cd /tmp/packer_ks cd /tmp/packer_ks
wget -m -nH "$(dirname "${ks}")" wget -m -nH "$(dirname "${ks}")"
if [ ! -e /dev/vda ]; then
ln -s /dev/sda /dev/vda
fi
%end %end
+11 -1
View File
@@ -2,12 +2,22 @@
# vim: set ft=yaml: # vim: set ft=yaml:
autoinstall: autoinstall:
version: 1 version: 1
apt:
preserve_sources_list: false
primary:
- arches: [i386, amd64]
uri: http://archive.ubuntu.com/ubuntu
- arches: [default]
uri: http://ports.ubuntu.com/ubuntu-ports
geoip: false
network: # Should disable networking, workaround for unattended-updates failing in install network: # Should disable networking, workaround for unattended-updates failing in install
version: 2 version: 2
refresh-installer: refresh-installer:
update: no update: no
keyboard: keyboard:
layout: us layout: us
variant: ""
toggle: null
storage: storage:
config: config:
- id: drive - id: drive
@@ -25,7 +35,7 @@ autoinstall:
- id: boot-partition - id: boot-partition
type: partition type: partition
device: drive device: drive
size: 200M size: 1G
name: boot name: boot
- id: swap-partition - id: swap-partition
type: partition type: partition
+18 -25
View File
@@ -7,39 +7,32 @@ distro="${1}"
url="$(cat "${distro}" | grep url | cut -f2 -d'"')" url="$(cat "${distro}" | grep url | cut -f2 -d'"')"
curl -C - -O "${url}" curl -C - -O "${url}"
# Mount and copy # Mount and extract
file=$(printf "${url}" | sed -E -e 's#.*/(.*)$#\1#') file=$(printf "${url}" | sed -E -e 's#.*/(.*)$#\1#')
old=$(mktemp -d) work="$(mktemp -d)"
new=$(mktemp -d) xorriso -osirrox on -indev "${file}" -extract / "${work}"
sudo mount -t iso9660 -o loop "${file}" "${old}"
{
cd "${old}"
tar -cvf - . | (cd "${new}" && tar -xf -)
cd -
}
# Modify timeout # Modify timeout
chmod +w "${new}/boot/grub" "${new}/boot/grub/grub.cfg" chmod -R +w "${work}"
chmod +w "${new}/isolinux" "${new}/isolinux/isolinux.cfg" sed -i -e 's/set timeout=.*/set timeout=30/' "${work}/boot/grub/grub.cfg"
sed -i -e 's/set timeout=.*/set timeout=30/' "${new}/boot/grub/grub.cfg" sed -i -e 's/timeout.*/timeout 300/' "${work}/isolinux/isolinux.cfg" # Uses 10ths of a second
sed -i -e 's/timeout.*/timeout 300/' "${new}/isolinux/isolinux.cfg" # Uses 10ths of a second chmod -R -w "${work}"
chmod -w "${new}/boot/grub" "${new}/boot/grub/grub.cfg"
chmod -w "${new}/isolinux" "${new}/isolinux/isolinux.cfg"
cat "${new}/boot/grub/grub.cfg"
cat "${new}/isolinux/isolinux.cfg"
# Create new ISO file # Create new ISO file
sudo umount "${old}"
rm "${file}" rm "${file}"
chmod +w "${new}/isolinux/isolinux.bin" chmod +w "${work}/ubuntu" "${work}/isolinux/isolinux.bin"
mkisofs -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "Boot" -r -iso-level 4 -chrp-boot -o "${file}" "${new}" mkisofs -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "Boot" -r -iso-level 3 -chrp-boot -o "${file}" "${work}"
new_sum=$(sha256sum "${file}" | cut -f1 -d' ') new_sum=$(sha256sum "${file}" | cut -f1 -d' ')
# Update distro file # Update distro file
sed -i "${distro}" -e "s/checksum = \".*\"/checksum = \"${new_sum}\"/" if [ "$(uname)" == "Darwin" ]; then
sed -i "${distro}" -e "s/url = \".*\"/url = \"${file}\"/" SED=$(which gsed)
sed -i "${distro}" -e "s/boot_wait = \".*\"/boot_wait = \"15s\"/" else
SED=$(which sed)
fi
"${SED}" -i -e "s/checksum = \".*\"/checksum = \"${new_sum}\"/" "${distro}"
"${SED}" -i -e "s/url = \".*\"/url = \"${file}\"/" "${distro}"
"${SED}" -i -e "s/boot_wait = \".*\"/boot_wait = \"15s\"/" "${distro}"
# Cleanup remaining directories # Cleanup remaining directories
rm -r "${old}" rm -r "${work}" || true
#sudo rm -r "${new}"
+2 -2
View File
@@ -6,12 +6,12 @@ set -x
rm -rf /home/vagrant/.ansible rm -rf /home/vagrant/.ansible
sudo rm -rf /root/.ansible sudo rm -rf /root/.ansible
#if [[ "${PACKER_BUILD_NAME}" != *"silverblue"* ]]; then if [ ! -e /etc/fedora-release ]; then
sudo dd if=/dev/zero of=/var/EMPTY bs=1M || : sudo dd if=/dev/zero of=/var/EMPTY bs=1M || :
sync sync
sudo rm /var/EMPTY sudo rm /var/EMPTY
sync sync
#fi fi
# In CentOS 7, blkid returns duplicate devices # In CentOS 7, blkid returns duplicate devices
swap_device_uuid=`sudo /sbin/blkid -t TYPE=swap -o value -s UUID | uniq` swap_device_uuid=`sudo /sbin/blkid -t TYPE=swap -o value -s UUID | uniq`
+1
View File
@@ -1,6 +1,7 @@
build { build {
sources = [ sources = [
"source.qemu.x86_64", "source.qemu.x86_64",
"source.virtualbox-iso.x86_64"
] ]
provisioner "ansible" { provisioner "ansible" {
+4 -1
View File
@@ -24,7 +24,10 @@ source "qemu" "x86_64" {
disk_cache = "writeback" disk_cache = "writeback"
format = "qcow2" format = "qcow2"
qemuargs = [["-serial", "stdio"]] qemuargs = [
["-chardev", "stdio,id=char0,logfile=serial-output-qemu-${var.arch}-${var.distro}-${var.version},signal=off"],
["-serial", "chardev:char0"]
]
http_directory = "http" http_directory = "http"
accelerator = var.qemu_accelerator accelerator = var.qemu_accelerator
} }
+6
View File
@@ -18,6 +18,12 @@ source "virtualbox-iso" "x86_64" {
memory = local.memory memory = local.memory
headless = var.headless headless = var.headless
guest_os_type = "${var.distro}_64" guest_os_type = "${var.distro}_64"
guest_additions_url = "http://download.virtualbox.org/virtualbox/6.1.34/VBoxGuestAdditions_6.1.34.iso"
guest_additions_sha256 = "88f86fa0e6970b6a7c80d714b7a91a8c425ff8ef53a3e73fc80781191a87257b"
vboxmanage = [
["modifyvm", "{{ .Name }}", "--uart1", "0x3F8", "4"],
["modifyvm", "{{ .Name }}", "--uartmode1", "file", "serial-output-virtualbox-${var.arch}-${var.distro}-${var.version}"]
]
http_directory = "http" http_directory = "http"
} }
+3 -1
View File
@@ -3,8 +3,10 @@
set -exo pipefail set -exo pipefail
build="${1}" build="${1}"
provider=virtualbox-iso.x86_64
#provider=qemu.x86_64
packer build -var headless=false -var-file distros/${build}.pkrvars.hcl -except=upload sources/ packer build -on-error=ask -var headless=false -var-file distros/${build}.pkrvars.hcl -except=upload -only=${provider} sources/
vagrant box add -f --name test ${build}.box vagrant box add -f --name test ${build}.box
vagrant up vagrant up
vagrant ssh -c "ls -la ~/" vagrant ssh -c "ls -la ~/"