From 01e04b8083885df49f04ac3fcdcedcaf0dcea881 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Wed, 12 Apr 2023 17:56:17 -0700 Subject: [PATCH] start pull_iso_images function --- .../empanadas/scripts/pull_iso_image.py | 3 +- .../templates/buildExtraImage.tmpl.sh | 56 +++++++++++++------ .../templates/buildLiveImage.tmpl.sh | 19 ++++--- iso/empanadas/empanadas/util/iso_utils.py | 13 +++++ 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/iso/empanadas/empanadas/scripts/pull_iso_image.py b/iso/empanadas/empanadas/scripts/pull_iso_image.py index cc84a8e..0e6e114 100755 --- a/iso/empanadas/empanadas/scripts/pull_iso_image.py +++ b/iso/empanadas/empanadas/scripts/pull_iso_image.py @@ -36,5 +36,4 @@ a = IsoBuild( ) def run(): - #a.run_pull_iso_images() - print('currently not supported') + a.run_pull_iso_images() diff --git a/iso/empanadas/empanadas/templates/buildExtraImage.tmpl.sh b/iso/empanadas/empanadas/templates/buildExtraImage.tmpl.sh index 1c6997e..f9e6eb0 100644 --- a/iso/empanadas/empanadas/templates/buildExtraImage.tmpl.sh +++ b/iso/empanadas/empanadas/templates/buildExtraImage.tmpl.sh @@ -1,20 +1,44 @@ #!/bin/bash set -ex +# funtions +function podman_setup_dirs() { + {{ lorax_pkg_cmd }} + mkdir -p {{ compose_work_iso_dir }}/{{ arch }} + cd {{ compose_work_iso_dir }}/{{ arch }} + test -f {{ isoname }} && { echo "ERROR: ISO ALREDY EXISTS!"; exit 1; } +} + +function podman_create_links() { + # symlink to unversioned image name + ln -sf {{ isoname }} {{ generic_isoname }} + ln -sf {{ isoname }} {{ latest_isoname }} + ln -sf {{ isoname }}.manifest {{ generic_isoname }}.manifest + ln -sf {{ isoname }}.manifest {{ latest_isoname }}.manifest +} + +function local_setup_env() { + cd /builddir + if ! TEMPLATE="$($(head -n1 $(which lorax) | cut -c3-) -c 'import pylorax; print(pylorax.find_templates())')"; then + TEMPLATE="/usr/share/lorax" + fi +} + +function check_for_sorry() { + if xorriso -indev {{ isoname }} -report_el_torito as_mkisofs 2>&1 | grep -q SORRY; then + echo "IMAGE WAS NOT BUILT CORRECTLY" + exit 23 + else + return 0 + fi +} + {% if extra_iso_mode == "podman" %} -{{ lorax_pkg_cmd }} -mkdir -p {{ compose_work_iso_dir }}/{{ arch }} -cd {{ compose_work_iso_dir }}/{{ arch }} -test -f {{ isoname }} && { echo "ERROR: ISO ALREDY EXISTS!"; exit 1; } +podman_setup_dirs {% else %} -cd /builddir - -if ! TEMPLATE="$($(head -n1 $(which lorax) | cut -c3-) -c 'import pylorax; print(pylorax.find_templates())')"; then - TEMPLATE="/usr/share/lorax" -fi +local_setup_env {% endif %} - {{ make_image }} {{ isohybrid }} @@ -23,11 +47,11 @@ fi {{ make_manifest }} -{% if extra_iso_mode == "podman" %} -# symlink to unversioned image name -ln -sf {{ isoname }} {{ generic_isoname }} -ln -sf {{ isoname }} {{ latest_isoname }} -ln -sf {{ isoname }}.manifest {{ generic_isoname }}.manifest -ln -sf {{ isoname }}.manifest {{ latest_isoname }}.manifest +## Check that the ISO came out fine +set +e +check_for_sorry +set -e +{% if extra_iso_mode == "podman" %} +podman_create_links {% endif %} diff --git a/iso/empanadas/empanadas/templates/buildLiveImage.tmpl.sh b/iso/empanadas/empanadas/templates/buildLiveImage.tmpl.sh index 938e487..e5e1cb8 100644 --- a/iso/empanadas/empanadas/templates/buildLiveImage.tmpl.sh +++ b/iso/empanadas/empanadas/templates/buildLiveImage.tmpl.sh @@ -1,6 +1,17 @@ #!/bin/bash set -ex +# functions +function check_for_container() { + [[ -f /run/.containerenv ]]; container_ec=$? + grep -q "0::/$" /proc/1/cgroup; pid_ec=$? + grep -q "0::/$" /proc/self/cgroup; self_ec=$? + + if [[ "$pid_ec" == "0" ]] || [[ "$self_ec" == 0 ]]; then + exit 23 + fi +} + {% if live_iso_mode == "podman" %} {{ live_pkg_cmd }} mkdir -p {{ compose_live_work_dir }}/{{ arch }} @@ -26,13 +37,7 @@ done # Even so, we don't support it. These checks are to prevent (you) from # getting needless headaches. set +e -[[ -f /run/.containerenv ]]; container_ec=$? -grep -q "0::/$" /proc/1/cgroup; pid_ec=$? -grep -q "0::/$" /proc/self/cgroup; self_ec=$? - -if [[ "$pid_ec" == "0" ]] || [[ "$self_ec" == 0 ]]; then - exit 23 -fi +check_for_container set -e cd /builddir diff --git a/iso/empanadas/empanadas/util/iso_utils.py b/iso/empanadas/empanadas/util/iso_utils.py index 43af9ed..54d289a 100644 --- a/iso/empanadas/empanadas/util/iso_utils.py +++ b/iso/empanadas/empanadas/util/iso_utils.py @@ -1307,6 +1307,19 @@ class IsoBuild: fh.write("%s=%s\n" % (zl, u[zl])) fh.close() + def run_pull_iso_images(self): + """ + Pulls ISO's made in v2 + """ + arches_to_unpack = self.arches + latest_artifacts = {} + if self.arch: + unpack_single_arch = True + arches_to_unpack = [self.arch] + + print("not supported") + sys.exit(1) + def run_pull_generic_images(self): """ Pulls generic images built in peridot and places them where they need