Skip to content

Commit

Permalink
Add new task for tagging images
Browse files Browse the repository at this point in the history
This new task "apply-tags" allows specifying additional-tags that will
be added to the specified image.

STONEBLD-2418

Signed-off-by: mkosiarc <[email protected]>
  • Loading branch information
mkosiarc committed May 13, 2024
1 parent 46f55f8 commit 4145807
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pipelines/template-build/template-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ spec:
value: $(tasks.build-container.results.IMAGE_URL)
- name: IMAGE_DIGEST
value: $(tasks.build-container.results.IMAGE_DIGEST)
- name: apply-tags
runAfter:
- build-container
taskRef:
name: apply-tags
version: "0.1"
params:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)

finally:
- name: show-sbom
Expand Down
13 changes: 13 additions & 0 deletions task/apply-tags/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# apply-tags task

Apply-tags task will apply additional tags to the specified IMAGE. These additional tags can be provided via the ADDITIONAL_TAGS array parameter or they can also be provided in the image label "konflux.additional-tags". If you specify more than one additional tag in the label, they must be separated by a comma, e.g:

```
LABEL konflux.additional-tags="tag1, tag2"
```

## Parameters
|name|description|default value|required|
|---|---|---|---|
|IMAGE|Reference of image that was pushed to registry in the buildah task.||true|
|ADDITIONAL_TAGS|Additional tags that will be applied to the image in the registry.|[]|false|
63 changes: 63 additions & 0 deletions task/apply-tags/0.1/apply-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: "appstudio, hacbs"
name: apply-tags
spec:
description: >-
Applies additional tags to the built image.
params:
- name: IMAGE
description: Reference of image that was pushed to registry in the buildah task.
type: string
- name: ADDITIONAL_TAGS
description: Additional tags that will be applied to the image in the registry.
type: array
default: []
steps:
- name: apply-additional-tags-from-parameter
image: registry.access.redhat.com/ubi9/skopeo:9.4-6@sha256:c4d70dec3eb0a0c831490192145ea25431fe04d1cf307f8d61e2d87adb41e7e3
args:
- $(params.ADDITIONAL_TAGS)
env:
- name: IMAGE
value: $(params.IMAGE)
script: |
#!/bin/bash
if [ "$#" -ne 0 ]; then
IMAGE_WITHOUT_TAG=$(echo "$IMAGE" | sed 's/:[^:]*$//')
for tag in "$@"; do
echo "Applying tag $tag"
skopeo copy docker://$IMAGE docker://$IMAGE_WITHOUT_TAG:$tag
done
else
echo "No additional tags parameter specified"
fi
- name: apply-additional-tags-from-image-label
image: registry.access.redhat.com/ubi9/skopeo:9.4-6@sha256:c4d70dec3eb0a0c831490192145ea25431fe04d1cf307f8d61e2d87adb41e7e3
env:
- name: IMAGE
value: $(params.IMAGE)
script: |
#!/bin/bash
ADDITIONAL_TAGS_FROM_IMAGE_LABEL=$(skopeo inspect --format '{{ index .Labels "konflux.additional-tags" }}' docker://$IMAGE)
if [ -n "${ADDITIONAL_TAGS_FROM_IMAGE_LABEL}" ]; then
IFS=', ' read -r -a tags_array <<< "$ADDITIONAL_TAGS_FROM_IMAGE_LABEL"
IMAGE_WITHOUT_TAG=$(echo "$IMAGE" | sed 's/:[^:]*$//')
for tag in "${tags_array[@]}"
do
echo "Applying tag $tag"
skopeo copy docker://$IMAGE docker://$IMAGE_WITHOUT_TAG:$tag
done
else
echo "No additional tags specified in the image labels"
fi
1 change: 1 addition & 0 deletions task/apply-tags/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Konflux Build team

0 comments on commit 4145807

Please sign in to comment.