Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(RELEASE-1042): add publish-index-image internal task and pipeline #736

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/pipelines/publish-index-image-pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# publish-index-image-pipeline

Tekton pipeline to publish a built FBC index image using skopeo

## Parameters

| Name | Description | Optional | Default value |
|-----------------------|-----------------------------------------------|----------|---------------|
| sourceIndex | sourceIndex signing image | No | - |
| targetIndex | targetIndex signing image | No | - |
| retries | Number of skopeo retries | Yes | 0 |
| publishingCredentials | The credentials used to access the registries | No | - |
| requestUpdateTimeout | Max seconds waiting for the status update | Yes | 360 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: publish-index-image-pipeline
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
spec:
description: >-
Pipeline to publish a built FBC index image using skopeo
params:
- name: sourceIndex
type: string
description: sourceIndex signing image
- name: targetIndex
type: string
description: targetIndex signing image
- name: retries
type: string
default: "0"
description: Number of skopeo retries
- name: publishingCredentials
type: string
description: The credentials used to access the registries
- name: requestUpdateTimeout
type: string
default: "360"
description: Max seconds waiting for the status update
tasks:
- name: publish-index-image-task
taskRef:
name: publish-index-image-task
params:
- name: sourceIndex
value: $(params.sourceIndex)
- name: targetIndex
value: $(params.targetIndex)
- name: retries
value: $(params.retries)
- name: publishingCredentials
value: $(params.publishingCredentials)
- name: requestUpdateTimeout
value: $(params.requestUpdateTimeout)
results:
- name: requestMessage
value: $(tasks.publish-index-image-task.results.requestMessage)
1 change: 1 addition & 0 deletions internal/resources/publish-index-image-pipeline.yaml
1 change: 1 addition & 0 deletions internal/resources/publish-index-image-task.yaml
13 changes: 13 additions & 0 deletions internal/tasks/publish-index-image-task/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# publish-index-image-task

Tekton task to publish a built FBC index image using skopeo

## Parameters

| Name | Description | Optional | Default value |
|-----------------------|-----------------------------------------------|----------|---------------|
| sourceIndex | sourceIndex signing image | No | - |
| targetIndex | targetIndex signing image | No | - |
| retries | Number of skopeo retries | Yes | 0 |
| publishingCredentials | The credentials used to access the registries | No | - |
| requestUpdateTimeout | Max seconds waiting for the status update | Yes | 360 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: publish-index-image-task
labels:
app.kubernetes.io/version: "0.1.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
spec:
description: >-
Task to publish a built FBC index image using skopeo
params:
- name: sourceIndex
type: string
description: sourceIndex signing image
- name: targetIndex
type: string
description: targetIndex signing image
- name: retries
type: string
default: "0"
description: Number of skopeo retries
- name: publishingCredentials
type: string
default: "fbc-publishing-credentials"
description: The credentials used to access the registries
- name: requestUpdateTimeout
type: string
default: "360"
description: Max seconds waiting for the status update
results:
- name: requestMessage
steps:
- name: publish-index-image
env:
- name: SOURCE_INDEX_CREDENTIAL
valueFrom:
secretKeyRef:
key: sourceIndexCredential
name: $(params.publishingCredentials)
- name: TARGET_INDEX_CREDENTIAL
valueFrom:
secretKeyRef:
key: targetIndexCredential
name: $(params.publishingCredentials)
image: >-
quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env bash
PATH=/bin:/usr/bin:/usr/local/bin
export PATH

# do not authenticate if the source is redhat's "registry-proxy" which is unauthenticated.
if [[ ! "$(params.sourceIndex)" =~ ^registry-proxy(\-stage)?.engineering.redhat.com ]]; then
AUTH_PARAM=("--src-creds" "${SOURCE_INDEX_CREDENTIAL}")
fi

(skopeo copy \
--all \
--preserve-digests \
--retry-times "$(params.retries)" \
--src-tls-verify=false "${AUTH_PARAM[@]}" \
"docker://$(params.sourceIndex)" \
--dest-creds "${TARGET_INDEX_CREDENTIAL}" \
"docker://$(params.targetIndex)" && \
echo -n "Index Image Published successfully" || \
echo -n "Failed publishing Index Image" ) | tee "$(results.requestMessage.path)"

# trick to get the proper exit status
grep "success" "$(results.requestMessage.path)" >/dev/null
22 changes: 22 additions & 0 deletions internal/tasks/publish-index-image-task/tests/mocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -x

# mocks to be injected into task step scripts

function skopeo() {
echo Mock skopeo called with: $* >&2

if [[ "$*" == *"--src-tls-verify=false --src-creds source docker://quay.io/source"* ]]
then
return 0
elif [[ "$*" == *"--src-tls-verify=false docker://registry-proxy.engineering.redhat.com/foo"* ]]
then
return 0
elif [[ "$*" == *"--src-tls-verify=false docker://registry-proxy.engineering.redhat.com/fail"* ]]
then
return 1
else
echo Error: Unexpected call
exit 1
fi
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

TASK_PATH="$1"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Add mocks to the beginning of task step script
yq -i '.spec.steps[0].script = load_str("'$SCRIPT_DIR'/mocks.sh") + .spec.steps[0].script' "$TASK_PATH"

# Create a dummy secret (and delete it first if it exists)
kubectl delete secret publish-index-image-secret --ignore-not-found
kubectl create secret generic publish-index-image-secret --from-literal=sourceIndexCredential=source --from-literal=targetIndexCredential=target
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-publish-index-image-fail
annotations:
test/assert-task-failure: "run-task"
mmalina marked this conversation as resolved.
Show resolved Hide resolved
spec:
description: |
Run the publish-index-image task with a failing sourceIndex. The grep at the end of the task sets the task
status to that of the skopeo command, and here the mock will make the skopeo command fail due to the sourceIndex
tasks:
- name: run-task
taskRef:
name: publish-index-image-task
params:
- name: sourceIndex
value: "registry-proxy.engineering.redhat.com/fail"
- name: targetIndex
value: "quay.io/target"
- name: publishingCredentials
value: "publish-index-image-secret"
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-publish-index-image-registry-proxy
spec:
description: |
Run the publish-index-image task with a registry-proxy sourceIndex. Ensure the task succeeds, which can
only happen if --src-creds is properly added (due to the mocks.sh)
tasks:
- name: run-task
taskRef:
name: publish-index-image-task
params:
- name: sourceIndex
value: "registry-proxy.engineering.redhat.com/foo"
- name: targetIndex
value: "quay.io/target"
- name: publishingCredentials
value: "publish-index-image-secret"
- name: check-result
runAfter:
- run-task
params:
- name: requestMessage
value: $(tasks.run-task.results.requestMessage)
taskSpec:
params:
- name: requestMessage
type: string
steps:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env bash
set -ex

if [[ "$(params.requestMessage)" != "Index Image Published successfully" ]]; then
echo Error: requestMessage task result is not correct
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-publish-index-image
spec:
description: |
Run the publish-index-image task with a non registry-proxy sourceIndex
tasks:
- name: run-task
taskRef:
name: publish-index-image-task
params:
- name: sourceIndex
value: "quay.io/source"
- name: targetIndex
value: "quay.io/target"
- name: publishingCredentials
value: "publish-index-image-secret"
- name: check-result
runAfter:
- run-task
params:
- name: requestMessage
value: $(tasks.run-task.results.requestMessage)
taskSpec:
params:
- name: requestMessage
type: string
steps:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env bash
set -ex

if [[ "$(params.requestMessage)" != "Index Image Published successfully" ]]; then
echo Error: requestMessage task result is not correct
exit 1
fi
Loading