Skip to content

Commit 616e787

Browse files
committed
chore(SRVKP-8611): include io.openshift.build and upstream-vcs labels to build image
Include several 'io.openshift.build.*' labels on the build output, as well as several labels with upstream commit info. Follows BuildConfig conventions set by source-to-image. See also: https://docs.redhat.com/en/documentation/openshift_container_platform/4.19/html/builds_using_buildconfig/managing-build-output#builds-output-image-labels_managing-build-output
1 parent 8ab6f29 commit 616e787

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

.tekton/docker-build-ta.yaml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ spec:
2525
- description: Source Repository URL
2626
name: git-url
2727
type: string
28+
- default: ""
29+
description: Upstream source Repository URL
30+
name: upstream-git-url
31+
type: string
2832
- default: ""
2933
description: Revision of the Source Repository
3034
name: revision
@@ -33,7 +37,7 @@ spec:
3337
name: output-image
3438
type: string
3539
- default: .
36-
description: Path to the source code of an application's component from where
40+
description: Path to the source code of an applications component from where
3741
to build image.
3842
name: path-context
3943
type: string
@@ -142,6 +146,35 @@ spec:
142146
workspaces:
143147
- name: basic-auth
144148
workspace: git-auth
149+
- name: extract-upstream-info
150+
taskSpec:
151+
results:
152+
- name: upstream-vcs-ref
153+
steps:
154+
- name: use-trusted-artifact
155+
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:8391272c4e5011120e9e7fee2c1f339e9405366110bf239dadcbc21e953ce099
156+
args:
157+
- use
158+
- $(tasks.clone-repository.results.SOURCE_ARTIFACT)=/var/workdir/source
159+
- image: registry.access.redhat.com/ubi9/ubi
160+
workingDir: /var/workdir/source
161+
script: |
162+
#!/usr/bin/env bash
163+
echo -n $(cat head 2>/dev/null || echo -n "") | tee $(results.upstream-vcs-ref.path)
164+
stepTemplate:
165+
volumeMounts:
166+
- mountPath: /var/workdir
167+
name: workdir
168+
volumes:
169+
- name: workdir
170+
emptyDir: {}
171+
runAfter:
172+
- clone-repository
173+
when:
174+
- input: $(tasks.init.results.build)
175+
operator: in
176+
values:
177+
- "true"
145178
- name: prefetch-dependencies
146179
params:
147180
- name: input
@@ -209,8 +242,18 @@ spec:
209242
value: $(tasks.prefetch-dependencies.results.CACHI2_ARTIFACT)
210243
- name: IMAGE_APPEND_PLATFORM
211244
value: $(params.build-image-index)
245+
- name: LABELS
246+
# Labels to mimic several s2i openshift labels as well as include upstream info
247+
# See also: https://docs.redhat.com/en/documentation/openshift_container_platform/4.19/html/builds_using_buildconfig/managing-build-output#builds-output-image-labels_managing-build-output
248+
value:
249+
- "io.openshift.build.commit.id=$(tasks.clone-repository.results.commit)"
250+
- "io.openshift.build.commit.url=$(params.git-url)/commit/$(tasks.clone-repository.results.commit)"
251+
- "io.openshift.build.source-location=$(params.git-url)"
252+
- "upstream-vcs-ref=$(tasks.extract-upstream-info.results.upstream-vcs-ref)"
253+
- "upstream-vcs-location=$(params.upstream-git-url)"
212254
runAfter:
213255
- prefetch-dependencies
256+
- extract-upstream-info
214257
taskRef:
215258
params:
216259
- name: name

0 commit comments

Comments
 (0)