1
0
Fork 0
mirror of https://github.com/JasonN3/build-container-installer.git synced 2025-12-25 02:47:56 +01:00

Split Makfile and move workflow to Makefile (#88)

Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
This commit is contained in:
Jason N 2024-04-04 16:32:52 -04:00 committed by GitHub
parent 662f1a94e4
commit b669420287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 800 additions and 665 deletions

23
test/Makefile Normal file
View file

@ -0,0 +1,23 @@
all: $(filter-out README.md Makefile,$(wildcard *))
$(filter-out README.md Makefile,$(wildcard *)):
$(eval DIR=$(firstword $(subst /, ,$@)))
$(MAKE) -w -C $(DIR)
$(filter-out README.md Makefile,$(wildcard */*)):
$(eval DIR=$(firstword $(subst /, ,$@)))
$(eval TARGET=$(subst $(DIR)/,,$@))
$(MAKE) -w -C $(DIR) $(TARGET)
.DEFAULT:
$(eval DIR=$(firstword $(subst /, ,$@)))
$(if $(filter-out $(DIR),$@), $(eval TARGET=$(subst $(DIR)/,,$@)),$(eval TARGET=))
$(MAKE) -w -C $(DIR) $(TARGET)
install-deps:
$(foreach DIR,$(filter-out README.md Makefile,$(wildcard *)),$(MAKE) -w -C $(DIR) install-deps;)
clean:
$(foreach DIR,$(filter-out README.md Makefile,$(wildcard *)),$(MAKE) -w -C $(DIR) clean;)
.PHONY: all $(filter-out README.md Makefile,$(wildcard *)) $(filter-out README.md Makefile,$(wildcard */*))

25
test/iso/Makefile Normal file
View file

@ -0,0 +1,25 @@
ISO_NAME=deploy.iso
ISO_TESTS=$(wildcard install_*) $(if $(FLATPAK_REMOTE_REFS),$(wildcard flatpak_*))$(if $(FLATPAK_DIR),$(wildcard flatpak_*))
all: $(ISO_TESTS) clean
$(ISO_TESTS): mnt/iso
$(eval _VARS = ISO_NAME VERSION FLATPAK_REMOTE_NAME _FLATPAK_REPO_URL)
chmod +x $@
$(foreach var,$(_VARS),$(var)=$($(var))) ./$@
mnt/iso:
sudo modprobe loop
sudo mkdir -p mnt/iso mnt/install
sudo mount -o loop ../../$(ISO_NAME) mnt/iso
sudo mount -t squashfs -o loop mnt/iso/images/install.img mnt/install
clean:
sudo umount mnt/install || true
sudo umount mnt/iso || true
sudo rmdir mnt/install mnt/iso
install-deps:
$(install_pkg) isomd5sum coreutils squashfs-tools curl
.PHONY: all $(ISO_TESTS) clean

1
test/iso/README.md Normal file
View file

@ -0,0 +1 @@
Place scripts that will test the ISO. The ISO file will be passed as the first argument

View file

@ -0,0 +1,40 @@
#!/bin/bash
add_line=$(grep flatpak_manager.add_remote mnt/install/usr/lib64/python*/site-packages/pyanaconda/modules/payloads/payload/rpm_ostree/flatpak_installation.py)
add_line_repo=$(echo "${add_line}" | grep "${FLATPAK_REMOTE_NAME}")
add_line_url=$(echo "${add_line}" | grep "${_FLATPAK_REPO_URL}")
result=0
if [ -z "${add_line_repo}" ]
then
echo "Repo name not updated on add_remote line"
echo "${add_line}"
result=1
else
echo "Repo name found on add_remote line"
fi
if [ -z "${add_line_url}" ]
then
echo "Repo url not updated on add_remote line"
echo "${add_line}"
result=1
else
echo "Repo url found on add_remote line"
fi
replace_line=$(grep flatpak_manager.replace_installed_refs_remote mnt/install/usr/lib64/python*/site-packages/pyanaconda/modules/payloads/payload/rpm_ostree/flatpak_installation.py)
replace_line_repo=$(echo "${replace_line}" | grep "${FLATPAK_REMOTE_NAME}")
if [ -z "${replace_line_repo}" ]
then
echo "Repo name not updated on replace_installed_refs line"
echo "${replace_line}"
result=1
else
echo "Repo name found on replace_installed_refs line"
fi
exit ${result}

14
test/iso/install_hash.sh Normal file
View file

@ -0,0 +1,14 @@
#!/bin/bash
#set -ex
checkisomd5 "../../${ISO_NAME}"
if [[ $? != 0 ]]
then
echo "Found:"
checkisomd5 --md5sumonly "../../${ISO_NAME}"
echo "Expected:"
implantisomd5 --force "../../${ISO_NAME}"
fi
cd "$(dirname "../../${ISO_NAME}")" && sha256sum -c "$(basename "${ISO_NAME}")-CHECKSUM"

View file

@ -0,0 +1,14 @@
#!/bin/bash
FOUND_VERSION=$(grep VERSION_ID mnt/install/etc/os-release | cut -d= -f2)
if [[ ${FOUND_VERSION} != ${VERSION} ]]
then
echo "Version mismatch"
echo "Expected: ${VERSION}"
echo "Found: ${FOUND_VERSION}"
exit 1
else
echo "Correct version found"
exit 0
fi

11
test/repo/Makefile Normal file
View file

@ -0,0 +1,11 @@
REPO_TESTS=$(filter-out README.md Makefile,$(wildcard *))
all: $(REPO_TESTS)
$(REPO_TESTS):
chmod +x $@
./$@
install-deps:
.PHONY: $(REPO_TESTS)

118
test/repo/vars.py Executable file
View file

@ -0,0 +1,118 @@
#!/usr/bin/env python
makefile = open('../../Makefile.inputs', 'r')
makefile_lines = makefile.readlines()
inputs = {}
outputs = {}
errors = 0
for line in makefile_lines:
if line.startswith('#'):
makefile_lines.remove(line)
continue
parts = line.split('=', 1)
if parts[0].startswith('export'):
var_name = parts[0].strip().split(' ')[1].lower()
else:
var_name = parts[0].strip().lower()
inputs[var_name] = {'default_value': parts[1].strip(), 'makefile': True}
action = open('../../action.yml', 'r')
action_lines = action.readlines()
at_inputs = False
at_outputs = False
for line in action_lines:
if not at_inputs:
if line.strip() == 'inputs:':
at_inputs = True
continue
else:
if line.startswith(' '):
parts = line.strip().split(':', 1)
if parts[0] == 'description':
inputs[var_name]['description'] = parts[1].strip()
if parts[0] == 'deprecationMessage':
inputs[var_name]['deprecated'] = True
if parts[0] == 'default':
if 'default' in inputs[var_name]:
if inputs[var_name]['default_value'] != parts[1].strip().strip('"'):
print("ERROR: Default value for " + var_name + " in action.yml does not match Makefile")
errors += 1
else:
inputs[var_name]['default_value'] = parts[1].strip().strip('"')
elif line.startswith(' '):
var_name = line.strip().strip(':').lower()
if not var_name in inputs:
inputs[var_name] = {}
inputs[var_name]['action'] = True
else:
at_inputs = False
if not at_outputs:
if line.strip() == 'outputs:':
at_outputs = True
continue
else:
if line.startswith(' '):
parts = line.strip().split(':', 1)
if parts[0] == 'description':
outputs[var_name]['description'] = parts[1].strip()
if parts[0] == 'deprecationMessage':
outputs[var_name]['deprecated'] = True
if parts[0] == 'default':
outputs[var_name]['default_value'] = parts[1].strip().strip('"')
elif line.startswith(' '):
var_name = line.strip().strip(':').lower()
outputs[var_name] = {}
else:
at_outputs = False
readme = open('../../README.md', 'r')
readme_lines = readme.readlines()
at_inputs = False
skip_header = True
at_outputs = False
for line in readme_lines:
if not at_inputs:
if line.strip() == '### Inputs':
at_inputs = True
continue
else:
if skip_header:
if line.startswith('| -----'):
skip_header = False
continue
else:
if not line.startswith('|'):
at_inputs = False
continue
parts = line.split('|')
var_name = parts[1].strip().lower()
if not var_name in inputs:
print("ERROR: " + var_name + " is not listed in action.yml or Makefile")
errors += 1
continue
if 'description' in inputs[var_name]:
if parts[2].strip() != inputs[var_name]['description']:
print("WARNING: " + var_name + " description in README.md does not match action.yml")
if 'default_value' in inputs[var_name]:
if not parts[3].strip().strip('"').startswith('*'):
if inputs[var_name]['default_value'] == "":
if parts[3].strip().strip('"') != '\\[empty\\]':
print("ERROR: " + var_name + " default value in README.md does not match action.yml")
errors += 1
elif parts[3].strip().strip('"') != inputs[var_name]['default_value']:
print("ERROR: " + var_name + " default value in README.md does not match action.yml")
errors += 1
if 'action' in inputs[var_name] and inputs[var_name]['action']:
if parts[4].strip() != ':white_check_mark:':
print("WARNING: " + var_name + " not labeled as in action.yml in the README.md")
if 'makefile' in inputs[var_name] and inputs[var_name]['makefile']:
if parts[4].strip() != ':white_check_mark:':
print("WARNING: " + var_name + " not labeled as in Makefile in the README.md")
exit(errors)

100
test/vm/Makefile Normal file
View file

@ -0,0 +1,100 @@
VM_TESTS=$(wildcard install_*) $(if $(FLATPAK_REMOTE_REFS),$(wildcard flatpak_*))$(if $(FLATPAK_DIR),$(wildcard flatpak_*))
all: $(VM_TESTS) clean
$(VM_TESTS): start_vm ansible_inventory
$(eval _VARS = IMAGE_REPO IMAGE_NAME IMAGE_TAG)
ansible -i ansible_inventory -m ansible.builtin.wait_for_connection vm
chmod +x $@
$(foreach var,$(_VARS),$(var)=$($(var))) ./$@
ansible_inventory:
echo "ungrouped:" > ansible_inventory
echo " hosts:" >> ansible_inventory
echo " vm:" >> ansible_inventory
echo " ansible_host: $(VM_IP)" >> ansible_inventory
echo " ansible_port: $(VM_PORT)" >> ansible_inventory
echo " ansible_user: $(VM_USER)" >> ansible_inventory
echo " ansible_password: $(VM_PASS)" >> ansible_inventory
echo " ansible_become_pass: $(VM_PASS)" >> ansible_inventory
echo " ansible_ssh_common_args: '-o StrictHostKeyChecking=no'" >> ansible_inventory
.PHONY: $(VM_TESTS) install-deps
install-deps:
$(install_pkg) qemu qemu-utils xorriso qemu-system-x86 netcat socat jq ansible curl
files/mnt/iso:
$(if $(wildcard files/mnt),,mkdir files/mnt)
$(if $(wildcard files/mnt/iso),,mkdir files/mnt/iso)
sudo mount -o loop ../../$(ISO_NAME) files/mnt/iso
files/grub.cfg: files/mnt/iso
cp files/mnt/iso/boot/grub2/grub.cfg files/grub.cfg
sed -i 's/quiet/console=ttyS0,115200n8 inst.ks=cdrom:\/ks.cfg/' files/grub.cfg
sed -i 's/set default="1"/set default="0"/' files/grub.cfg
sed -i 's/set timeout=60/set timeout=1/' files/grub.cfg
.PHONY: clean
clean:
$(if $(wildcard start_vm), kill "$(shell cat start_vm)")
$(if $(wildcard files/mnt/iso),sudo umount files/mnt/iso)
$(if $(wildcard files/mnt/iso),rmdir files/mnt/iso)
$(if $(wildcard ansible_inventory),rm ansible_inventory)
$(if $(wildcard files/install.iso),rm files/install.iso)
$(if $(wildcard files/disk.qcow2),rm files/disk.qcow2)
$(if $(wildcard install_os),rm install_os)
$(if $(wildcard start_vm),rm start_vm)
files/install.iso: files/grub.cfg
xorriso -dialog on << EOF
-indev ../../$(ISO_NAME)
-outdev files/install.iso
-boot_image any replay
-joliet on
-compliance joliet_long_names
-map files/ks.cfg ks.cfg
-chmod 0444 ks.cfg
-map files/grub.cfg boot/grub2/grub.cfg
-end
EOF
files/disk.qcow2:
qemu-img create -f qcow2 files/disk.qcow2 50G
install_os: files/install.iso files/disk.qcow2
timeout 1h qemu-system-x86_64 -name "Anaconda" -boot d -m 4096 -cpu qemu64 -display none -cdrom files/install.iso -smp 2 -hda files/disk.qcow2 -serial telnet:localhost:4321,server=on,wait=off & QEMU_PID=$$!
echo "PID: $$QEMU_PID"
timeout 1m bash -c "while ! (echo > /dev/tcp/127.0.0.1/4321); do sleep 0.1; done"
(nc localhost 4321 | tee vm.stdout) &
wait $$QEMU_PID
touch install_os
.ONESHELL:
start_vm: install_os
mkfifo vm.stdin
qemu-system-x86_64 -name "Anaconda" \
-m 4096 -cpu qemu64 -display none -smp 2 \
-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0 \
-device e1000,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::$(VM_PORT)-:22 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-boot c -hda files/disk.qcow2 -serial telnet:localhost:4321,server=on,wait=off & export QEMU_PID=$$!
echo "PID: $$QEMU_PID"
timeout 1m bash -c "while ! (echo > /dev/tcp/127.0.0.1/4321); do sleep 0.1; done"
(tail -f vm.stdin | nc localhost 4321 | tee vm.stdout) &
timeout 30m bash -c "while ! (echo > /dev/tcp/$(VM_IP)/$(VM_PORT)); do sleep 1; done"
if ! (echo > /dev/tcp/$(VM_IP)/$(VM_PORT))
then
echo "SSH must be installed and enabled inside the container"
fi
echo "VM ready for tests at IP $(VM_IP):$(VM_PORT)"
echo $$QEMU_PID > start_vm

1
test/vm/README.md Normal file
View file

@ -0,0 +1 @@
Place scripts that will test the VM. The VM will be available at ${VM_IP} using username ${VM_USER} and password ${VM_PASS}

9
test/vm/files/ks.cfg Normal file
View file

@ -0,0 +1,9 @@
lang en_US.UTF-8
keyboard us
timezone Americas/New_York
zerombr
clearpart --all --initlabel
autopart
poweroff
user --name=core --groups=wheel --password=foobar
%include /usr/share/anaconda/interactive-defaults.ks

View file

@ -0,0 +1,16 @@
#!/usr/bin/env -S ansible-playbook -i ./ansible_inventory
---
- name: Test fedora flatpak repo wasn't enabled
hosts: vm
gather_facts: no
tasks:
- name: Collect facts about system services
service_facts:
register: services_state
- name: Check that flatpak-add-fedora-repos is disabled
ansible.builtin.assert:
that:
- services_state['ansible_facts']['services']['flatpak-add-fedora-repos.service']['status'] == 'disabled'
fail_msg: 'flatpak-add-fedora-repos.service is not disabled'

View file

@ -0,0 +1,25 @@
#!/usr/bin/env -S ansible-playbook -i ./ansible_inventory
---
- name: Test for installed flatpaks
hosts: vm
gather_facts: no
tasks:
# Verifies that the flatpaks are installed
- name: Get list of installed Flatpaks
become: true
ansible.builtin.command:
cmd: /usr/bin/flatpak list
register: flatpaks
- name: Check that VLC is installed
ansible.builtin.assert:
that:
- "'VLC' in flatpaks.stdout"
fail_msg: 'VLC is not installed'
- name: Check that Firefox is installed
ansible.builtin.assert:
that:
- "'Firefox' in flatpaks.stdout"
fail_msg: 'Firefox is not installed'

View file

@ -0,0 +1,12 @@
#!/usr/bin/env -S ansible-playbook -i ./ansible_inventory
---
- name: Test flatpak update
hosts: vm
gather_facts: no
tasks:
# Verifies that the GPG key is functional
- name: Test updating flatpak packages
become: true
ansible.builtin.command:
cmd: /usr/bin/flatpak update -y --noninteractive

View file

@ -0,0 +1,25 @@
#!/usr/bin/env -S ansible-playbook -i ./ansible_inventory
---
- name: Test Container Image source updates
hosts: vm
gather_facts: no
tasks:
# Get list of origins
- name: Get origin
become: true
ansible.builtin.command:
cmd: /bin/bash -c "cat /ostree/deploy/default/deploy/*.origin"
register: origin
- name: Get vars
ansible.builtin.set_fact:
image_repo: "{{ lookup('ansible.builtin.env', 'IMAGE_REPO') }}"
image_name: "{{ lookup('ansible.builtin.env', 'IMAGE_NAME') }}"
image_tag: "{{ lookup('ansible.builtin.env', 'IMAGE_TAG') }}"
- name: Tests
ansible.builtin.assert:
that:
- (image_repo + '/' + image_name + ':' + image_tag) in origin.stdout
fail_msg: 'Origin not configured'