Skip to content

Commit 9f76c46

Browse files
committed
konflux: push images to the quay.io/ramalama org after integration testing
The "bats-integration" pipeline is now run on every pull request and push to the main branch. In the case of pushes, if the integration tests run successfully, the images are pushed to a repo matching their component name in the quay.io/ramalama org. Images will be tagged with the sha of the commit from which they were built. Signed-off-by: Mike Bonnet <[email protected]>
1 parent e8e5fae commit 9f76c46

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed

.tekton/integration/pipelines/bats-integration.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ spec:
2626
- name: git-revision
2727
description: Revision of the Git repository containing pipeline and task definitions
2828
default: main
29+
- name: repo-prefix
30+
description: The prefix (usually hostname/orgname) of the destination repo where the Snapshot components will be pushed
31+
default: quay.io/ramalama
32+
- name: skip-components
33+
description: A space-separated list of components that should not be pushed
34+
default: bats
35+
results:
36+
- name: TEST_OUTPUT
37+
description: Test results in JSON format
38+
value: $(tasks.push.results.TEST_OUTPUT)
2939
tasks:
3040
- name: init
3141
params:
@@ -64,3 +74,30 @@ spec:
6474
value: $(params.git-revision)
6575
- name: pathInRepo
6676
value: .tekton/integration/tasks/test-vm-cmd.yaml
77+
when:
78+
- input: $(tasks.init.results.sync)
79+
operator: in
80+
values: ["true"]
81+
- name: push
82+
params:
83+
- name: SNAPSHOT
84+
value: $(params.SNAPSHOT)
85+
- name: event-type
86+
value: $(tasks.init.results.event-type)
87+
- name: sync
88+
value: $(tasks.init.results.sync)
89+
- name: repo-prefix
90+
value: $(params.repo-prefix)
91+
- name: skip-components
92+
value: $(params.skip-components)
93+
taskRef:
94+
resolver: git
95+
params:
96+
- name: url
97+
value: $(params.git-url)
98+
- name: revision
99+
value: $(params.git-revision)
100+
- name: pathInRepo
101+
value: .tekton/integration/tasks/push-snapshot.yaml
102+
runAfter:
103+
- test

.tekton/integration/tasks/init-snapshot.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ spec:
1111
results:
1212
- name: event-type
1313
description: The type of event that triggered the pipeline
14+
- name: snapshot-type
15+
description: The type of Snapshot that is being tested.
16+
- name: sync
17+
description: >-
18+
True if all components are built from the same git commit. False if components
19+
are built from different commits.
1420
- name: bats-image
1521
description: URI of the bats image included in the snapshot
1622
- name: ramalama-image
@@ -27,8 +33,16 @@ spec:
2733
valueFrom:
2834
fieldRef:
2935
fieldPath: metadata.labels['pac.test.appstudio.openshift.io/event-type']
36+
- name: SNAPSHOT_TYPE
37+
valueFrom:
38+
fieldRef:
39+
fieldPath: metadata.labels['test.appstudio.openshift.io/type']
3040
- name: RESULTS_EVENT_TYPE_PATH
3141
value: $(results.event-type.path)
42+
- name: RESULTS_SNAPSHOT_TYPE_PATH
43+
value: $(results.snapshot-type.path)
44+
- name: RESULTS_SYNC_PATH
45+
value: $(results.sync.path)
3246
- name: RESULTS_BATS_IMAGE_PATH
3347
value: $(results.bats-image.path)
3448
- name: RESULTS_RAMALAMA_IMAGE_PATH
@@ -40,6 +54,10 @@ spec:
4054
dnf -y install jq
4155
echo -n "$EVENT_TYPE" | tee "$RESULTS_EVENT_TYPE_PATH"
4256
echo
57+
echo -n "$SNAPSHOT_TYPE" | tee "$RESULTS_SNAPSHOT_TYPE_PATH"
58+
echo
59+
jq -j '[.components[] | .source.git.revision] | unique | length == 1' <<< "$SNAPSHOT" | tee "$RESULTS_SYNC_PATH"
60+
echo
4361
component_image() {
4462
TAGSEP=":"
4563
if [ "$EVENT_TYPE" == "pull_request" ]; then
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
apiVersion: tekton.dev/v1
2+
kind: Task
3+
metadata:
4+
name: push-snapshot
5+
spec:
6+
description: Push images referenced by the provided Snapshot to another registry
7+
params:
8+
- name: SNAPSHOT
9+
description: Information about the Snapshot to be pushed
10+
- name: event-type
11+
description: The type of event that triggered the pipeline
12+
- name: sync
13+
description: >-
14+
True if all components are built from the same git commit. False if components
15+
are built from different commits.
16+
- name: repo-prefix
17+
description: >-
18+
The prefix (usually hostname/orgname) of the destination repo to push the Snapshot components to.
19+
The name of the component will be appended to this prefix and the result will be used as the
20+
destination repo to push the component to.
21+
- name: skip-components
22+
description: >-
23+
A space-separated list of components that should not be pushed
24+
default: ""
25+
results:
26+
- name: TEST_OUTPUT
27+
description: Test results in JSON format
28+
steps:
29+
- name: push-to-registry
30+
image: registry.redhat.io/rhel10/skopeo:latest
31+
env:
32+
- name: SNAPSHOT
33+
value: $(params.SNAPSHOT)
34+
- name: EVENT_TYPE
35+
value: $(params.event-type)
36+
- name: SYNC
37+
value: $(params.sync)
38+
- name: REPO_PREFIX
39+
value: $(params.repo-prefix)
40+
- name: SKIP_COMPONENTS
41+
value: $(params.skip-components)
42+
- name: RESULTS_TEST_OUTPUT_PATH
43+
value: $(results.TEST_OUTPUT.path)
44+
- name: NAMESPACE
45+
value: $(context.taskRun.namespace)
46+
script: |
47+
#!/bin/bash -x
48+
dnf -y install jq
49+
50+
log() {
51+
echo "[$(date -uIns)]" $*
52+
}
53+
54+
in_args() {
55+
local item="$1"
56+
shift
57+
while [ "$#" -gt 0 ]; do
58+
if [ "$item" == "$1" ]; then
59+
return 0
60+
fi
61+
shift
62+
done
63+
return 1
64+
}
65+
66+
test_output() {
67+
local RESULT="$1"
68+
local SUCCESSES="$2"
69+
local FAILURES="$3"
70+
local WARNINGS="$4"
71+
local NOTE="$5"
72+
73+
jq -jnc \
74+
--arg result "$RESULT" \
75+
--arg note "$NOTE" \
76+
--arg namespace "$NAMESPACE" \
77+
--arg successes "$SUCCESSES" \
78+
--arg failures "$FAILURES" \
79+
--arg warnings "$WARNINGS" \
80+
'{
81+
result: $result,
82+
timestamp: now | todateiso8601[:-1] | "\(.)+00:00",
83+
note: $note,
84+
namespace: $namespace,
85+
successes: $successes | tonumber,
86+
failures: $failures | tonumber,
87+
warnings: $warnings | tonumber
88+
}' | tee "$RESULTS_TEST_OUTPUT_PATH"
89+
}
90+
91+
COMPONENTS="$(jq -r '.components | length' <<< "$SNAPSHOT")"
92+
SKIP=($SKIP_COMPONENTS)
93+
94+
if [ "$EVENT_TYPE" != "push" ]; then
95+
NOTE="Skipped push of $COMPONENTS components from \"$EVENT_TYPE\" event"
96+
test_output SKIPPED 0 0 0 "$NOTE"
97+
exit
98+
elif [ "$SYNC" != "true" ]; then
99+
NOTE="Skipped push of $COMPONENTS components due to out-of-sync components"
100+
test_output SKIPPED 0 0 0 "$NOTE"
101+
exit
102+
fi
103+
104+
SUCCESSES=0
105+
SKIPS=0
106+
FAILED_COMPONENTS=()
107+
while read NAME SRC DEST; do
108+
if in_args "$NAME" "${SKIP[@]}"; then
109+
log Skipping push of "$NAME"
110+
(( SKIPS+=1 ))
111+
continue
112+
fi
113+
log Copying "$NAME" from "$SRC" to "$DEST"
114+
if skopeo copy --all --multi-arch all --retry-times 5 "docker://$SRC" "docker://$DEST"; then
115+
(( SUCCESSES+=1 ))
116+
else
117+
FAILED_COMPONENTS+=("$NAME")
118+
fi
119+
done < <(
120+
jq -r --arg prefix "$REPO_PREFIX" \
121+
'.components[] | "\(.name) \(.containerImage) \($prefix)/\(.name):\(.source.git.revision)"' \
122+
<<< "$SNAPSHOT"
123+
)
124+
125+
if [ "${#FAILED_COMPONENTS[*]}" -gt 0 ]; then
126+
NOTE="$SUCCESSES components successfully pushed, $SKIPS components skipped, ${#FAILED_COMPONENTS[*]} failed to push: ${FAILED_COMPONENTS[*]}"
127+
test_output FAILURE "$SUCCESSES" "${#FAILED_COMPONENTS[*]}" 0 "$NOTE"
128+
exit 1
129+
else
130+
NOTE="$SUCCESSES components successfully pushed, $SKIPS components skipped"
131+
test_output SUCCESS "$SUCCESSES" 0 0 "$NOTE"
132+
fi

0 commit comments

Comments
 (0)