Skip to content

Commit

Permalink
Prepare for universal usage of an image index task
Browse files Browse the repository at this point in the history
* Created a new task that has an appropriate name (build-image-index)
* Changed the build-image-manifest task to be a rebuild of the new
  build-image-index task
* Enabled the image index task to run and skip the generation of an
  index image. This lets the task be added into "single arch" pipelines
  as well as there are still situations where an image index should be
  created

Signed-off-by: arewm <[email protected]>
  • Loading branch information
arewm committed Aug 16, 2024
1 parent 029db70 commit f327525
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 38 deletions.
19 changes: 19 additions & 0 deletions task/build-image-index/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# build-image-index task

This task generates an image index from a collection of existing single platform images to create a multi-platform image.

## Parameters
| name | description |default value|required|
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|---|
| IMAGE | Reference of the image buildah will produce. ||true|
| TLSVERIFY | Verify the TLS on the registry endpoint (for push/pull to a non-TLS registry) |true|false|
| COMMIT_SHA | The git commit sha that was used to produce the images |""|false|
| IMAGES | List of images that should be merged into a multi arch image |false|false|
| IMAGE_EXPIRES_AFTER | Delete image tag after specified time. Empty means to keep the image tag. Time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively. |""|false|

## Results
|name|description|
|---|---|
|IMAGE_DIGEST|Digest of the image just built|
|IMAGE_URL|Image repository where the built image was pushed|

Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@ metadata:
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: "image-build, konflux"
name: build-image-manifest
name: build-image-index
spec:
description: |-
This takes existing images and stiches them together into a multi platform image.
This takes existing Image Manifests and combines them in an Image Index.
params:
- description: Reference of the image buildah will produce.
name: IMAGE
- name: IMAGE
description: The target image and tag where the image will be pushed to.
type: string
- default: "true"
- name: TLSVERIFY
description: Verify the TLS on the registry endpoint (for push/pull to a non-TLS registry)
name: TLSVERIFY
type: string
default: "true"
- name: COMMIT_SHA
description: The image is built from this commit.
description: The commit the image is built from.
type: string
default: ""
- name: IMAGES
description: List of images that are to be merged into the multi platform image
description: List of Image Manifests to be referenced by the Image Index
type: array
- default: ""
description: Delete image tag after specified time. Empty means to keep the image tag. Time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.
name: IMAGE_EXPIRES_AFTER
- name: IMAGE_EXPIRES_AFTER
description: Delete image tag after specified time resulting in garbage collection of the digest. Empty means to keep the image tag. Time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.
type: string
default: ""
- name: BUILD_IMAGE_INDEX
description: Create an OCI image index referencing all passed params.IMAGES. This allows us to always include this task for a consistent pipeline even if a user does not want to generate the image index. If the image index generation is skipped, the task will forward values for params.IMAGES[0] to results.IMAGE_*.
type: string
default: "false"
- name: STORAGE_DRIVER
description: Storage driver to configure for buildah
type: string
Expand All @@ -45,14 +49,16 @@ spec:
env:
- name: BUILDAH_FORMAT
value: oci
- name: STORAGE_DRIVER
value: $(params.STORAGE_DRIVER)
- name: COMMIT_SHA
value: $(params.COMMIT_SHA)
- name: IMAGE
value: $(params.IMAGE)
- name: TLSVERIFY
value: $(params.TLSVERIFY)
- name: COMMIT_SHA
value: $(params.COMMIT_SHA)
- name: BUILD_IMAGE_INDEX
value: $(params.BUILD_IMAGE_INDEX)
- name: STORAGE_DRIVER
value: $(params.STORAGE_DRIVER)
steps:
- image: quay.io/konflux-ci/buildah-task:latest@sha256:5d933087a49a6e0b959b9a9fa5a91d545380217e565d7be7cc74a9588f64c314
# per https://kubernetes.io/docs/concepts/containers/images/#imagepullpolicy-defaulting
Expand All @@ -79,10 +85,19 @@ spec:
for i in $@
do
TOADD="$i"
if [[ $(echo $i | tr -cd ":" | wc -c) == 2 ]]; then
if [[ $(echo "$i" | tr -cd ":" | wc -c) == 2 ]]; then
#we need to remove the tag, and just reference the digest
#as tag + digest is not supported
TOADD="$(echo $i | cut -d: -f1)@sha256:$(echo $i | cut -d: -f3)"
TOADD_REPOSITORY="$(echo "$i" | cut -d: -f1)"
TOADD_DIGEST="sha256:$(echo "$i" | cut -d: -f3)"
TOADD="${TOADD_REPOSITORY}@${TOADD_DIGEST}"
fi
if [[ "$SKIP_INDEX_GENERATION" != "false" ]]; then
echo "Skipping image index generation. Returning results for $TOADD"
echo -n "${TOADD_REPOSITORY}" > "$(results.IMAGE_URL.path)"
echo -n "${TOADD_DIGEST}" > "$(results.IMAGE_DIGEST.path)"
echo -n "${TOADD}" > "$(results.IMAGES.path)"
exit 0
fi
echo "Adding $TOADD"
image_manifests="${image_manifests} ${TOADD},"
Expand Down
5 changes: 5 additions & 0 deletions task/build-image-index/0.1/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- build-image-index.yaml
5 changes: 5 additions & 0 deletions task/build-image-index/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See the OWNERS docs: https://go.k8s.io/owners
approvers:
- build-team
reviewers:
- build-team
2 changes: 2 additions & 0 deletions task/build-image-manifest/0.1/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# build-image-manifest task

WARNING: Usage of this task is deprecated. You should use the `build-image-index` task instead.

This task generates an image index from a collection of existing single platform images to create a multi-platform image.

## Parameters
Expand Down
10 changes: 10 additions & 0 deletions task/build-image-manifest/0.1/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../../build-image-index/0.1

patches:
- path: patch.yaml
target:
kind: Task
4 changes: 4 additions & 0 deletions task/build-image-manifest/0.1/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- op: replace
path: /metadata/name
value: build-image-manifest
21 changes: 0 additions & 21 deletions task/build-image-manifest/README.md

This file was deleted.

0 comments on commit f327525

Please sign in to comment.