pkg-auto: Simplify SDK image override handling

There used to be a possibility to override used SDK image per
architecture, but the need for it disappeared once SDK images started
to contain the initial form of board rootfs for both amd64 and
arm64. This eliminated problems with cyclic dependencies errors
popping up while gather the package reports. So with this change it is
now only possible to specify just one SDK image to use for any
arch. This feature is not used all that often anyway.
This commit is contained in:
Krzesimir Nowak 2025-04-10 18:07:52 +02:00
parent 7b5841c039
commit 00572476c4
2 changed files with 23 additions and 84 deletions

View File

@ -9,9 +9,8 @@ set -euo pipefail
## -a: aux directory
## -d: debug package - list many times
## -h: this help
## -i: SDK image override in form of ${arch}:${name}, the name part
## should be a valid docker image with an optional tag
## -ip: add SDK image overrides using flatcar-packages images
## -i: override SDK image, it should be a valid docker image with an
## optional tag
## -n: new base
## -o: old base
## -r: reports directory
@ -39,12 +38,14 @@ gc_reports_directory=''
gc_scripts_directory=''
# shellcheck disable=SC2034 # used by name below
gc_cleanup_opts=''
# gc_${arch}_sdk_img are declared on demand
# shellcheck disable=SC2034 # used by name below
gc_image_override=''
gc_debug_packages=()
declare -A opt_map
opt_map=(
['-a']=gc_aux_directory
['-i']=gc_image_override
['-n']=gc_new_base
['-o']=gc_old_base
['-r']=gc_reports_directory
@ -68,36 +69,6 @@ while [[ ${#} -gt 0 ]]; do
print_help
exit 0
;;
-i)
if [[ -z ${2:-} ]]; then
fail 'missing value for -i'
fi
arch=${2%%:*}
image_name=${2#*:}
var_name="gc_${arch}_sdk_img"
unset arch
# shellcheck disable=SC2178 # shellcheck does not grok refs
declare -n ref="${var_name}"
unset var_name
# shellcheck disable=SC2178 # shellcheck does not grok refs
ref=${image_name}
unset image_name
unset -n ref
shift 2
;;
-ip)
for arch in "${gc_arches[@]}"; do
var_name="gc_${arch}_sdk_img"
# shellcheck disable=SC2178 # shellcheck does not grok refs
declare -n ref="${var_name}"
unset var_name
# shellcheck disable=SC2178 # shellcheck does not grok refs
ref="flatcar-packages-${arch}"
unset -n ref
done
unset arch
shift
;;
--)
shift
break
@ -134,15 +105,10 @@ pairs=(
'old-base' gc_old_base
'new-base' gc_new_base
'cleanups' gc_cleanup_opts
'sdk-image-override' gc_image_override
'debug-packages' gc_debug_packages_csv
)
for arch in "${gc_arches[@]}"; do
pairs+=( "${arch}-sdk-img" "gc_${arch}_sdk_img" )
done
pairs+=( 'debug-packages' gc_debug_packages_csv )
if [[ ${#} -ne 1 ]]; then
fail 'expected one positional parameters: a path for the config'
fi

View File

@ -72,15 +72,14 @@ function setup_workdir_with_config() {
workdir=${1}; shift
config_file=${1}; shift
local cfg_scripts cfg_aux cfg_reports cfg_old_base cfg_new_base
local cfg_scripts cfg_aux cfg_reports cfg_old_base cfg_new_base cfg_sdk_image_override
local -a cfg_cleanups cfg_debug_packages
local -A cfg_overrides
# some defaults
cfg_old_base='origin/main'
cfg_new_base=''
cfg_cleanups=('ignore')
cfg_overrides=()
cfg_sdk_image_override=''
cfg_debug_packages=()
local line key value swwc_stripped var_name arch
@ -99,7 +98,7 @@ function setup_workdir_with_config() {
var=$(realpath "${value}")
unset -n var
;;
old-base|new-base)
old-base|new-base|sdk-image-override)
var_name="cfg_${key//-/_}"
local -n var=${var_name}
var=${value}
@ -109,11 +108,6 @@ function setup_workdir_with_config() {
var_name="cfg_${key//-/_}"
mapfile -t "${var_name}" <<<"${value//,/$'\n'}"
;;
*-sdk-img)
arch=${key%%-*}
# shellcheck disable=SC2034 # used by name below
cfg_overrides["${arch}"]=${value}
;;
esac
done < <(cat_meaningful "${config_file}")
if [[ -z "${cfg_new_base}" ]]; then
@ -131,7 +125,9 @@ function setup_workdir_with_config() {
add_cleanup "rm -f ${WORKDIR@Q}/config"
cp -a "${config_file}" "${WORKDIR}/config"
setup_worktrees_in_workdir "${cfg_scripts}" "${cfg_old_base}" "${cfg_new_base}" "${cfg_reports}" "${cfg_aux}"
override_sdk_image_names cfg_overrides
if [[ -n ${cfg_sdk_image_override} ]]; then
override_sdk_image_name "${cfg_sdk_image_override}"
fi
add_debug_packages "${cfg_debug_packages[@]}"
}
@ -244,32 +240,15 @@ function setup_worktrees_in_workdir() {
extend_globals_file "${scripts}" "${old_state}" "${new_state}" "${reports_dir}" "${aux_dir}"
}
# Adds overridden SDK image names to the globals file.
# Adds an overridden SDK image name to the globals file.
#
# Params:
#
# 1 - name of a map variable; should be a mapping of architecture to
# the image name
function override_sdk_image_names() {
local -n overrides_map_ref=${1}
# 1 - image name
function override_sdk_image_name() {
local image_name=${1}; shift
if [[ ${#overrides_map_ref[@]} -eq 0 ]]; then
return 0
fi
local arch image_name upcase_arch
local -a lines
lines=()
for arch in "${!overrides_map_ref[@]}"; do
image_name=${overrides_map_ref["${arch}"]}
upcase_arch=${arch^^}
if [[ ${#lines[@]} -eq 0 ]]; then
# separate overrides from initial values
lines+=( '' )
fi
lines+=( "${upcase_arch}_SDK_IMAGE=${image_name@Q}" )
done
append_to_globals "${lines[@]}"
append_to_globals "SDK_IMAGE=${image_name@Q}"
}
# Adds information about packages to be debugged to the globals file.
@ -572,17 +551,11 @@ EOF
# shellcheck disable=SC1091 # sourcing generated file
last_nightly_build_id=$(source "${NEW_STATE}/sdk_container/.repo/manifests/version.txt"; printf '%s' "${FLATCAR_BUILD_ID}")
local -a locals definitions
locals=()
definitions=()
local sdk_image_name
local -a locals=() definitions=()
local sdk_image_name sdk_image_var_name=SDK_IMAGE
sdk_image_name="ghcr.io/flatcar/flatcar-sdk-all:${last_nightly_version_id}-${last_nightly_build_id}"
local arch sdk_image_var_name
for arch in "${ARCHES[@]}"; do
sdk_image_var_name="${arch^^}_SDK_IMAGE"
locals+=( "${sdk_image_var_name@Q}" )
definitions+=( "${sdk_image_var_name}=${sdk_image_name@Q}" )
done
locals+=( "${sdk_image_var_name@Q}" )
definitions+=( "${sdk_image_var_name}=${sdk_image_name@Q}" )
append_to_globals \
'' \
@ -1146,7 +1119,7 @@ function generate_sdk_reports() {
local file full_file rv sdk_reports_dir salvaged_dir pkg_auto_copy
local -a report_files run_sdk_container_args
for arch in "${ARCHES[@]}"; do
sdk_image_var_name="${arch^^}_SDK_IMAGE"
sdk_image_var_name="SDK_IMAGE"
sdk_image_name=${!sdk_image_var_name}
if ! docker images --format '{{.Repository}}:{{.Tag}}' | grep --quiet --line-regexp --fixed-strings "${sdk_image_name}"; then
fail "No SDK image named ${sdk_image_name@Q} available locally, pull it before running this script"