From 9731a09588af78a05a6ed99f5b163fba95ca6f8b Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Sun, 30 Apr 2023 16:26:16 +0100 Subject: [PATCH] test(packer): add image for opensuse & some cleanup. --- tests/packer/init/init.sh | 27 +++++++++--- tests/packer/init/opensuse-kde.user-data.yml | 33 ++++++++++++++ tests/packer/main.pkr.hcl | 4 +- tests/packer/opensuse.pkr.hcl | 45 ++++++++++++++++++++ tests/packer/src/aa-update | 16 ++++--- 5 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 tests/packer/init/opensuse-kde.user-data.yml create mode 100644 tests/packer/opensuse.pkr.hcl diff --git a/tests/packer/init/init.sh b/tests/packer/init/init.sh index 7cefce5c8..56b133974 100644 --- a/tests/packer/init/init.sh +++ b/tests/packer/init/init.sh @@ -5,24 +5,37 @@ set -eu -# shellcheck source=/dev/null -_lsb_release() { . /etc/os-release; echo "$ID"; } +_lsb_release() { + # shellcheck source=/dev/null + . /etc/os-release + echo "$ID" +} DISTRIBUTION="$(_lsb_release)" readonly SRC=/tmp/src readonly DISTRIBUTION main() { - install -dm0750 -o "$SUDO_USER" -g "$SUDO_USER" "/home/$SUDO_USER/Projects/" "/home/$SUDO_USER/.config/" + install -dm0750 -o "$SUDO_USER" -g "$SUDO_USER" "/home/$SUDO_USER/Projects/" "/home/$SUDO_USER/.config/" install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/.bash_aliases "/home/$SUDO_USER/.bash_aliases" install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/htoprc "/home/$SUDO_USER/.config/htop/htoprc" install -Dm0644 $SRC/parser.conf /etc/apparmor/parser.conf - install -Dm0644 $SRC/site.local /etc/apparmor.d/tunables/etc.d/site.local + install -Dm0644 $SRC/site.local /etc/apparmor.d/tunables/multiarch.d/site.local install -Dm0755 $SRC/aa-update /usr/bin/aa-update chown -R "$SUDO_USER:$SUDO_USER" "/home/$SUDO_USER/.config/" case "$DISTRIBUTION" in - debian | ubuntu) dpkg -i $SRC/apparmor.d_*_all.deb ;; - opensuse*) zypper install -y bash-completion git go htop make rsync vim ;; - arch) pacman --noconfirm -U $SRC/apparmor.d-*-x86_64.pkg.tar.zst ;; + arch) pacman --noconfirm -U $SRC/apparmor.d-*-x86_64.pkg.tar.zst ;; + debian | ubuntu) + apt-get update -y + apt-get install -y apparmor-profiles build-essential config-package-dev \ + debhelper devscripts htop qemu-guest-agent rsync vim + dpkg -i $SRC/apparmor.d_*_all.deb + ;; + + opensuse*) + zypper install -y bash-completion git go htop make rsync vim + sed -i -e '/cache-loc/d' /etc/apparmor/parser.conf + ;; + esac } diff --git a/tests/packer/init/opensuse-kde.user-data.yml b/tests/packer/init/opensuse-kde.user-data.yml new file mode 100644 index 000000000..e334c16c6 --- /dev/null +++ b/tests/packer/init/opensuse-kde.user-data.yml @@ -0,0 +1,33 @@ +#cloud-config + +hostname: ${hostname} +locale: en_IE +keyboard: + layout: ie + +ssh_pwauth: true +users: + - name: ${username} + plain_text_passwd: ${password} + shell: /bin/bash + ssh_authorized_keys: + - ${ssh_key} + lock_passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + +package_update: true +package_upgrade: true +package_reboot_if_required: false +packages: + - bash-completion + - git + - go + - htop + - make + - rsync + - vim + +runcmd: + + # Set some bash aliases + - echo '[[ -f ~/.bash_aliases ]] && source ~/.bash_aliases' >> /home/${username}/.bashrc diff --git a/tests/packer/main.pkr.hcl b/tests/packer/main.pkr.hcl index 6c3e455a4..b039a8a5c 100644 --- a/tests/packer/main.pkr.hcl +++ b/tests/packer/main.pkr.hcl @@ -7,6 +7,8 @@ build { sources = [ "source.qemu.archlinux-gnome", "source.qemu.archlinux-kde", + "source.qemu.debian-server", + "source.qemu.opensuse-kde", "source.qemu.ubuntu-server", ] @@ -22,7 +24,7 @@ build { } provisioner "file" { - only = ["qemu.ubuntu-server", "qemu.ubuntu-desktop"] + only = ["qemu.debian-server", "qemu.ubuntu-server", "qemu.ubuntu-desktop"] destination = "/tmp/src/" sources = ["${path.cwd}/../apparmor.d_${var.version}_all.deb"] } diff --git a/tests/packer/opensuse.pkr.hcl b/tests/packer/opensuse.pkr.hcl new file mode 100644 index 000000000..f86a463b9 --- /dev/null +++ b/tests/packer/opensuse.pkr.hcl @@ -0,0 +1,45 @@ +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2023 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +# TODO: Fully automate the creation of the base image +# To save some dev time, 'base_opensuse_kde' is manually created from the opensuse iso with: +# - KDE +# - username/password defined in the variables +# - cloud-init installed and enabled + +source "qemu" "opensuse-kde" { + disk_image = true + iso_url = "${var.iso_dir}/base_opensuse_kde.qcow2" + iso_checksum = "sha256:62a174725bdf26981d15969e53461b89359f7763450cbfd3e258d4035731279b" + iso_target_path = "${var.iso_dir}/base_opensuse_kde.qcow2" + cpus = 6 + memory = 4096 + disk_size = "${var.disk_size}" + accelerator = "kvm" + headless = false + ssh_username = "${var.username}" + ssh_password = "${var.password}" + ssh_port = 22 + ssh_wait_timeout = "1000s" + disk_compression = true + disk_detect_zeroes = "unmap" + disk_discard = "unmap" + output_directory = "${var.iso_dir}/packer/" + vm_name = "${var.prefix}${source.name}.qcow2" + boot_wait = "10s" + firmware = "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" + shutdown_command = "echo ${var.password} | sudo shutdown -hP now" + cd_label = "cidata" + cd_content = { + "meta-data" = "" + "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", + { + username = "${var.username}" + password = "${var.password}" + ssh_key = file("${var.ssh_publickey}") + hostname = "${var.prefix}${source.name}" + } + ) + } +} diff --git a/tests/packer/src/aa-update b/tests/packer/src/aa-update index e2128923f..b8e3491fb 100644 --- a/tests/packer/src/aa-update +++ b/tests/packer/src/aa-update @@ -1,13 +1,19 @@ #!/usr/bin/env bash set -eu + export BUILDDIR=/tmp/build/ PKGDEST=/tmp/pkg + # shellcheck source=/dev/null -_lsb_release() { . /etc/os-release || exit 1; echo "$ID"; } +_lsb_release() { + . /etc/os-release || exit 1 + echo "$ID" +} DISTRIBUTION="$(_lsb_release)" + cd "$HOME/Projects/apparmor.d" case "$DISTRIBUTION" in -arch) make pkg ;; -debian | ubuntu | whonix) make dpkg ;; -opensuse*) make rpm ;; +arch) make pkg ;; +debian | ubuntu | whonix) make dpkg ;; +opensuse*) make rpm ;; *) ;; -esac \ No newline at end of file +esac