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 hte 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 2, 2024
1 parent 1924ddd commit bf2e62e
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 21 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:latest@sha256:3fe211715717eca9eca1f19d326e19dd052c92fc6eb4f2434d8f903fe5b9aeb7
# per https://kubernetes.io/docs/concepts/containers/images/#imagepullpolicy-defaulting
Expand Down Expand Up @@ -82,7 +88,16 @@ spec:
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
1 change: 1 addition & 0 deletions task/build-image-index/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stonesoup Build Team
22 changes: 22 additions & 0 deletions task/build-image-index/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# build-image-index task

This takes existing Image Manifests and combines them in an Image Index.

## Parameters
|name|description|default value|required|
|---|---|---|---|
|IMAGE|The target image and tag where the image will be pushed to.||true|
|TLSVERIFY|Verify the TLS on the registry endpoint (for push/pull to a non-TLS registry)|true|false|
|COMMIT_SHA|The commit the image is built from.|""|false|
|IMAGES|List of Image Manifests to be referenced by the Image Index||true|
|IMAGE_EXPIRES_AFTER|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.|""|false|
|BUILD_IMAGE_INDEX|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_*.|false|false|
|STORAGE_DRIVER|Storage driver to configure for buildah|vfs|false|

## Results
|name|description|
|---|---|
|IMAGE_DIGEST|Digest of the image just built|
|IMAGE_URL|Image repository where the built image was pushed|
|IMAGES|List of all referenced image manifests|

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
11 changes: 6 additions & 5 deletions task/build-image-manifest/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# build-image-manifest task

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.

## Parameters
|name|description|default value|required|
|---|---|---|---|
|IMAGE|Reference of the image buildah will produce.||true|
|IMAGE|The target image and tag where the image will be pushed to.||true|
|TLSVERIFY|Verify the TLS on the registry endpoint (for push/pull to a non-TLS registry)|true|false|
|COMMIT_SHA|The image is built from this commit.|""|false|
|IMAGES|List of images that are to be merged into the multi platform image||true|
|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|
|COMMIT_SHA|The commit the image is built from.|""|false|
|IMAGES|List of Image Manifests to be referenced by the Image Index||true|
|IMAGE_EXPIRES_AFTER|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.|""|false|
|BUILD_IMAGE_INDEX|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_*.|false|false|
|STORAGE_DRIVER|Storage driver to configure for buildah|vfs|false|

## Results
Expand Down

0 comments on commit bf2e62e

Please sign in to comment.