Skip to content

Commit

Permalink
Finish reducing and compartmentalizing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MTecknology committed Feb 28, 2024
1 parent 0c8ec00 commit 9e16bb5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 63 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ jobs:
# 1. Build a "teckhost" iso from upstream release
- name: Build Teckhost ISO
id: build_iso
run: make teckhost-CICD_debian12.iso
run: make teckhost_debian12.iso
env:
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 }}
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-CICD_debian12-${{ github.sha }}.iso
path: teckhost-CICD_debian12.iso
name: teckhost_debian12-${{ github.sha }}.iso
path: teckhost_debian12.iso
compression-level: 0

testinstall:
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Pull ISO (teckhost.iso)
uses: actions/download-artifact@v4
with:
name: teckhost-CICD_debian12-${{ github.sha }}.iso
name: teckhost_debian12-${{ github.sha }}.iso

# 2. Install OS on VM using teckhost.iso (testing option)
- name: Create VM and Install (Testing) Teckhost
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: '0'
ref: cicd-release
Expand Down
29 changes: 9 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# See env[TH_SRC] and env[TH_CKSUM] for ISO building
##
export WORKSPACE ?= $(abspath $(PWD)/)
export GRUB_EXTRA ?= hostname=testpc1

# Version Table
debian12_src ?= https://cdimage.debian.org/cdimage/archive/12.4.0/amd64/iso-cd/debian-12.4.0-amd64-netinst.iso
debian12_sha ?= 64d727dd5785ae5fcfd3ae8ffbede5f40cca96f1580aaa2820e8b99dae989d94
ubuntu2204_src ?= https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso
ubuntu2204_sha ?= 510ce77afcb9537f198bc7daa0e5b503b6e67aaed68146943c231baeaab94df1

##
# ISO
Expand All @@ -18,21 +19,10 @@ debian12_sha ?= 64d727dd5785ae5fcfd3ae8ffbede5f40cca96f1580aaa2820e8b99dae989d94
teckhost.iso: teckhost_debian12.iso
cp teckhost_debian12.iso teckhost.iso

# Intended for use in production and development
# Remaster an upstream ISO with teckhost bootstrapping
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
./iso/build_iso $(ISOARGS) -d iso/$* \
-i upstream_$*.iso -o teckhost_$*.iso

# Grab an upstream ISO and validate checksum
upstream_%.iso:
Expand Down Expand Up @@ -94,14 +84,13 @@ ssh-%-admin: testprep
##

# Create a testpc1 image using the specified iso
testpc1_%: teckhost-CICD_%.iso
testpc1_%: teckhost_%.iso
ifneq (,$(findstring testpc1,$(shell VBoxManage list vms)))
echo 'VM already exists: testpc1'
else
./test/vbox_create \
-i $(WORKSPACE)/teckhost-CICD_$*.iso \
-n testpc1 \
-p 4222
-i $(WORKSPACE)/teckhost_$*.iso \
-n testpc1 -p 4222
endif


Expand All @@ -122,4 +111,4 @@ clean-%:
fi


.PHONY: testprep test testpc1 clean
.PHONY: testprep test clean
60 changes: 29 additions & 31 deletions iso/build_iso
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ main() {

# Build customized ISO with preseed
unpack_source
inject_grubconfig
inject_preseed
build_iso
case "$TH_DST" in
(*debian*)
[ -f "$TH_DATA/testseed.cfg" ] || make "$TH_DATA/testseed.cfg"
inject_preseed
inject_grubconfig
;;
(*ubuntu*)
echo TODO
;;
esac
repack_iso

# Clean up temp data
if is_true "$TH_KEEP"; then
Expand All @@ -30,24 +38,18 @@ parse_options() {
# Defaults
export TH_SRC="${TH_SRC:-./debian-netinst.iso}"
export TH_DST="${TH_DST:-./teckhost.iso}"
export TH_SEED="${TH_SEED:-preseed.cfg}"
export TH_GRUBb="${TH_GRUBb:-./grub-bios.cfg}"
export TH_GRUBe="${TH_GRUBe:-./grub-efi.cfg}"
export THT_GRUBTEST="${THT_GRUBTEST:-BS_pillar_root=test/pillar BS_gitfs_base=master TH_SALTGPG=https://raw.githubusercontent.com/MTecknology/teckhost/master/test/pillar/skeys.gpg}"
export THT_GRUBTXTRA="${THT_GRUBTXTRA}"
export TH_DATA="${TH_DATA:-./iso/debian12}"
export THT_GRUBTEST="${THT_GRUBTEST:-hostname=testpc1 BS_pillar_root=test/pillar BS_gitfs_base=master TH_SALTGPG=https://raw.githubusercontent.com/MTecknology/teckhost/master/test/pillar/skeys.gpg}"
export TH_KEEP="${TH_KEEP:-False}"
export LOG_LEVEL="${LOG_LEVEL:-1}"

while getopts 'i:o:s:f:g:kd:b:x:l:h' OPT; do
while getopts 'i:o:d:kb:l:h' OPT; do
case "$OPT" in
i) TH_SRC="$OPTARG";;
o) TH_DST="$OPTARG";;
s) TH_SEED="$OPTARG";;
f) TH_GRUBb="$OPTARG";;
g) TH_GRUBe="$OPTARG";;
d) TH_DATA="$OPTARG";;
k) TH_KEEP=True;;
b) THT_GRUBTEST="$OPTARG";;
x) THT_GRUBTXTRA="$OPTARG";;
l) LOG_LEVEL="$OPTARG";;
h) show_help; exit 1;;
*) die "Unexpected argument provided: '$OPT'";;
Expand All @@ -69,10 +71,7 @@ show_help() {
Options:
-i X${t}Pristine ISO to be modified (can be http)
-o X${t}Output ISO
-s X${t}Preseed template to embed into ISO
-f X${t}Grub (bios) configuration file
-g X${t}Grub (efi) configuration file
-d X${t}Installation device
-d X${t}Directory with source data for ISO modification
-b X${t}Options added to test entry in grub boot menu (replace)
-x X${t}Additional options added to test entry (append)
-l X${t}Log level (0=Debug, 1=Info, 2=Warn, 3=Error)
Expand All @@ -82,12 +81,9 @@ show_help() {
Defaults (can be set as environment variables):
TH_SRC${t}./debian-netinst.iso
TH_DST${t}./teckhost.iso
TH_SEED${t}./preseed.cfg
TH_GRUBb${t}./grub-bios.cfg
TH_GRUBe${t}./grub-efi.cfg
TH_DATA${t}./iso/debian12
TH_KEEP${t}True
THT_GRUBTEST${t}BS_pillar_root=test/pillar TH_SALTGPG=https://raw.githubusercontent.com/MTecknology/teckhost/master/test/pillar/skeys.gpg
THT_GRUBTXTRA${t}""
LOG_LEVEL${t}1 (info)
EOF
}
Expand All @@ -101,8 +97,7 @@ safety_checks() {
done

# Verify provided values point at files
[ -f "$TH_SEED" ] || die 'Seed file not found'
[ -f "$TH_GRUBe" ] || die 'Grub v2 configuration not found'
[ -d "$TH_DATA" ] || die 'Data directory not found'

# Other option checks
is_int "$LOG_LEVEL" || die 'Log level must be an integer (0-3)'
Expand All @@ -124,15 +119,16 @@ inject_grubconfig() {
log "$DEBUG" 'Copying grub config'

# Copy template and update template value(s)
sed -e "s|TEMPLATE_GRUBTEST|$THT_GRUBTEST $THT_GRUBTXTRA|" "$TH_GRUBb" >"$TH_TEMP/isolinux/menu.cfg"
sed -e "s|TEMPLATE_GRUBTEST|$THT_GRUBTEST $THT_GRUBTXTRA|" "$TH_GRUBe" >"$TH_TEMP/boot/grub/grub.cfg"
sed -e "s|TEMPLATE_GRUBTEST|$THT_GRUBTEST|" "$TH_DATA/grub-bios.cfg" >"$TH_TEMP/isolinux/menu.cfg"
sed -e "s|TEMPLATE_GRUBTEST|$THT_GRUBTEST|" "$TH_DATA/grub-efi.cfg" >"$TH_TEMP/boot/grub/grub.cfg"
}

# Inject a custom preseed into initrd
inject_preseed() {
log "$DEBUG" 'Generating preseed file'
# Copy template
cp "$TH_SEED" "$TH_TEMP/preseed.cfg"
log "$DEBUG" 'Injecting preseed file'
# Copy preseed and testseed config files
cp "$TH_DATA/preseed.cfg" "$TH_TEMP/mainseed.cfg"
cp "$TH_DATA/testseed.cfg" "$TH_TEMP/"

# Not the cleanest assumption, but we error if files are missisg
basedir="$(dirname "$0")/../"
Expand All @@ -145,20 +141,22 @@ inject_preseed() {
log "$DEBUG" 'Injecting preseed into initrd'
pushd "$TH_TEMP" >/dev/null || return 1
gunzip install.amd/initrd.gz
echo 'preseed.cfg' | cpio --quiet -o -H newc -A -F install.amd/initrd
# NOTE: preseed.cfg is *always* loaded
echo 'mainseed.cfg' | cpio --quiet -o -H newc -A -F install.amd/initrd
echo 'testseed.cfg' | cpio --quiet -o -H newc -A -F install.amd/initrd
gzip install.amd/initrd
find . -follow -type f -print0 2>/dev/null | xargs --null md5sum >md5sum.txt
popd >/dev/null || return 1
}

# Build the modified ISO
build_iso() {
repack_iso() {
log "$INFO" "Bulding ISO at $TH_DST"
# Some weird requirement; things break without it
chmod -R -w "$TH_TEMP"
# command partially copied from iso in .disk/isofs
# see: https://wiki.debian.org/RepackBootableISO
xorriso -as mkisofs -quiet -r -V 'Debian Teckhost amd64' \
xorriso -as mkisofs -quiet -r -V 'Teckhost Installer' \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 \
-boot-info-table -no-emul-boot -eltorito-alt-boot \
Expand Down
6 changes: 3 additions & 3 deletions iso/debian12/grub-bios.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ label installplain
menu label Teckhost auto-install w/ ^LVM
menu default
kernel /install.amd/vmlinuz
append auto=true priority=high initrd=/install.amd/initrd.gz TEMPLATE_METHOD=lvm
append auto=true priority=high initrd=/install.amd/initrd.gz TEMPLATE_METHOD=lvm /cdrom/mainseed.cfg
label installcrypto
menu label Teckhost auto-install w/ En^crypted LVM
kernel /install.amd/vmlinuz
append auto=true priority=high initrd=/install.amd/initrd.gz TEMPLATE_METHOD=crypto
append auto=true priority=high initrd=/install.amd/initrd.gz TEMPLATE_METHOD=crypto /cdrom/mainseed.cfg
label installtesting
menu label Teckhost auto-install w/ FOR ^Testing
kernel /install.amd/vmlinuz
append auto=true priority=high initrd=/install.amd/initrd.gz TEMPLATE_METHOD=lvm partman-efi/non_efi_system=false TEMPLATE_GRUBTEST
append auto=true priority=high initrd=/install.amd/initrd.gz TEMPLATE_METHOD=lvm file=/cdrom/testseed.cfg partman-efi/non_efi_system=false TEMPLATE_GRUBTEST
label rescue
menu label ^Rescue mode
kernel /install.amd/vmlinuz
Expand Down
6 changes: 3 additions & 3 deletions iso/debian12/grub-efi.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ play 960 440 1 0 4 440 1
set theme=/boot/grub/theme/1
menuentry --hotkey=l 'Teckhost auto-install w/ LVM' {
set background_color=black
linux /install.amd/vmlinuz auto=true priority=high TEMPLATE_METHOD=lvm
linux /install.amd/vmlinuz auto=true priority=high TEMPLATE_METHOD=lvm file=/cdrom/mainseed.cfg
initrd /install.amd/initrd.gz
}
menuentry --hotkey=c 'Teckhost auto-install w/ Encrypted LVM' {
set background_color=black
linux /install.amd/vmlinuz auto=true priority=high TEMPLATE_METHOD=crypto
linux /install.amd/vmlinuz auto=true priority=high TEMPLATE_METHOD=crypto file=/cdrom/mainseed.cfg
initrd /install.amd/initrd.gz
}
menuentry --hotkey=t 'Teckhost auto-install FOR TESTING' {
set background_color=black
linux /install.amd/vmlinuz auto=true priority=high TEMPLATE_METHOD=lvm TEMPLATE_GRUBTEST
linux /install.amd/vmlinuz auto=true priority=high TEMPLATE_METHOD=lvm file=/cdrom/testseed.cfg TEMPLATE_GRUBTEST
initrd /install.amd/initrd.gz
}
menuentry --hotkey=r 'Rescue mode' {
Expand Down

0 comments on commit 9e16bb5

Please sign in to comment.