From 84266982bc8d0d411d4984898571ba2e239b6331 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 26 Oct 2023 17:04:37 +0200 Subject: [PATCH] overlay, ci-automation: Factor out OEMID info to a separate file Image changes job needs a list of OEMIDs that are built for a specific architecture. Similar information already existed in the coreos-base/common-oem-files ebuild, so factor it out to a separate file, so the image changes job does not need to source the entire ebuild (or process it in other way), but rather source the smaller file. --- ci-automation/image_changes.sh | 61 ++++--------------- .../common-oem-files-0-r4.ebuild | 17 +----- .../common-oem-files/files/oemids.sh | 30 +++++++++ 3 files changed, 44 insertions(+), 64 deletions(-) create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/files/oemids.sh diff --git a/ci-automation/image_changes.sh b/ci-automation/image_changes.sh index 3c873dd6912..238309fd0b5 100644 --- a/ci-automation/image_changes.sh +++ b/ci-automation/image_changes.sh @@ -206,59 +206,22 @@ function git_tag_for_nightly() { # 2 - arch # 3 - name of an array variable to store the result in function get_oem_id_list() { - local scripts_repo arch + local scripts_repo arch list_var_name scripts_repo=${1}; shift arch=${1}; shift - local -n list_var_ref=${1}; shift + list_var_name=${1}; shift - local -a ebuilds - ebuilds=( "${scripts_repo}/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/common-oem-files-"*'.ebuild' ) + # This defines COMMON_OEMIDS, AMD64_ONLY_OEMIDS, ARM64_ONLY_OEMIDS + # and OEMIDS variable. We don't use the last one. + source "${scripts_repo}/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/files/oemids.sh" local - list_var_ref=() - if [[ ${#ebuilds[@]} -eq 0 ]]; then - return 0 - fi - local mode - # 0 = no OEMIDS line found yet - # 1 = OEMIDS line found - mode=0 - local -a fields - local first arch_field arch_found - while read -r -a fields; do - if [[ ${#fields[@]} -eq 0 ]]; then - continue - fi - first=${fields[0]} - case ${mode} in - 0) - if [[ ${first} = 'OEMIDS=(' ]]; then - mode=1 - fi - ;; - 1) - if [[ ${first} = ')' ]]; then - break - fi - if [[ ${#fields[@]} -gt 1 ]]; then - if [[ ${fields[1]} != '#' ]]; then - echo "expect a line inside OEMIDS to be like ' # …' or just '', got '${fields[*]}'" >&2 - exit 1 - fi - arch_found= - for arch_field in "${fields[@]:2}"; do - if [[ ${arch} = "${arch_field}" ]]; then - arch_found=x - break - fi - done - if [[ -z ${arch_found} ]]; then - continue - fi - fi - list_var_ref+=( "${first}" ) - ;; - esac - done <"${ebuilds[0]}" + local -n arch_oemids_ref="${arch^^}_ONLY_OEMIDS" + local all_oemids=( + "${COMMON_OEMIDS[@]}" + "${arch_oemids_ref[@]}" + ) + + mapfile -t "${list_var_name}" < <(printf '%s\n' "${all_oemids[@]}" | sort) } function get_base_sysext_list() { diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/common-oem-files-0-r4.ebuild b/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/common-oem-files-0-r4.ebuild index 16b385bac91..33c4b20a735 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/common-oem-files-0-r4.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/common-oem-files-0-r4.ebuild @@ -3,21 +3,8 @@ EAPI=8 -# One OEM ID per line, a comment at the end of the line to denote -# which arch this OEM is for (not necessary if OEM is built for all of -# them). The arches should be space separated. -# -# This is used by the ci-automation/image_changes.sh script to figure -# out the per-arch OEM IDs. -OEMIDS=( - ami - azure - digitalocean # amd64 - openstack - packet - qemu - vmware # amd64 -) +# This defines the OEMIDS variable. +source "${FILESDIR}/oemids.sh" only-oemids DESCRIPTION='Common OEM files' HOMEPAGE='https://www.flatcar.org/' diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/files/oemids.sh b/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/files/oemids.sh new file mode 100644 index 00000000000..ca6b294aa93 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/common-oem-files/files/oemids.sh @@ -0,0 +1,30 @@ +if [[ ${1:-} = 'local' ]]; then + local -a COMMON_OEMIDS ARM64_ONLY_OEMIDS AMD64_ONLY_OEMIDS OEMIDS + shift +fi + +COMMON_OEMIDS=( + ami + azure + openstack + packet + qemu +) + +ARM64_ONLY_OEMIDS=( +) + +AMD64_ONLY_OEMIDS=( + digitalocean + vmware +) + +OEMIDS=( + "${COMMON_OEMIDS[@]}" + "${ARM64_ONLY_OEMIDS[@]}" + "${AMD64_ONLY_OEMIDS[@]}" +) + +if [[ ${1:-} = 'only-oemids' ]]; then + unset COMMON_OEMIDS ARM64_ONLY_OEMIDS AMD64_ONLY_OEMIDS +fi