|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Update images from project.yaml to "generated" files |
| 3 | +TAG=${1:-"devel"} |
| 4 | +TARGET_REGISTRY="quay.io/openshift-pipeline" |
| 5 | +LENGTH=$(yq e '.images | length' project.yaml) |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +function ensure_mirror() { |
| 10 | + input=$1 |
| 11 | + |
| 12 | + SOURCE_PATTEN="quay.io/.*/(pipeline-)?(.*@sha256:.+)" |
| 13 | + TARGET_PATTEN="${TARGET_REGISTRY}/pipelines-\2" |
| 14 | + output=$(echo "$input" | sed -E "s|$SOURCE_PATTEN|$TARGET_PATTEN|g") |
| 15 | + |
| 16 | + #Update Operator Image operator-operator to operator |
| 17 | + output=$(echo "$output" | sed -E "s/operator-operator-rhel9/rhel9-operator/g") |
| 18 | + |
| 19 | + if [ $output == $input ]; then |
| 20 | + echo -e "\e[33m Image ${input} is already in the target registry, skipping \e[0m" >&2 |
| 21 | + return 0 |
| 22 | + fi |
| 23 | + |
| 24 | + # Check if the image exists in the target registry |
| 25 | + skopeo inspect --raw docker://${output} > /dev/null 2>&1 |
| 26 | + if [ $? -ne 0 ]; then |
| 27 | + echo -e "\e[33m Image ${output} does not exist, Trying to mirror \e[0m" >&2 |
| 28 | + sha=${output/*@sha256:/} |
| 29 | + new_image=${output/@sha256:*/} |
| 30 | + tags=("$TAG" "$sha") |
| 31 | + for tag in "${tags[@]}"; do |
| 32 | + echo "copying the image from $input to $new_image with tag $tag and preserving digests" |
| 33 | + skopeo copy docker://"$input" docker://"$new_image:$tag" --all --preserve-digests |
| 34 | + done |
| 35 | + |
| 36 | + skopeo copy --all docker://${input} docker://${output} > /dev/null 2>&1 |
| 37 | + if [ $? -ne 0 ]; then |
| 38 | + echo -e "\e[31m Failed to mirror image ${input} to ${output} \e[0m" >&2 |
| 39 | + return 1 |
| 40 | + else |
| 41 | + echo "Successfully mirrored image ${input} to ${output}" |
| 42 | + fi |
| 43 | + fi |
| 44 | + |
| 45 | +} |
| 46 | +for i in $(seq 0 $((${LENGTH}-1))); do |
| 47 | + ensure_mirror "$(yq e ".images.${i}.value" project.yaml)" |
| 48 | +done |
| 49 | + |
0 commit comments