193 lines
6 KiB
Bash
Executable file
193 lines
6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -x
|
|
|
|
#
|
|
# Sync latest docker image
|
|
#
|
|
# Docs in the f_help function
|
|
f_ctrl_c() {
|
|
printf "\n*** Exiting ***\n"
|
|
exit $?
|
|
}
|
|
# trap int (ctrl-c)
|
|
trap f_ctrl_c SIGINT
|
|
f_help() {
|
|
cat <<EOF
|
|
NAME
|
|
${0}
|
|
SYNOPSIS
|
|
${0} FEDORA_RELEASE IMAGE_URL [-s]
|
|
OPTIONS
|
|
-s - Sync the stage registries instead of production
|
|
DESCRIPTION
|
|
This is a stop-gap solution to identify parent inheritance of container
|
|
images until the container release automation[0] is in place and we have
|
|
fully automated rebuilds[1] in OSBS.
|
|
This information should be used such that the images can be rebuilt and
|
|
released in the appropriate order using flr-koji.
|
|
[0] - https://pagure.io/releng-automation
|
|
[1] - https://osbs.readthedocs.io/en/latest/multiarch.html#chain-rebuilds
|
|
EXAMPLE
|
|
${0} 26
|
|
EOF
|
|
}
|
|
|
|
arch_to_goarch() {
|
|
local a=$1; shift
|
|
# See https://github.com/coreos/stream-metadata-go/blob/c5fe1b98ac1b1e6ab62a606b7580dc1f30703f83/arch/arch.go#L14
|
|
case "$a" in
|
|
aarch64) echo arm64 ;;
|
|
x86_64) echo amd64 ;;
|
|
ppc64le) echo ppc64le ;;
|
|
s390x) echo s390x ;;
|
|
*) echo $a ;;
|
|
esac
|
|
}
|
|
|
|
# This is the release of Fedora that is currently stable, it will define if we
|
|
# need to move the fedora:latest tag
|
|
current_stable="43"
|
|
# Define what is rawhide so we know to push that tag
|
|
current_rawhide="45"
|
|
# Sanity checking
|
|
if ! [[ "${1}" =~ ^-?[0-9]+$ ]];
|
|
then
|
|
printf "ERROR: FEDORA_RELEASE missing or invalid\n"
|
|
f_help
|
|
exit 1
|
|
fi
|
|
# Determine if we want stage or not (yes, I know this should be getops but I
|
|
# don't want this script to survive so we're doing quick and dirty.
|
|
#
|
|
# If ${stage} is a non-zero length string, then perform staging
|
|
stage=""
|
|
if [[ "${3}" == "-s" ]]; then
|
|
printf "INFO: PERFORMING STAGE SYNC\n"
|
|
stage="true"
|
|
fi
|
|
|
|
BASENAMES=("Fedora-IoT-bootc" "Fedora-IoT-bootc-base")
|
|
format="oci-archive"
|
|
vers=${1}
|
|
compose=${2}
|
|
compdate=`echo ${compose} | cut -c 4-`
|
|
|
|
# Obtain the latest build
|
|
#
|
|
# Need fXX-updates-canddiate to get actual latest nightly
|
|
# Can't currently query koji for runroot tasks as they're not tagged
|
|
#
|
|
# base_build_nvr=$(koji -q latest-build --type=image f${1}-updates-candidate ${basename} | awk '{print $1}')
|
|
|
|
if [[ ${1} -eq "$current_stable" ]]; then
|
|
tagname="latest"
|
|
fi
|
|
if [[ ${1} -eq "$current_rawhide" ]]; then
|
|
tagname="rawhide"
|
|
fi
|
|
|
|
if [[ -z "$stage" ]]; then
|
|
registries=("registry.fedoraproject.org" "candidate-registry.fedoraproject.org" "quay.io/fedora")
|
|
else
|
|
registries=("registry.stg.fedoraproject.org" "candidate-registry.stg.fedoraproject.org")
|
|
fi
|
|
|
|
# Copy a local image to all necessary remote registries
|
|
copy_image() {
|
|
local src=$1; shift
|
|
local name=$1; shift
|
|
for registry in ${registries[@]}; do
|
|
skopeo copy $src docker://${registry}/${name}
|
|
done
|
|
}
|
|
|
|
# From already uploaded architecture-specific images, generate a manifest listed image
|
|
# on all registries
|
|
generate_manifest_list() {
|
|
local name=$1; shift
|
|
local version=$1; shift
|
|
for registry in "${registries[@]}"
|
|
do
|
|
printf "Push manifest to ${registry}\n"
|
|
if [ -n "$tagname" ]
|
|
then
|
|
printf "tag is set: ${tagname}\n"
|
|
buildah rmi "${registry}/${name}:${tagname}" || true
|
|
buildah manifest create "${registry}/${name}:${tagname}"
|
|
for arch in "${ARCHES[@]}"; do
|
|
buildah manifest add --arch=$(arch_to_goarch ${arch}) "${registry}/${name}:${tagname}" "docker://${registry}/${name}:${version}-${arch}"
|
|
done
|
|
buildah manifest push "${registry}/${name}:${tagname}" "docker://${registry}/${name}:${tagname}" --all
|
|
fi
|
|
buildah rmi "${registry}/${name}:${version}" || true
|
|
buildah manifest create "${registry}/${name}:${version}"
|
|
for arch in "${ARCHES[@]}"; do
|
|
buildah manifest add --arch=$(arch_to_goarch ${arch}) "${registry}/${name}:${version}" "docker://${registry}/${name}:${version}-${arch}"
|
|
done
|
|
buildah manifest push "${registry}/${name}:${version}" "docker://${registry}/${name}:${version}" --all
|
|
done
|
|
}
|
|
|
|
find_and_copy_images() {
|
|
local nvr=$1
|
|
local registry_name=$2
|
|
local release=$3
|
|
local name
|
|
if [[ ${registry_name} = "fedora-bootc" ]] || [[ ${registry_name} = "fedora-iot" ]]; then
|
|
name=${basename}
|
|
else
|
|
printf "Unexpected image type! If we added a new one, it needs mapping here"
|
|
exit 1
|
|
fi
|
|
# Check that all architectures completed in the build else exit
|
|
for arch in "${ARCHES[@]}"; do
|
|
if [ ! -f "/mnt/koji/compose/iot/Fedora-IoT-${release}-${compdate}/compose/${compose_type}/${arch}/images/${basename}-${release}.${compdate}.ociarchive" ]; then
|
|
echo "One of the expected images are missing, exiting."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
work_dir=$(mktemp -d)
|
|
pushd ${work_dir} &> /dev/null
|
|
# Import the image
|
|
for arch in "${ARCHES[@]}"; do
|
|
local filename
|
|
filename="/mnt/koji/compose/iot/Fedora-IoT-${release}-${compdate}/compose/${compose_type}/${arch}/images/${basename}-${release}.${compdate}.ociarchive"
|
|
copy_image ${format}:${filename} ${registry_name}:${release}-${arch}
|
|
done
|
|
|
|
popd &> /dev/null
|
|
|
|
generate_manifest_list ${registry_name} ${release}
|
|
printf "Removing temporary directory\n"
|
|
rm -rf $work_dir
|
|
}
|
|
|
|
#
|
|
# Version should not be higher than rawhide
|
|
# Either there is a mistake or script is out of date
|
|
#
|
|
if [[ ${1} -gt "$current_rawhide" ]]; then
|
|
printf "ERROR: VERSION HIGHER THAN RAWHIDE"
|
|
exit 1
|
|
fi
|
|
|
|
printf "Syncing compose contailers: ${vers} : ${compose}\n"
|
|
|
|
# For fedora-bootc and fedora-iot
|
|
for basename in "${BASENAMES[@]}"; do
|
|
if [[ ${basename} = "Fedora-IoT-bootc" ]]; then
|
|
registry_name="fedora-bootc"
|
|
compose_type="bootc"
|
|
ARCHES=("aarch64" "x86_64" "ppc64le" "s390x")
|
|
elif [[ ${basename} = "Fedora-IoT-bootc-base" ]]; then
|
|
registry_name="fedora-iot"
|
|
compose_type="bootc-base"
|
|
ARCHES=("aarch64" "x86_64")
|
|
fi
|
|
base_build_nvr=${basename}-${vers}-${compdate}
|
|
if [[ -n ${base_build_nvr} ]]; then
|
|
find_and_copy_images ${base_build_nvr} ${registry_name} ${vers} ${compose}
|
|
fi
|
|
done
|