Skip to content

Commit 941358c

Browse files
committed
feat(RELEASE-1989): python for publish-index-images tasks
tasks/internal/publish-index-image and tasks/managed/publish-index-image internal bash scripts are replaced with python scripts from release-service-utils Signed-off-by: Jindrich Luza <jluza@redhat.com>
1 parent bcaa9a5 commit 941358c

2 files changed

Lines changed: 17 additions & 115 deletions

File tree

tasks/internal/publish-index-image-task/publish-index-image-task.yaml

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ spec:
6464
securityContext:
6565
runAsUser: 1001
6666
image: >-
67-
quay.io/konflux-ci/release-service-utils@sha256:5546fa78d3c88d7b6a2e8cff8902f7757f00541d0bbaf113b9f293133894afa3
67+
quay.io/jluza/release-service-utils:RELEASE-1989
6868
computeResources:
6969
limits:
7070
memory: 64Mi
@@ -74,52 +74,9 @@ spec:
7474
script: |
7575
#!/usr/bin/env bash
7676
set -euo pipefail
77-
78-
SOURCE_INDEX_CREDENTIAL="$(cat /mnt/publishingCredentials/sourceIndexCredential)"
79-
TARGET_INDEX_CREDENTIAL="$(cat /mnt/publishingCredentials/targetIndexCredential)"
80-
81-
PATH=/bin:/usr/bin:/usr/local/bin
82-
export PATH
83-
84-
SOURCE_AUTH_ARGS=()
85-
if [[ ! "$(params.sourceIndex)" =~ ^registry-proxy(\-stage)?.engineering.redhat.com ]]; then
86-
SOURCE_AUTH_ARGS=("--src-creds" "${SOURCE_INDEX_CREDENTIAL}")
87-
fi
88-
89-
TARGET_AUTH_ARGS=("--dest-creds" "${TARGET_INDEX_CREDENTIAL}")
90-
91-
# Extract digest from pull spec
92-
SOURCE_INDEX="$(params.sourceIndex)"
93-
SOURCE_DIGEST="${SOURCE_INDEX##*@}"
94-
95-
echo "Getting target image digest: $(params.targetIndex)"
96-
if TARGET_DIGEST=$(skopeo inspect \
97-
"docker://$(params.targetIndex)" \
98-
--format '{{.Digest}}' \
99-
--retry-times "$(params.retries)"); then
100-
echo "Target image exists."
101-
echo "DEBUG: Source Digest - $SOURCE_DIGEST"
102-
echo "DEBUG: Target Digest - $TARGET_DIGEST"
103-
if [ "$SOURCE_DIGEST" == "$TARGET_DIGEST" ]; then
104-
echo "Image already exists with the same digest, skipping copy." | tee "$(results.requestMessage.path)"
105-
exit 0
106-
else
107-
echo "Image exists in target registry but digests do not match." \
108-
"Proceeding to copy the image."
109-
fi
110-
else
111-
echo "Target image does not exist. Proceeding to copy the image."
112-
fi
113-
114-
# Proceed with copying the image
115-
echo "Copying image from $(params.sourceIndex) to $(params.targetIndex)"
116-
(skopeo copy \
117-
--all \
118-
--preserve-digests \
119-
--retry-times "$(params.retries)" \
120-
--src-tls-verify=false "${SOURCE_AUTH_ARGS[@]}" \
121-
"docker://$(params.sourceIndex)" \
122-
"${TARGET_AUTH_ARGS[@]}" \
123-
"docker://$(params.targetIndex)" && \
124-
echo -n "Index Image Published successfully" || \
125-
echo -n "Error: Failed publishing Index Image" ) | tee "$(results.requestMessage.path)"
77+
python3 -m publish_index_image \
78+
--source-index "$(params.sourceIndex)" \
79+
--target-index "$(params.targetIndex)" \
80+
--retries "$(params.retries)" \
81+
--source-credential-path /mnt/publishingCredentials/sourceIndexCredential \
82+
--target-credential-path /mnt/publishingCredentials/targetIndexCredential

tasks/managed/publish-index-image/publish-index-image.yaml

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ spec:
125125
value: $(params.sourceDataArtifact)
126126
- name: publish-index-image
127127
image: >-
128-
quay.io/konflux-ci/release-service-utils@sha256:5546fa78d3c88d7b6a2e8cff8902f7757f00541d0bbaf113b9f293133894afa3
128+
quay.io/jluza/release-service-utils:RELEASE-1989
129129
computeResources:
130130
limits:
131131
memory: 512Mi
@@ -142,71 +142,16 @@ spec:
142142
exit 1
143143
fi
144144
145-
request="publish-index-image-pipeline"
146-
credentials=$(jq -r '.fbc.publishingCredentials' "$DATA_FILE")
147-
pipelinerun_label="internal-services.appstudio.openshift.io/pipelinerun-uid"
145+
credentials="$(jq -r '.fbc.publishingCredentials' "$DATA_FILE")"
148146
149-
LENGTH="$(jq -r '.components | length' "$(params.dataDir)/$(params.internalRequestResultsFile)")"
150-
for((i=0; i<LENGTH; i++)); do
151-
targetIndex=$(jq -r --argjson i "$i" \
152-
'.components[$i].target_index' "$(params.dataDir)/$(params.internalRequestResultsFile)")
153-
154-
sourceIndex=$(jq -r --argjson i "$i" \
155-
'.components[$i].index_image' "$(params.dataDir)/$(params.internalRequestResultsFile)")
156-
157-
buildTimestamp=$(jq -r --argjson i "$i" '.components[$i].completion_time' \
158-
"$(params.dataDir)/$(params.internalRequestResultsFile)")
159-
160-
publishingImages=("$targetIndex")
161-
# only publish the extra timestamp-based tag if the targetIndex does not have it already
162-
if [[ ! "$targetIndex" =~ .*"$buildTimestamp"$ ]]; then
163-
publishingImages+=("${targetIndex}-${buildTimestamp}")
164-
fi
165-
166-
requestTimeout=$(params.requestTimeout)
167-
pipelineTimeoutSeconds=$((requestTimeout+300))
168-
pipelineTimeout=$(date -u -d @"${pipelineTimeoutSeconds}" +"%Hh%Mm%Ss")
169-
taskTimeout=$(date -u -d @"${requestTimeout}" +"%Hh%Mm%Ss")
170-
171-
IR_RESULT_FILE=$(mktemp)
172-
173-
for((x=0; x<${#publishingImages[@]}; x++ )); do
174-
echo "=== Creating internal request to publish image:"
175-
echo ""
176-
echo "- from: ${sourceIndex}"
177-
echo "- to: ${publishingImages[$x]}"
178-
179-
internal-request --pipeline "${request}" \
180-
-p sourceIndex="${sourceIndex}" \
181-
-p targetIndex="${publishingImages[$x]}" \
182-
-p publishingCredentials="${credentials}" \
183-
-p retries="$(params.retries)" \
184-
-p taskGitUrl="$(params.taskGitUrl)" \
185-
-p taskGitRevision="$(params.taskGitRevision)" \
186-
-t "$(params.requestTimeout)" \
187-
--pipeline-timeout "${pipelineTimeout}" \
188-
--task-timeout "$taskTimeout" \
189-
-l ${pipelinerun_label}="$(params.pipelineRunUid)" \
190-
| tee "$IR_RESULT_FILE" || \
191-
(grep "^\[" "$IR_RESULT_FILE" | jq . && exit 1)
192-
193-
internalRequest=$(awk -F"'" '/created/ { print $2 }' "$IR_RESULT_FILE")
194-
echo "done (${internalRequest})"
195-
196-
results=$(kubectl get internalrequest "${internalRequest}" -o=jsonpath='{.status.results}')
197-
requestMessage=$(echo "${results}" | jq -r '.requestMessage // ""')
198-
199-
if echo "${requestMessage}" | grep -qi "error"; then
200-
echo "ERROR: Publish to ${publishingImages[$x]} failed"
201-
echo "requestMessage: ${requestMessage}"
202-
exit 1
203-
fi
204-
echo "=== published successfully (${publishingImages[$x]})"
205-
206-
echo ""
207-
echo ""
208-
done
209-
done
147+
python3 -m managed_publish_index_image \
148+
--request-timeout "$(params.requestTimeout)" \
149+
--publishing-credentials "${credentials}" \
150+
--retries "$(params.retries)" \
151+
--task-git-url "$(params.taskGitUrl)" \
152+
--task-git-revision "$(params.taskGitRevision)" \
153+
--pipeline-run-id "$(params.pipelineRunUid)" \
154+
--ir-results-file "$(params.dataDir)/$(params.internalRequestResultsFile)"
210155
- name: create-trusted-artifact
211156
computeResources:
212157
limits:

0 commit comments

Comments
 (0)