Skip to content

Commit

Permalink
Begin using pre-generated test image (Closes: #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
MTecknology committed Jul 22, 2024
1 parent 85f2c1e commit 144b804
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 38 deletions.
89 changes: 52 additions & 37 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ jobs:
##
# Test installed OS from built ISO:
# 1. Build a "teckhost" iso from upstream release
# 2. Install OS on VM using teckhost.iso (testing option)
# Replaced with OVA: 2. Install OS on VM using teckhost.iso (testing option)
# 2. Deploy Testing VM from Release OVA
# 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 @@ -77,16 +78,18 @@ jobs:
env:
THT_GRUBTEST: hostname=testpc1 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.iso)
uses: actions/upload-artifact@v4
with:
name: teckhost_debian12-${{ github.sha }}.iso
path: teckhost_debian12.iso
compression-level: 0
# Disabled: OVA
#- name: Save ISO (teckhost.iso)
# uses: actions/upload-artifact@v4
# with:
# name: teckhost_debian12-${{ github.sha }}.iso
# path: teckhost_debian12.iso
# compression-level: 0

testinstall:
name: "Install and Validate"
needs: buildiso
# Disabled:_OVA
#needs: buildiso

strategy:
matrix:
Expand All @@ -95,48 +98,59 @@ jobs:
#os: [debian11, debian12]
os: [debian12]

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

- name: Install Dependencies
run: |
brew install coreutils
#brew install --cask virtualbox
brew install --cask virtualbox
pip3 install pytest-testinfra distro
#sh ./test/vbox_extpack
- name: Pull ISO (teckhost.iso)
uses: actions/download-artifact@v4
with:
name: teckhost_debian12-${{ github.sha }}.iso

sh ./test/vbox_extpack
# Disabled: OVA
#- name: Pull ISO (teckhost.iso)
# uses: actions/download-artifact@v4
# with:
# name: teckhost_debian12-${{ github.sha }}.iso
#
# 2. Install OS on VM using teckhost.iso (testing option)
- name: Create VM and Install (Testing) Teckhost
#- name: Create VM and Install (Testing) Teckhost
# id: install_os
# run: make testpc1_${{ matrix.os }}
# env:
# TH_SHOTS: testpc1-${{ matrix.boot }}
# TH_BOOT: ${{ matrix.boot }}
#
#- name: (on failure) Package Screenshots
# if: failure() && steps.install_os.outcome == 'failure'
# run: "tar -vczf testpc1-${{ matrix.boot }}.tgz *.png"
#
#- name: (on failure) Upload Screenshots
# if: failure() && steps.install_os.outcome == 'failure'
# uses: actions/upload-artifact@v4
# with:
# name: testpc1-${{ matrix.boot }}_screenshots.tgz
# path: testpc1-${{ matrix.boot }}.tgz
# compression-level: 0
#
# 2. Deploy Testing VM from Release OVA
- name: Create VM from (Testing) OVA
id: install_os
run: make testpc1_${{ matrix.os }}
env:
TH_SHOTS: testpc1-${{ matrix.boot }}
TH_BOOT: ${{ matrix.boot }}

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

- name: (on failure) Upload Screenshots
if: failure() && steps.install_os.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: testpc1-${{ matrix.boot }}_screenshots.tgz
path: testpc1-${{ matrix.boot }}.tgz
compression-level: 0
run: |
touch teckhost_${{ matrix.os }}.iso
make import-testpc1_${{ matrix.os }}
VBoxManage modifyvm testpc1 --vram 7 --paravirtprovider legacy
VBoxManage startvm testpc1 --type headless
sleep 90
# 3. Verify we can log in using the "testuser" account
- name: User (testuser) Login
- name: Prep and Ping
id: basic_validation
run: |
make testprep
ssh -v -o "StrictHostKeyChecking=no" -i test/.ssh/id_ed25519 ssh://testuser@localhost:4222 'echo ping'
ssh -4 -v -o StrictHostKeyChecking=no -o ConnectTimeout=10 -i test/.ssh/id_ed25519 ssh://testuser@localhost:4222 'echo ping'
# 4. Run validation tests against the installed OS
- name: Validation Tests
Expand All @@ -155,7 +169,8 @@ jobs:

deploy:
name: Deploy Changes
needs: [lint, testinstall]
#OVA: needs: [lint, testinstall]
needs: [lint, buildiso, testinstall]
if: github.ref == 'refs/heads/master'

permissions:
Expand Down
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
##
export WORKSPACE ?= $(abspath $(PWD)/)

##
# Version Table
##

# Current Debian Stable
debian12_src ?= https://cdimage.debian.org/cdimage/archive/12.5.0/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso
debian12_sha ?= 013f5b44670d81280b5b1bc02455842b250df2f0c6763398feb69af1a805a14f

# Current Ubuntu LTS
ubuntu2204_src ?= https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso
ubuntu2204_sha ?= 510ce77afcb9537f198bc7daa0e5b503b6e67aaed68146943c231baeaab94df1

# Latest Test Images
debian12_OVA_src ?= https://storage.googleapis.com/teckhost/testpc1_debian12-v1.2.ova
debian12_OVA_sha ?= 723d7e54f4cf706dafc47a5b80d799b716401c5b4b032e5289cfde2f02d9e63b

##
# ISO
##
Expand All @@ -33,6 +43,16 @@ upstream_%.iso:
# Move into location to verify success
mv "$($*_sha).iso" "upstream_$*.iso"

# Grab an upstream ISO and validate checksum
# TODO: Remove duplication with above
upstream_%.ova:
# Copy iso from parent directory or download fresh copy
cp "../$($*_OVA_sha).ova" ./ || wget --quiet -O "$($*_OVA_sha).ova" "$($*_OVA_src)"
# Verify checksum of pristine ova
echo "$($*_OVA_sha) $($*_OVA_sha).ova" | sha256sum -c
# Move into location to verify success
mv "$($*_OVA_sha).ova" "upstream_$*.ova"


##
# Test/Dev Stuff
Expand Down Expand Up @@ -87,19 +107,31 @@ ssh-%-admin: testprep
testpc1_%: teckhost_%.iso
ifneq (,$(findstring testpc1,$(shell VBoxManage list vms)))
echo 'VM already exists: testpc1'
ifeq (,$(findstring testpc1,$(shell VBoxManage list runningvms)))
VBoxManage startvm testpc1 --type headless && sleep 60
endif
else
./test/vbox_create \
-i $(WORKSPACE)/teckhost_$*.iso \
-n testpc1 -p 4222
endif

# Import a previously-generated test image
import-testpc1_%: upstream_%.ova
ifneq (,$(findstring testpc1,$(shell VBoxManage list vms)))
echo 'VM already exists: testpc1'
else
VBoxManage import upstream_$*.ova --vsys 0 \
--eula accept --vmname testpc1
endif


##
# Cleanup
##

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

# Delete a VM if it exists
clean-%:
Expand Down
54 changes: 54 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,59 @@ Bare Metal:
:align: center
:alt: teckhost-lifecycle

GA Prebuild
-----------

Prior to Teckhost v1.2, Github Actions ran through the entire build process,
including a fresh installation from a generated VM. Each Github Action workflow
took 40-80 minutes to complete and often took multiple attempts before success.

Starting with v1.2, a manually-generated OVA is uploaded to the github release
and then used by future workflows to prime the installation.

To create ``testpc1.ova``:

1. ``make clean test``
2. Wait for all tests to succeed
3. Within VM::

# Update
apt update
apt upgrade -y
reboot # if kernel was updated

# Clean apt
apt autoremove -y
apt clean
rm /var/lib/apt/lists/* 2>/dev/null

# Fix boot
/sbin/grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable --boot-directory=/boot/efi --bootloader-id=grub /dev/sda1

# Reclaim zeros
service cron stop
for i in / /var/ /tmp/; do cat /dev/zero >"${i}zero"; rm "${i}zero"; done
shutdown -h now

4. Compress disk::

VBoxManage modifyhd --compact testpc1/disk0.vdi

5. VBox > Machine > Export to OCI

- Format: v2.0
- File: testpc1_debian12-v0.0.ova [template]
- Product: Teckhost
- Product-URL: https://github.com/MTecknology/teckhost
- Version: v0.0
- CPU: 2
- RAM: 1024 MB

6. Upload this OVA file to GCP Cloud Storage
7. Edit Access > ``Public, allUsers, Reader``
8. Update file and checksum in ``Makefile`` (use "Public URL" link)
9. Push the change and verify tests succeed

.. _bootstrap:

Salt Bootstrap
Expand Down Expand Up @@ -88,6 +141,7 @@ To encrypt data for pillar::

.. _state.highstate: https://docs.saltproject.io/en/latest/topics/tutorials/states_pt1.html


.. |cicd-release| image:: https://github.com/MTecknology/teckhost/actions/workflows/cicd.yml/badge.svg?branch=cicd-release
:target: https://github.com/MTecknology/teckhost/actions/workflows/cicd.yml
:alt: CI/CD
Expand Down
1 change: 1 addition & 0 deletions test/.ssh/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Host testpc1
Hostname localhost
Port 4222
StrictHostKeyChecking no
ConnectTimeout 10

0 comments on commit 144b804

Please sign in to comment.