Skip to content

Commit

Permalink
Prepare image creation for ubuntu support
Browse files Browse the repository at this point in the history
- Sync partman/early_command and drop TEMPLATE_DEVICE
- Drop unused devpc1 form Makefile
- Fix bugs in mokutil and support virtualbox-dkms
- Relocate preseed data to subdirectory
  • Loading branch information
MTecknology committed Feb 27, 2024
1 parent 8df8a1b commit 0c8ec00
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 158 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# 1. Shellcheck
# Looks for +x files
Expand All @@ -40,7 +40,7 @@ jobs:

# 3. Python Lint
- name: Set Up Python environment
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Flake8 Lint
Expand All @@ -52,7 +52,7 @@ jobs:
##
# Test installed OS from built ISO:
# 1. Build a "teckhost" iso from upstream release
# 2. Install OS on VM using teckhost-sda.iso (testing option)
# 2. Install OS on VM using teckhost.iso (testing option)
# 3. Verify we can log in using the "testuser" account
# 4. Run validation tests against the installed OS
# 5. Ensure make clean produces no errors
Expand All @@ -63,25 +63,26 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install virtualbox libarchive-tools syslinux xorriso isolinux python3-distro coreutils
sudo apt-get install libarchive-tools syslinux xorriso isolinux python3-distro coreutils
# 1. Build a "teckhost" iso from upstream release
- name: Build Teckhost ISO
id: build_iso
run: make teckhost-sda.iso
run: make teckhost-CICD_debian12.iso
env:
THT_GRUBTEST: TEMPLATE_METHOD=lvm BS_pillar_root=test/pillar TH_SALTGPG=https://raw.githubusercontent.com/MTecknology/teckhost/master/test/pillar/skeys.gpg BS_gitfs_pillar_base=master BS_gitfs_base=${{ github.sha }}
THT_GRUBTEST: BS_pillar_root=test/pillar TH_SALTGPG=https://raw.githubusercontent.com/MTecknology/teckhost/master/test/pillar/skeys.gpg BS_gitfs_pillar_base=master BS_gitfs_base=${{ github.sha }}

- name: Save ISO (teckhost-sda.iso)
uses: actions/upload-artifact@v3
- name: Save ISO (teckhost.iso)
uses: actions/upload-artifact@v4
with:
name: teckhost-sda_${{ github.sha }}.iso
path: teckhost-sda.iso
name: teckhost-CICD_debian12-${{ github.sha }}.iso
path: teckhost-CICD_debian12.iso
compression-level: 0

testinstall:
name: "Install and Validate"
Expand All @@ -96,7 +97,7 @@ jobs:

runs-on: macos-12
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand All @@ -105,30 +106,30 @@ jobs:
pip3 install pytest-testinfra distro
#sh ./test/vbox_extpack
- name: Pull ISO (teckhost-sda.iso)
uses: actions/download-artifact@v3
- name: Pull ISO (teckhost.iso)
uses: actions/download-artifact@v4
with:
name: teckhost-sda_${{ github.sha }}.iso
name: teckhost-CICD_debian12-${{ github.sha }}.iso

# 2. Install OS on VM using teckhost-sda.iso (testing option)
# 2. Install OS on VM using teckhost.iso (testing option)
- name: Create VM and Install (Testing) Teckhost
id: install_os
run: touch testseed.cfg; touch teckhost-sda.iso; make testpc1
run: make testpc1_${{ matrix.os }}
env:
TH_ISOPATH: teckhost-sda_${{ github.sha }}.iso
TH_SHOTS: testpc1-${{ matrix.boot }}
TH_BOOT: ${{ matrix.boot }}

- name: (on failure) Package Screenshots
if: failure() && steps.install_os.outcome == 'failure'
run: "tar -vcf testpc1-${{ matrix.boot }}.tar *.png"
run: "tar -vczf testpc1-${{ matrix.boot }}.tgz *.png"

- name: (on failure) Upload Screenshots
if: failure() && steps.install_os.outcome == 'failure'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: testpc1-${{ matrix.boot }}_screenshots.tar
path: testpc1-${{ matrix.boot }}.tar
name: testpc1-${{ matrix.boot }}_screenshots.tgz
path: testpc1-${{ matrix.boot }}.tgz
compression-level: 0

# 3. Verify we can log in using the "testuser" account
- name: User (testuser) Login
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# 1. Pre-Release Checks
- name: Pre-Release Checks
Expand All @@ -43,7 +43,7 @@ jobs:
# 2. Build "Production" ISO (teckhost*.iso)
- name: Build Teckhost ISO
id: build_iso
run: make teckhost.iso teckhost-sda.iso teckhost-nvme0n1.iso
run: make teckhost.iso

# 3. Publish Release w/ Artifacts
- name: Create Release
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ __pycache__
.pytest_cache/

# Makefile
testseed.cfg
testseed.cfg.orig
testseed*
15 changes: 5 additions & 10 deletions HACKING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,15 @@ Download and cache "latest" ``debian-netinst.iso``::
Build the Default ISO::

make teckhost.iso
OR
make teckhost-sda.iso
OR
make teckhost-nvme0n1.iso

Run tests::

make test

Build and log in to dev box (requires virtualbox)::

make devpc1
make devpc1-ssh
make testpc1
make testpc1-ssh

.. _branches:

Expand Down Expand Up @@ -124,11 +120,10 @@ Makefile
Key Targets:

- ``make teckhost.iso``
- ``make teckhost-sda.iso``
- ``make test``
- ``make devpc1``
- ``make devpc1-ssh``
- ``make devpc1-root``
- ``make testpc1_<version>``
- ``make ssh-testpc1-user``
- ``make ssh-testpc1-admin``
- ``make clean``

.. _version w/ firmware: https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/current/amd64/iso-cd/
141 changes: 63 additions & 78 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,32 @@ export WORKSPACE ?= $(abspath $(PWD)/)
export GRUB_EXTRA ?= hostname=testpc1

# Version Table
debian12_src ?= https://cdimage.debian.org/cdimage/archive/12.1.0/amd64/iso-cd/debian-12.1.0-amd64-netinst.iso
debian12_sha ?= 9f181ae12b25840a508786b1756c6352a0e58484998669288c4eec2ab16b8559

debian12_src ?= https://cdimage.debian.org/cdimage/archive/12.4.0/amd64/iso-cd/debian-12.4.0-amd64-netinst.iso
debian12_sha ?= 64d727dd5785ae5fcfd3ae8ffbede5f40cca96f1580aaa2820e8b99dae989d94

##
# ISO
##

# Intended for production use
teckhost.iso: upstream_debian12.iso iso/preseed.cfg iso/grub-bios.cfg iso/grub-efi.cfg
./iso/build_iso \
-s iso/preseed.cfg \
-i upstream_debian12.iso \
-o teckhost.iso \
-x "$(GRUB_EXTRA)" \
-f iso/grub-bios.cfg -g iso/grub-efi.cfg

# Intended for use with automated testing
teckhost-%.iso: upstream_debian12.iso testseed.cfg iso/grub-bios.cfg iso/grub-efi.cfg
./iso/build_iso \
-s testseed.cfg \
-i upstream_debian12.iso \
-o "$@" \
-d "/dev/$*" \
-x "$(GRUB_EXTRA)" \
-f iso/grub-bios.cfg -g iso/grub-efi.cfg

# Intended for local developmnt with virtualbox
teckhost-local.iso: upstream_debian12.iso testseed.cfg iso/grub-bios.cfg iso/grub-efi.cfg
./iso/build_iso \
-s testseed.cfg \
-i upstream_debian12.iso \
-o teckhost-local.iso \
-d /dev/sda \
-x "hostname=devpc1 BS_devdir=/srv" \
-f iso/grub-bios.cfg -g iso/grub-efi.cfg
# Default release
teckhost.iso: teckhost_debian12.iso
cp teckhost_debian12.iso teckhost.iso

# Intended for use in production and development
teckhost_%.iso: upstream_%.iso
./iso/build_iso $(ISOARGS) \
-i upstream_$*.iso -o teckhost_$*.iso \
-f iso/$*/grub-bios.cfg -g iso/$*/grub-efi.cfg \
-x "$(GRUB_EXTRA)" \
-s iso/$*/preseed.cfg

# Intended for use in automated testing
teckhost-CICD_%.iso: upstream_%.iso iso/%/testseed.cfg
./iso/build_iso $(ISOARGS) \
-i upstream_$*.iso -o $@ \
-f iso/$*/grub-bios.cfg -g iso/$*/grub-efi.cfg \
-x "$(GRUB_EXTRA)" \
-s iso/$*/testseed.cfg

# Grab an upstream ISO and validate checksum
upstream_%.iso:
Expand All @@ -55,79 +45,75 @@ upstream_%.iso:


##
# Preeseed
# Test/Dev Stuff
##

testseed.cfg: iso/preseed.cfg test/preseed.patch
cp iso/preseed.cfg testseed.cfg
patch testseed.cfg test/preseed.patch
# Apply minimum patches (hostname, confirmation, etc.) to preseed
iso/%/testseed.cfg: iso/%/preseed.cfg iso/%/preseed_test.patch
cp iso/$*/preseed.cfg iso/$*/testseed.cfg
patch iso/$*/testseed.cfg iso/$*/preseed_test.patch


##
# Test/Dev Stuff
##

# This can't be cleanly checked into git
# File modes in git are not reliable
testprep:
chmod 0700 test/.ssh
chmod 0600 test/.ssh/id_ed25519

# Run all tests against testpc1
test: test-testpc1
test-testpc1: pytest-testpc1-user pytest-testpc1-admin

# Run all tests against devpc1
test-devpc1: pytest-devpc1-user pytest-devpc1-admin
# Create testpc1 and run all {admin,user} tests
test: testpc1_debian12 pytest-testpc1-user pytest-testpc1-admin

# Run tests against a host (test-<host>-<type>)
_target = $(word $2,$(subst -, ,$1))
# Run user-only tests against a host as user:testuser
pytest-%-user:
python3 -m pytest \
--ssh-config=test/.ssh/config \
--ssh-identity-file=test/.ssh/id_ed25519 \
--hosts=ssh://testuser@$* \
--type user

.SECONDEXPANSION:
pytest-%: testprep $$(call _target,$$*,1) explicit_phony
# Run root-required tests against a host as user:testadmin
pytest-%-admin:
python3 -m pytest \
--ssh-config=test/.ssh/config --ssh-identity-file=test/.ssh/id_ed25519 \
--hosts=ssh://test$(call _target,$*,2)@$(call _target,$*,1) \
--type $(call _target,$*,2)
--ssh-config=test/.ssh/config \
--ssh-identity-file=test/.ssh/id_ed25519 \
--hosts=ssh://testadmin@$* \
--type admin

# Connect to a host using ssh as user:testadmin
ssh-%-user: testprep
ssh -F test/.ssh/config -i test/.ssh/id_ed25519 \
ssh://testuser@$*

# Connect to a host using ssh as user:testadmin
ssh-%-admin: testprep
ssh -F test/.ssh/config -i test/.ssh/id_ed25519 \
ssh://testadmin@$*

# Connect to a host using ssh (ssh-<host>-<user>)
ssh-%: $$(call _target,$$*,1) explicit_phony
ssh \
-F test/.ssh/config -i test/.ssh/id_ed25519 \
ssh://test$(call _target,$*,2)@$(call _target,$*,1)

##
# Virtual Machines
##

# TEST: The standard virtualbox deployment; replicates production
testpc1: teckhost-sda.iso
ifneq (,$(findstring testpc1,$(shell VBoxManage list runningvms)))
# Create a testpc1 image using the specified iso
testpc1_%: teckhost-CICD_%.iso
ifneq (,$(findstring testpc1,$(shell VBoxManage list vms)))
echo 'VM already exists: testpc1'
else
./test/vbox_create -i $(WORKSPACE)/teckhost-sda.iso -n testpc1 \
-p 4222
endif

# DEV: Build a dev box using local file directory for salt data
# Note: The first highstate will still be from git
devpc1: teckhost-local.iso
ifneq (,$(findstring devpc1,$(shell VBoxManage list runningvms)))
echo 'VM already exists: devpc1'
else
./test/vbox_create -i $(WORKSPACE)/teckhost-local.iso -n devpc1 \
-p 4224 -d $(WORKSPACE)
./test/vbox_create \
-i $(WORKSPACE)/teckhost-CICD_$*.iso \
-n testpc1 \
-p 4222
endif


##
# Cleanup
##

clean: clean-testpc1 clean-devpc1
$(RM) testseed.cfg* teckhost*.iso
clean: clean-testpc1
$(RM) iso/*/testseed.cfg teckhost*.iso

# Delete a VM if it exists
clean-%: explicit_phony
clean-%:
@if [ -n "$(findstring $*,$(shell VBoxManage list vms))" ]; then \
VBoxManage controlvm $* poweroff || true; \
VBoxManage unregistervm $* --delete; \
Expand All @@ -136,5 +122,4 @@ clean-%: explicit_phony
fi


explicit_phony:
.PHONY: testprep test testpc1 devpc1 clean explicit_phony
.PHONY: testprep test testpc1 clean
Loading

0 comments on commit 0c8ec00

Please sign in to comment.