From ea5118889760f5c509336046de0000d2ebe0adab Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 10 Apr 2024 12:56:52 -0500 Subject: [PATCH 01/10] Try pre-caching ISO files Since the builds themselves get run in a big parallel morass of nonsense, this causes cache clobbering all over. So now I move the downloading to the pre-trigger stage and hopefully we can use the pre-download step to cache things properly. Hopefully this will also prevent issues where dynamically generated download files are missing for later runs. --- .gitignore | 1 + .gitlab-ci-build.yml.in | 7 ++-- .gitlab-ci.yml | 76 +++++++++++++++++++++++++--------- sources/hyperv-iso.pkr.hcl | 1 + sources/qemu.pkr.hcl | 1 + sources/virtualbox-iso.pkr.hcl | 1 + sources/vmware-iso.pkr.hcl | 1 + 7 files changed, 65 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 104b1e3..5012c47 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ __pycache__ *.pyc *.pyo packer_cache +cache .venv venv diff --git a/.gitlab-ci-build.yml.in b/.gitlab-ci-build.yml.in index 3495756..6da64c2 100644 --- a/.gitlab-ci-build.yml.in +++ b/.gitlab-ci-build.yml.in @@ -11,8 +11,9 @@ stages: - sources/build.pkr.hcl paths: - ./packer_config/ - - paths: - - packer_cache/*.iso + - key: isofiles + paths: + - cache/*.iso rules: - if: $CI_COMMIT_TAG variables: @@ -31,7 +32,7 @@ stages: - ${tag} variables: &variables PACKER_CONFIG_DIR: ./packer_config/ - PACKER_CACHE_DIR: ./packer_cache/ + PACKER_CACHE_DIR: ./cache/ PACKER_LOG: 1 COMMAND: > packer build ${only} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ae619d..d8baee3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,13 @@ stages: - generate - lint + - cache - trigger +variables: + PACKER_CONFIG_DIR: ./packer_config/ + PACKER_CACHE_DIR: ./cache/ + generate: stage: generate artifacts: @@ -13,26 +18,6 @@ generate: "./${vars}" done -validate: - stage: lint - needs: - - generate - cache: - paths: - - /var/lib/gitlab-runner/.config/packer/plugins/ - script: |- - set -exo pipefail - packer init sources - for vars in $(find distros/ -name '*.pkrvars.hcl'); do - packer validate -except=upload -var-file=${vars} sources/ - done - -shellcheck: - stage: lint - script: |- - shellcheck --version - shellcheck $(find . -name '*.sh') - distros: stage: generate image: $CI_REGISTRY_DIRECT/greg/ci-images/fedora:latest @@ -45,6 +30,57 @@ distros: xonsh ./build.xsh -a --list echo "BUILD=$(date +'%Y.%m.%d.%H')" >> build.env +validate: + stage: lint + needs: + - generate + cache: + - key: + files: + - sources/build.pkr.hcl + paths: + - ./packer_config/ + script: |- + set -exo pipefail + packer init sources + for vars in $(find distros/ -name '*.pkrvars.hcl'); do + packer validate -except=upload -var-file=${vars} sources/ + done + +shellcheck: + stage: lint + script: |- + shellcheck --version + shellcheck $(find . -name '*.sh') + +# Downloads all the ISO files so that we have a single cache with all +# of them present. This prevents a race condition where some of the +# files were being downloaded multiple times due to parallel jobs, and +# others were disappearing (e.g. daily builds for Rawhide) before we +# could get to them +downloads: + stage: cache + image: $CI_REGISTRY_DIRECT/greg/ci-images/fedora:latest + cache: + - key: isofiles + paths: + - cache/*.iso + - key: + files: + - sources/build.pkr.hcl + paths: + - ./packer_config/ + script: + - set -exo pipefail + - packer init sources + - |- + for vars in $(find distros/ -name '*.pkrvars.hcl'); do + file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) + pushd cache + curl -O "${file}" + popd + done + trigger: stage: trigger trigger: diff --git a/sources/hyperv-iso.pkr.hcl b/sources/hyperv-iso.pkr.hcl index 1d1691d..cd06012 100644 --- a/sources/hyperv-iso.pkr.hcl +++ b/sources/hyperv-iso.pkr.hcl @@ -1,5 +1,6 @@ source "hyperv-iso" "amd64" { iso_url = var.iso.url + iso_target_path = "cache/${basename(var.iso.url)}" iso_checksum = var.iso.checksum output_directory = "output/hyperv/${local.name}" diff --git a/sources/qemu.pkr.hcl b/sources/qemu.pkr.hcl index ec70ccc..9a69ff3 100644 --- a/sources/qemu.pkr.hcl +++ b/sources/qemu.pkr.hcl @@ -5,6 +5,7 @@ variable "qemu_accelerator" { source "qemu" "amd64" { iso_url = var.iso.url + iso_target_path = "cache/${basename(var.iso.url)}" iso_checksum = var.iso.checksum output_directory = "output/libvirt/${local.name}" diff --git a/sources/virtualbox-iso.pkr.hcl b/sources/virtualbox-iso.pkr.hcl index efee8c1..5848ff8 100644 --- a/sources/virtualbox-iso.pkr.hcl +++ b/sources/virtualbox-iso.pkr.hcl @@ -1,5 +1,6 @@ source "virtualbox-iso" "amd64" { iso_url = var.iso.url + iso_target_path = "cache/${basename(var.iso.url)}" iso_checksum = var.iso.checksum output_directory = "output/virtualbox/${local.name}" diff --git a/sources/vmware-iso.pkr.hcl b/sources/vmware-iso.pkr.hcl index 065eae2..687b7ac 100644 --- a/sources/vmware-iso.pkr.hcl +++ b/sources/vmware-iso.pkr.hcl @@ -1,5 +1,6 @@ source "vmware-iso" "amd64" { iso_url = var.iso.url + iso_target_path = "cache/${basename(var.iso.url)}" iso_checksum = var.iso.checksum output_directory = "output/vmware/${local.name}" From b52e08d4bf27397d77de775fbf5da3f41841e950 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 10 Apr 2024 12:59:16 -0500 Subject: [PATCH 02/10] Fix indent in YAML --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d8baee3..28de315 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -68,8 +68,8 @@ downloads: - key: files: - sources/build.pkr.hcl - paths: - - ./packer_config/ + paths: + - ./packer_config/ script: - set -exo pipefail - packer init sources From 46e2edc9d8b50ee8be0e550634d74230ceb5bb22 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 10 Apr 2024 13:06:37 -0500 Subject: [PATCH 03/10] Try doing parallel downloads with curl --- .gitlab-ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 28de315..1260afa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -73,13 +73,15 @@ downloads: script: - set -exo pipefail - packer init sources + - files="" - |- for vars in $(find distros/ -name '*.pkrvars.hcl'); do file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) - pushd cache - curl -O "${file}" - popd + files="${file} ${files}" done + pushd cache + curl --parallel -L -O "${files}" + popd trigger: stage: trigger From 034316198553d2c4dd4872b56a5c8cb58e520cfa Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 10 Apr 2024 13:13:26 -0500 Subject: [PATCH 04/10] Use bash array --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1260afa..ccfbf38 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -73,14 +73,14 @@ downloads: script: - set -exo pipefail - packer init sources - - files="" + - files=() - |- for vars in $(find distros/ -name '*.pkrvars.hcl'); do file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) - files="${file} ${files}" + files+=("${file}") done pushd cache - curl --parallel -L -O "${files}" + curl --parallel -L -O "${files[@]}" popd trigger: From 702373e989f8cb724ad8a1208a769e87e0f118ac Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 10 Apr 2024 13:42:59 -0500 Subject: [PATCH 05/10] Create directory first --- .gitlab-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ccfbf38..7f16030 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -79,9 +79,10 @@ downloads: file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) files+=("${file}") done - pushd cache - curl --parallel -L -O "${files[@]}" - popd + - mkdir -p cache + - pushd cache + - curl --parallel -L -O "${files[@]}" + - popd trigger: stage: trigger From 375f5ea92c23cc63cb82cd883eb0e44749f7990d Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 10 Apr 2024 13:49:55 -0500 Subject: [PATCH 06/10] Tell curl to be sane --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f16030..9b19e44 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,11 +77,11 @@ downloads: - |- for vars in $(find distros/ -name '*.pkrvars.hcl'); do file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) - files+=("${file}") + files+=("-O" "${file}") done - mkdir -p cache - pushd cache - - curl --parallel -L -O "${files[@]}" + - curl --parallel -L "${files[@]}" - popd trigger: From e359957376d14f9e24f32de8307c7a2018b7a0a6 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Thu, 11 Apr 2024 13:32:56 -0500 Subject: [PATCH 07/10] OpenSuSE LEAP 15.6 is not GA yet --- build.xsh | 1 + distros/opensuse/supports.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.xsh b/build.xsh index 81919ee..d129fe7 100755 --- a/build.xsh +++ b/build.xsh @@ -84,6 +84,7 @@ if args.all or args.list or (args.distro and args.version and args.build): with open(".gitlab-ci-build.yml.in", "r") as fp: y = load(fp, Loader=Loader) for item in my_list: + print(item) if item.is_github: y[ item.only[6:] ]["parallel"]["matrix"].append({"distro": item.var_path}) with open(".gitlab-ci-build.yml", "w") as fp: diff --git a/distros/opensuse/supports.yml b/distros/opensuse/supports.yml index a709f30..06d713d 100644 --- a/distros/opensuse/supports.yml +++ b/distros/opensuse/supports.yml @@ -1,4 +1,4 @@ -15.6: &supp +15.5: &supp - arch: amd64 provider: qemu - arch: amd64 @@ -7,5 +7,5 @@ provider: vmware-iso - arch: amd64 provider: hyperv-iso -15.5: *supp +15.6: tumbleweed: *supp From da06cd988be36bcd32f035d5990513b24a228e15 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Fri, 12 Apr 2024 10:22:23 -0500 Subject: [PATCH 08/10] Improve cache usage 1. Only download cached files that are not present in the current cache 2. Try pulling directly from the cache, not only with the target information --- .gitlab-ci.yml | 4 +++- sources/qemu.pkr.hcl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b19e44..bbac26d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,7 +77,9 @@ downloads: - |- for vars in $(find distros/ -name '*.pkrvars.hcl'); do file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) - files+=("-O" "${file}") + if [ ! -e "cache/${file}" ]; then + files+=("-O" "${file}") + fi done - mkdir -p cache - pushd cache diff --git a/sources/qemu.pkr.hcl b/sources/qemu.pkr.hcl index 9a69ff3..bb3ecba 100644 --- a/sources/qemu.pkr.hcl +++ b/sources/qemu.pkr.hcl @@ -4,7 +4,7 @@ variable "qemu_accelerator" { } source "qemu" "amd64" { - iso_url = var.iso.url + iso_urls = [ "cache/${basename(var.iso.url)}", var.iso.url] iso_target_path = "cache/${basename(var.iso.url)}" iso_checksum = var.iso.checksum output_directory = "output/libvirt/${local.name}" From 57b2ae29eefc16cb7c530a4cd293fb14e4db5b4a Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Fri, 12 Apr 2024 10:34:31 -0500 Subject: [PATCH 09/10] Fix check for file existence --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bbac26d..3a4a47a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,7 +77,7 @@ downloads: - |- for vars in $(find distros/ -name '*.pkrvars.hcl'); do file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) - if [ ! -e "cache/${file}" ]; then + if [ ! -e "cache/$(basename '${file}')" ]; then files+=("-O" "${file}") fi done From f4a43a46cf4da4bddcf58fd95fe8506c976bfd73 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Fri, 12 Apr 2024 12:01:16 -0500 Subject: [PATCH 10/10] Try, again, to do this right... --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3a4a47a..acab16b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,7 +77,8 @@ downloads: - |- for vars in $(find distros/ -name '*.pkrvars.hcl'); do file=$(echo var.iso.url | packer console -var-file=${vars} -config-type=hcl2 sources/) - if [ ! -e "cache/$(basename '${file}')" ]; then + base="$(basename "${file}")" + if [ ! -e "cache/${base}" ]; then files+=("-O" "${file}") fi done