diff --git a/tekton/ci-cd/manifests/pipelines/fastapi-pipeline.yaml b/tekton/ci-cd/manifests/pipelines/fastapi-pipeline.yaml index f4c6ac6..42ff3b8 100644 --- a/tekton/ci-cd/manifests/pipelines/fastapi-pipeline.yaml +++ b/tekton/ci-cd/manifests/pipelines/fastapi-pipeline.yaml @@ -47,7 +47,9 @@ spec: - clone params: - name: IMAGE - value: zot0213.kro.kr/$(params.app-name):$(params.git-revision) + value: zot0213.kro.kr/$(params.app-name) + - name: TAG + value: $(params.git-revision) - name: DOCKERFILE value: ./Dockerfile - name: CONTEXT diff --git a/tekton/ci-cd/manifests/pipelines/nextjs-pipeline.yaml b/tekton/ci-cd/manifests/pipelines/nextjs-pipeline.yaml index c22f110..79a74f8 100644 --- a/tekton/ci-cd/manifests/pipelines/nextjs-pipeline.yaml +++ b/tekton/ci-cd/manifests/pipelines/nextjs-pipeline.yaml @@ -51,7 +51,9 @@ spec: - clone params: - name: IMAGE - value: zot0213.kro.kr/$(params.app-name):$(params.git-revision) + value: zot0213.kro.kr/$(params.app-name) + - name: TAG + value: $(params.git-revision) - name: DOCKERFILE value: ./Dockerfile - name: CONTEXT diff --git a/tekton/ci-cd/manifests/pipelines/python-pipeline.yaml b/tekton/ci-cd/manifests/pipelines/python-pipeline.yaml index fc22dd7..3da6dd5 100644 --- a/tekton/ci-cd/manifests/pipelines/python-pipeline.yaml +++ b/tekton/ci-cd/manifests/pipelines/python-pipeline.yaml @@ -47,7 +47,9 @@ spec: - clone params: - name: IMAGE - value: zot0213.kro.kr/$(params.app-name):$(params.git-revision) + value: zot0213.kro.kr/$(params.app-name) + - name: TAG + value: $(params.git-revision) - name: DOCKERFILE value: ./Dockerfile - name: CONTEXT diff --git a/tekton/ci-cd/manifests/tasks/buildah-build-push.yaml b/tekton/ci-cd/manifests/tasks/buildah-build-push.yaml index b8dc5b0..0703d8b 100644 --- a/tekton/ci-cd/manifests/tasks/buildah-build-push.yaml +++ b/tekton/ci-cd/manifests/tasks/buildah-build-push.yaml @@ -4,11 +4,15 @@ metadata: name: buildah-build-push namespace: tekton-pipelines spec: - description: Build container image with Buildah and push to registry + description: Build container image with Buildah and push as OCI manifest list params: - name: IMAGE - description: Full image reference (registry/repo:tag) + description: Image reference without tag (registry/repo) type: string + - name: TAG + description: Image tag (e.g., commit SHA or branch) + type: string + default: latest - name: DOCKERFILE description: Path to Dockerfile type: string @@ -31,7 +35,7 @@ spec: - name: IMAGE_DIGEST description: Digest of built image - name: IMAGE_URL - description: Full URL of pushed image + description: Full URL of pushed image with digest steps: - name: build-and-push image: quay.io/buildah/stable:v1.33 @@ -45,7 +49,9 @@ spec: #!/usr/bin/env bash set -ex - REGISTRY=$(echo "$(params.IMAGE)" | cut -d'/' -f1) + IMAGE="$(params.IMAGE)" + TAG="$(params.TAG)" + REGISTRY=$(echo "$IMAGE" | cut -d'/' -f1) DOCKER_CONFIG="$(workspaces.dockerconfig.path)/.dockerconfigjson" # Login to registry @@ -61,11 +67,24 @@ spec: [ -n "$line" ] && BUILD_ARGS_FLAGS="$BUILD_ARGS_FLAGS --build-arg $line" done <<< "$BUILD_ARGS" - # Build and push - buildah bud --platform linux/arm64 --format docker \ - -f $(params.DOCKERFILE) -t $(params.IMAGE) $BUILD_ARGS_FLAGS $(params.CONTEXT) - buildah push --digestfile /tmp/image-digest $(params.IMAGE) + # Build OCI image + buildah bud --platform linux/arm64 --format oci \ + -f $(params.DOCKERFILE) -t localhost/build:local $BUILD_ARGS_FLAGS $(params.CONTEXT) + + # Create and push manifest list with :latest tag + buildah manifest create ${IMAGE}:latest + buildah manifest add ${IMAGE}:latest localhost/build:local + buildah manifest push --all --digestfile /tmp/image-digest \ + ${IMAGE}:latest docker://${IMAGE}:latest + + # Also push with specific tag if not 'latest' + if [ "$TAG" != "latest" ]; then + buildah manifest create ${IMAGE}:${TAG} + buildah manifest add ${IMAGE}:${TAG} localhost/build:local + buildah manifest push --all ${IMAGE}:${TAG} docker://${IMAGE}:${TAG} + fi # Output results - cat /tmp/image-digest | tee $(results.IMAGE_DIGEST.path) - echo -n "$(params.IMAGE)" | tee $(results.IMAGE_URL.path) + DIGEST=$(cat /tmp/image-digest) + echo -n "$DIGEST" | tee $(results.IMAGE_DIGEST.path) + echo -n "${IMAGE}:latest@${DIGEST}" | tee $(results.IMAGE_URL.path)