Skip to content

Commit a47e9ae

Browse files
author
openshift-pipelines-bot
committed
Add workflow to mirror operand images
1 parent ccfee5a commit a47e9ae

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: mirror-operand-images
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- project.yaml
7+
workflow_dispatch:
8+
9+
jobs:
10+
mirror-operand-images:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
steps:
16+
- name: Checkout the current repo
17+
uses: actions/checkout@v4
18+
19+
- name: Configure Docker authentication
20+
env:
21+
DOCKER_CONFIG: /home/runner/.docker
22+
DOCKER_JSON: ${{ secrets.QUAY_REGISTRY_SECRET }}
23+
run: |
24+
echo ${DOCKER_JSON} > $DOCKER_CONFIG/config.json
25+
26+
- name: mirror-images
27+
run: |
28+
# Update operator's payload and stuff
29+
./hack/mirror-operand-images.sh
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

hack/mirror-operand-images.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)