Skip to content

Commit 0d740df

Browse files
authored
Merge pull request #1926 from containers/konflux-release-tag
konflux: release images when a tag is pushed to the git repo
2 parents edb1292 + e8e3a00 commit 0d740df

File tree

7 files changed

+660
-4
lines changed

7 files changed

+660
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ metadata:
55
spec:
66
description: |
77
Test the newly-built ramalama image and layered images on all supported architectures.
8+
If the tests succeed, push the images to the public repos. If the tests were triggered by
9+
pushing a tag to the git repo, apply floating tags to the pushed images.
810
params:
911
- name: SNAPSHOT
1012
description: >-
@@ -85,6 +87,10 @@ spec:
8587
value: $(params.SNAPSHOT)
8688
- name: event-type
8789
value: $(tasks.init.results.event-type)
90+
- name: snapshot-type
91+
value: $(tasks.init.results.snapshot-type)
92+
- name: release-tags
93+
value: $(tasks.init.results.release-tags)
8894
- name: sync
8995
value: $(tasks.init.results.sync)
9096
- name: repo-prefix

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ spec:
1313
description: The type of event that triggered the pipeline
1414
- name: snapshot-type
1515
description: The type of Snapshot that is being tested.
16+
- name: release-tags
17+
description: A space-separated list of tags that should be applied to the release
1618
- name: sync
1719
description: >-
1820
True if all components are built from the same git commit. False if components
@@ -39,10 +41,16 @@ spec:
3941
valueFrom:
4042
fieldRef:
4143
fieldPath: metadata.labels['test.appstudio.openshift.io/type']
44+
- name: RELEASE_TAGS
45+
valueFrom:
46+
fieldRef:
47+
fieldPath: metadata.annotations['custom.appstudio.openshift.io/release-tags']
4248
- name: RESULTS_EVENT_TYPE_PATH
4349
value: $(results.event-type.path)
4450
- name: RESULTS_SNAPSHOT_TYPE_PATH
4551
value: $(results.snapshot-type.path)
52+
- name: RESULTS_RELEASE_TAGS_PATH
53+
value: $(results.release-tags.path)
4654
- name: RESULTS_SYNC_PATH
4755
value: $(results.sync.path)
4856
- name: RESULTS_BATS_IMAGE_PATH
@@ -60,11 +68,13 @@ spec:
6068
echo
6169
echo -n "$SNAPSHOT_TYPE" | tee "$RESULTS_SNAPSHOT_TYPE_PATH"
6270
echo
71+
echo -n "$RELEASE_TAGS" | tee "$RESULTS_RELEASE_TAGS_PATH"
72+
echo
6373
jq -j '[.components[] | .source.git.revision] | unique | length == 1' <<< "$SNAPSHOT" | tee "$RESULTS_SYNC_PATH"
6474
echo
6575
component_image() {
6676
TAGSEP=":"
67-
if [ "$EVENT_TYPE" == "pull_request" ]; then
77+
if [ "$EVENT_TYPE" == "pull_request" ] || [[ "$EVENT_TYPE" == *-comment ]]; then
6878
TAGSEP+="on-pr-"
6979
fi
7080
jq -j --arg name "$1" --arg tagsep "$TAGSEP" '.components[] | select(.name == $name) | [(.containerImage | split("@")[0]), .source.git.revision] | join($tagsep)' <<< "$SNAPSHOT"

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ spec:
99
description: Information about the Snapshot to be pushed
1010
- name: event-type
1111
description: The type of event that triggered the pipeline
12+
- name: snapshot-type
13+
description: The type of snapshot that triggered the pipeline
14+
- name: release-tags
15+
description: A space-separated list of tags that should be applied to the release
16+
default: ""
1217
- name: sync
1318
description: >-
1419
True if all components are built from the same git commit. False if components
@@ -33,6 +38,10 @@ spec:
3338
value: $(params.SNAPSHOT)
3439
- name: EVENT_TYPE
3540
value: $(params.event-type)
41+
- name: SNAPSHOT_TYPE
42+
value: $(params.snapshot-type)
43+
- name: RELEASE_TAGS
44+
value: $(params.release-tags)
3645
- name: SYNC
3746
value: $(params.sync)
3847
- name: REPO_PREFIX
@@ -91,7 +100,11 @@ spec:
91100
COMPONENTS="$(jq -r '.components | length' <<< "$SNAPSHOT")"
92101
SKIP=($SKIP_COMPONENTS)
93102
94-
if [ "$EVENT_TYPE" != "push" ]; then
103+
if [ "$SNAPSHOT_TYPE" != "override" ]; then
104+
NOTE="Skipped push of $COMPONENTS components from \"$SNAPSHOT_TYPE\" snapshot"
105+
test_output SKIPPED 0 0 0 "$NOTE"
106+
exit
107+
elif [ "$EVENT_TYPE" != "override" ]; then
95108
NOTE="Skipped push of $COMPONENTS components from \"$EVENT_TYPE\" event"
96109
test_output SKIPPED 0 0 0 "$NOTE"
97110
exit
@@ -110,8 +123,21 @@ spec:
110123
(( SKIPS+=1 ))
111124
continue
112125
fi
113-
log Copying "$NAME" from "$SRC" to "$DEST"
114-
if skopeo copy --all --retry-times 5 "docker://$SRC" "docker://$DEST"; then
126+
DESTS=("$DEST")
127+
for TAG in $RELEASE_TAGS; do
128+
RELEASE_DEST="${DEST%:*}:$TAG"
129+
DESTS+=("$RELEASE_DEST")
130+
done
131+
SUCCESS="true"
132+
for DEST in "${DESTS[@]}"; do
133+
log Copying "$NAME" from "$SRC" to "$DEST"
134+
if skopeo copy --all --retry-times 5 "docker://$SRC" "docker://$DEST"; then
135+
:
136+
else
137+
SUCCESS="false"
138+
fi
139+
done
140+
if [ "$SUCCESS" == "true" ]; then
115141
(( SUCCESSES+=1 ))
116142
else
117143
FAILED_COMPONENTS+=("$NAME")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: tekton.dev/v1
2+
kind: PipelineRun
3+
metadata:
4+
annotations:
5+
build.appstudio.openshift.io/repo: https://github.com/containers/ramalama?rev={{revision}}
6+
build.appstudio.redhat.com/commit_sha: "{{revision}}"
7+
build.appstudio.redhat.com/git_tag: "{{git_tag}}"
8+
build.appstudio.redhat.com/latest_tag: "true"
9+
pipelinesascode.tekton.dev/on-event: "[push]"
10+
pipelinesascode.tekton.dev/on-target-branch: "[refs/tags/v*]"
11+
pipelinesascode.tekton.dev/cancel-in-progress: "false"
12+
pipelinesascode.tekton.dev/max-keep-runs: "3"
13+
labels:
14+
appstudio.openshift.io/application: ramalama
15+
pipelines.appstudio.openshift.io/type: release
16+
name: ramalama-release-tag
17+
namespace: ramalama-tenant
18+
spec:
19+
params:
20+
- name: skip-components
21+
value: e2e
22+
pipelineRef:
23+
name: create-release-snapshot
24+
timeouts:
25+
pipeline: 6h
26+
finally: 15m
27+
taskRunTemplate:
28+
serviceAccountName: appstudio-pipeline
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
kind: Pipeline
2+
apiVersion: tekton.dev/v1
3+
metadata:
4+
name: create-release-snapshot
5+
spec:
6+
description: |
7+
Check if all builds associated with the given commit are complete. If they are, create an override Snapshot
8+
to test all the images together.
9+
params:
10+
- name: SNAPSHOT
11+
description: >-
12+
Information about the components included in the current snapshot under test.
13+
default: ""
14+
- name: skip-components
15+
description: A space-separated list of components that should not be pushed
16+
default: ""
17+
- name: git-url
18+
description: URL of the Git repository containing pipeline and task definitions
19+
default: https://github.com/containers/ramalama.git
20+
- name: git-revision
21+
description: Revision of the Git repository containing pipeline and task definitions
22+
default: main
23+
results:
24+
- name: TEST_OUTPUT
25+
description: Test results in JSON format
26+
value: $(tasks.create.results.TEST_OUTPUT)
27+
tasks:
28+
- name: create
29+
params:
30+
- name: skip
31+
value: $(params.skip-components)
32+
taskRef:
33+
resolver: git
34+
params:
35+
- name: url
36+
value: $(params.git-url)
37+
- name: revision
38+
value: $(params.git-revision)
39+
- name: pathInRepo
40+
value: .tekton/release/tasks/create-override-snapshot.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
YAMLDIR="$(dirname $0)"
4+
TMPSCRIPT="$(mktemp)"
5+
if [ "$1" == "-s" ]; then
6+
echo "Saving file to $TMPSCRIPT"
7+
else
8+
trap "rm $TMPSCRIPT" 0
9+
fi
10+
awk '/script:/ {in_script = 1; next}; {if (in_script) print substr($0, 7)}' "$YAMLDIR/create-override-snapshot.yaml" > "$TMPSCRIPT"
11+
python3 "$TMPSCRIPT"

0 commit comments

Comments
 (0)