From 0642dba48e771edcb131740613805e99c77f706b Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Fri, 8 Mar 2024 08:37:43 +0100 Subject: [PATCH 01/13] add parallel task --- .tekton/create-ci-image-pipelinerun.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index ec86a3c5..5c3da285 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -89,6 +89,20 @@ spec: workspace: source - name: dockerconfig workspace: dockerconfig + - name: buildah2 + taskref: + kind: ClusterTask + name: buildah + params: + - name: IMAGE + value: $(tasks.generate-image-name.results.image-name) + - name: DOCKERFILE + value: ./Dockerfile.CI + runAfter: + - generate-image-name + workspaces: + - name: source + workspace: source - name: skopeo-copy taskRef: kind: ClusterTask From 70a19d3c86467eddbd4b1ca5c6a6ab01f46a5092 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Fri, 8 Mar 2024 10:11:34 +0100 Subject: [PATCH 02/13] when expressions --- .tekton/create-ci-image-pipelinerun.yaml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 5c3da285..69572b7a 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -1,5 +1,5 @@ --- -apiVersion: tekton.dev/v1beta1 +apiVersion: tekton.dev/v1 kind: PipelineRun metadata: name: create-push-ci-image @@ -39,6 +39,7 @@ spec: results: - name: image-name - name: image-name-timestamp + - name: repository steps: - name: generate-image-name image: quay.io/openshift-pipeline/ci @@ -47,21 +48,26 @@ spec: BRANCH_NAME={{ target_branch }} IMAGE_NAME="" IMAGE_NAME_TIMESTAMP="" + REPOSITORY="" TIMESTAMP=$(date +"%y%m%d%H%M") if [ "$BRANCH_NAME" == "master" ]; then if [ {{ event_type }} == "pull_request" ]; then IMAGE_NAME="image-registry.openshift-image-registry.svc:5000/pipelines-ci/ci:latest" IMAGE_NAME_TIMESTAMP="image-registry.openshift-image-registry.svc:5000/pipelines-ci/ci:5.0-$TIMESTAMP" + REPOSITORY="image-registry" else - IMAGE_NAME="quay.io/openshift-pipeline/ci:latest" - IMAGE_NAME_TIMESTAMP="quay.io/openshift-pipeline/ci:5.0-$TIMESTAMP" + IMAGE_NAME="quay.io/openshift-pipeline/chainstest/test:latest" + IMAGE_NAME_TIMESTAMP="quay.io/openshift-pipeline/chainstest/test:5.0-$TIMESTAMP" + REPOSITORY="quay.io" fi elif [[ "$BRANCH_NAME" == release-* ]]; then if [ {{ event_type }} == "pull_request" ]; then IMAGE_NAME="image-registry.openshift-image-registry.svc:5000/pipelines-ci/ci:${BRANCH_NAME#release-}" + REPOSITORY="image-registry" else IMAGE_NAME="quay.io/openshift-pipeline/ci:${BRANCH_NAME#release-}" + REPOSITORY="quay.io" fi IMAGE_NAME_TIMESTAMP="$IMAGE_NAME-$TIMESTAMP" else @@ -71,9 +77,11 @@ spec: echo -n "$IMAGE_NAME" | tee $(results.image-name.path) echo -n "$IMAGE_NAME_TIMESTAMP" | tee $(results.image-name-timestamp.path) + echo -n "$REPOSITORY" | tee $(results.repository.path) runAfter: - fetch-repository - name: buildah + onError: continue taskRef: kind: ClusterTask name: buildah @@ -89,8 +97,11 @@ spec: workspace: source - name: dockerconfig workspace: dockerconfig + when: + expression: $(tasks.generate-image-name.results.repository == 'quay.io') - name: buildah2 - taskref: + onError: continue + taskRef: kind: ClusterTask name: buildah params: @@ -103,6 +114,8 @@ spec: workspaces: - name: source workspace: source + when: + expression: $(tasks.generate-image-name.results.repository == 'image-registry') - name: skopeo-copy taskRef: kind: ClusterTask @@ -117,6 +130,7 @@ spec: value: docker://$(tasks.generate-image-name.results.image-name-timestamp) runAfter: - buildah + - buildah2 finally: - name: send-slack-notification taskRef: @@ -149,4 +163,4 @@ spec: - ReadWriteOnce resources: requests: - storage: 1Gi + storage: 1Gi \ No newline at end of file From 31cbf320572709692372d7cf88c6317b2454f691 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Fri, 8 Mar 2024 10:17:17 +0100 Subject: [PATCH 03/13] refactoring --- .tekton/create-ci-image-pipelinerun.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 69572b7a..679e0594 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -98,7 +98,10 @@ spec: - name: dockerconfig workspace: dockerconfig when: - expression: $(tasks.generate-image-name.results.repository == 'quay.io') + - input: "quay.io" + operator: in + values: + - "$(tasks.generate-image-name.results.repository)" - name: buildah2 onError: continue taskRef: @@ -115,7 +118,10 @@ spec: - name: source workspace: source when: - expression: $(tasks.generate-image-name.results.repository == 'image-registry') + - input: "image-registry" + operator: in + values: + - "$(tasks.generate-image-name.results.repository)" - name: skopeo-copy taskRef: kind: ClusterTask From 338c2f213f2b5f2412dbc73ead2898e9113a1bd9 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Fri, 8 Mar 2024 11:01:18 +0100 Subject: [PATCH 04/13] refactoring --- .tekton/create-ci-image-pipelinerun.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 679e0594..67bac3ba 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -81,7 +81,6 @@ spec: runAfter: - fetch-repository - name: buildah - onError: continue taskRef: kind: ClusterTask name: buildah @@ -103,7 +102,6 @@ spec: values: - "$(tasks.generate-image-name.results.repository)" - name: buildah2 - onError: continue taskRef: kind: ClusterTask name: buildah From b81f9a37ffff0630a41295dd485dae90317e2f6c Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Fri, 8 Mar 2024 12:44:26 +0100 Subject: [PATCH 05/13] correct image name --- .tekton/create-ci-image-pipelinerun.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 67bac3ba..84319719 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -57,8 +57,8 @@ spec: IMAGE_NAME_TIMESTAMP="image-registry.openshift-image-registry.svc:5000/pipelines-ci/ci:5.0-$TIMESTAMP" REPOSITORY="image-registry" else - IMAGE_NAME="quay.io/openshift-pipeline/chainstest/test:latest" - IMAGE_NAME_TIMESTAMP="quay.io/openshift-pipeline/chainstest/test:5.0-$TIMESTAMP" + IMAGE_NAME="quay.io/openshift-pipeline/chainstest:latest" + IMAGE_NAME_TIMESTAMP="quay.io/openshift-pipeline/chainstest:5.0-$TIMESTAMP" REPOSITORY="quay.io" fi elif [[ "$BRANCH_NAME" == release-* ]]; then From e8e1d5b55fdc6aed492f757a187c6cd08672fb74 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Fri, 8 Mar 2024 13:08:47 +0100 Subject: [PATCH 06/13] rename tasks --- .tekton/create-ci-image-pipelinerun.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 84319719..febcb807 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -80,7 +80,7 @@ spec: echo -n "$REPOSITORY" | tee $(results.repository.path) runAfter: - fetch-repository - - name: buildah + - name: buildah-push taskRef: kind: ClusterTask name: buildah @@ -101,7 +101,7 @@ spec: operator: in values: - "$(tasks.generate-image-name.results.repository)" - - name: buildah2 + - name: buildah-pull-request taskRef: kind: ClusterTask name: buildah @@ -133,8 +133,8 @@ spec: - name: destImageURL value: docker://$(tasks.generate-image-name.results.image-name-timestamp) runAfter: - - buildah - - buildah2 + - buildah-push + - buildah-pull-request finally: - name: send-slack-notification taskRef: From 39fda8675e4bc2525b40f00eef497d2811ac8394 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 09:26:35 +0100 Subject: [PATCH 07/13] add service account --- .tekton/create-ci-image-pipelinerun.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index febcb807..47f8c3a3 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -8,6 +8,7 @@ metadata: "Dockerfile.CI".pathChanged() && ( event == "push" || event == "pull_request" ) pipelinesascode.tekton.dev/max-keep-runs: "5" spec: + serviceAccountName: skopeo-copy-quay-creds params: - name: repo_url value: "{{ repo_url }}" From 7148d4cef93d70494891ff0e7c6f854fb6729f7a Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 11:22:28 +0100 Subject: [PATCH 08/13] change spec --- .tekton/create-ci-image-pipelinerun.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 47f8c3a3..45010b1e 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -8,7 +8,9 @@ metadata: "Dockerfile.CI".pathChanged() && ( event == "push" || event == "pull_request" ) pipelinesascode.tekton.dev/max-keep-runs: "5" spec: - serviceAccountName: skopeo-copy-quay-creds + taskRunSpecs: + - pipelineTaskName: skopeo-copy + serviceAccountName: skopeo-copy-quay-creds params: - name: repo_url value: "{{ repo_url }}" From 5efe022441870c2947f5db1b18c619790c7480c3 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 12:23:42 +0100 Subject: [PATCH 09/13] add skopeo-copy task --- .tekton/create-ci-image-pipelinerun.yaml | 29 +++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 45010b1e..5ba085cb 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -9,7 +9,7 @@ metadata: pipelinesascode.tekton.dev/max-keep-runs: "5" spec: taskRunSpecs: - - pipelineTaskName: skopeo-copy + - pipelineTaskName: skopeo-copy-push serviceAccountName: skopeo-copy-quay-creds params: - name: repo_url @@ -123,7 +123,7 @@ spec: operator: in values: - "$(tasks.generate-image-name.results.repository)" - - name: skopeo-copy + - name: skopeo-copy-pull-request taskRef: kind: ClusterTask name: skopeo-copy @@ -136,8 +136,31 @@ spec: - name: destImageURL value: docker://$(tasks.generate-image-name.results.image-name-timestamp) runAfter: - - buildah-push - buildah-pull-request + when: + - input: "image-registry" + operator: in + values: + - "$(tasks.generate-image-name.results.repository)" + - name: skopeo-copy-push + taskRef: + kind: ClusterTask + name: skopeo-copy + workspaces: + - name: images-url + workspace: images-url + params: + - name: srcImageURL + value: docker://$(tasks.generate-image-name.results.image-name) + - name: destImageURL + value: docker://$(tasks.generate-image-name.results.image-name-timestamp) + runAfter: + - buildah-push + when: + - input: "quay" + operator: in + values: + - "$(tasks.generate-image-name.results.repository)" finally: - name: send-slack-notification taskRef: From 547e7f269ec5e81a3fc5bc04ed0044130e68d4d4 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 12:25:13 +0100 Subject: [PATCH 10/13] refactoring --- .tekton/create-ci-image-pipelinerun.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 5ba085cb..8c1ce9e5 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -157,7 +157,7 @@ spec: runAfter: - buildah-push when: - - input: "quay" + - input: "quay.io" operator: in values: - "$(tasks.generate-image-name.results.repository)" From b7cd4a07a439472f3a879521b5e25f3a93098518 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 12:42:05 +0100 Subject: [PATCH 11/13] add when expressions --- .tekton/create-ci-image-pipelinerun.yaml | 32 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 8c1ce9e5..256458b2 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -157,12 +157,34 @@ spec: runAfter: - buildah-push when: - - input: "quay.io" + - input: "image-registry" operator: in values: - "$(tasks.generate-image-name.results.repository)" finally: - - name: send-slack-notification + - name: send-slack-notification-request + taskRef: + resolver: cluster + params: + - name: kind + value: task + - name: name + value: send-slack-notification + - name: namespace + value: pipelines-ci + params: + - name: MESSAGE + value: " Uploading IS image ** <|logs>" + when: + - input: $(tasks.skopeo-copy-pull-request.status) + operator: in + values: ["Failed", "None"] + - input: "image-registry" + operator: in + values: + - "$(tasks.generate-image-name.results.repository)" + + - name: send-slack-notification-push taskRef: resolver: cluster params: @@ -176,9 +198,13 @@ spec: - name: MESSAGE value: " Uploading CI image ** <|logs>" when: - - input: $(tasks.skopeo-copy.status) + - input: $(tasks.skopeo-copy-push.status) operator: in values: ["Failed", "None"] + - input: "quay.io" + operator: in + values: + - "$(tasks.generate-image-name.results.repository)" workspaces: - name: dockerconfig From d53096908f103729038c9cdaf691e6485399f49f Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 12:47:34 +0100 Subject: [PATCH 12/13] refactoring --- .tekton/create-ci-image-pipelinerun.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 256458b2..145d0ae6 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -157,7 +157,7 @@ spec: runAfter: - buildah-push when: - - input: "image-registry" + - input: "quay.io" operator: in values: - "$(tasks.generate-image-name.results.repository)" From de6e7113303f1da0e583d62318717f56bb4759b3 Mon Sep 17 00:00:00 2001 From: Anton Misskii Date: Tue, 12 Mar 2024 13:27:47 +0100 Subject: [PATCH 13/13] test --- .tekton/create-ci-image-pipelinerun.yaml | 48 ++++++++++-------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/.tekton/create-ci-image-pipelinerun.yaml b/.tekton/create-ci-image-pipelinerun.yaml index 145d0ae6..b8ef426f 100644 --- a/.tekton/create-ci-image-pipelinerun.yaml +++ b/.tekton/create-ci-image-pipelinerun.yaml @@ -104,26 +104,7 @@ spec: operator: in values: - "$(tasks.generate-image-name.results.repository)" - - name: buildah-pull-request - taskRef: - kind: ClusterTask - name: buildah - params: - - name: IMAGE - value: $(tasks.generate-image-name.results.image-name) - - name: DOCKERFILE - value: ./Dockerfile.CI - runAfter: - - generate-image-name - workspaces: - - name: source - workspace: source - when: - - input: "image-registry" - operator: in - values: - - "$(tasks.generate-image-name.results.repository)" - - name: skopeo-copy-pull-request + - name: skopeo-copy-push taskRef: kind: ClusterTask name: skopeo-copy @@ -136,13 +117,27 @@ spec: - name: destImageURL value: docker://$(tasks.generate-image-name.results.image-name-timestamp) runAfter: - - buildah-pull-request + - buildah-push when: - - input: "image-registry" + - input: "quay.io" operator: in values: - "$(tasks.generate-image-name.results.repository)" - - name: skopeo-copy-push + - name: buildah-pull-request + taskRef: + kind: ClusterTask + name: buildah + params: + - name: IMAGE + value: $(tasks.generate-image-name.results.image-name) + - name: DOCKERFILE + value: ./Dockerfile.CI + runAfter: + - generate-image-name + workspaces: + - name: source + workspace: source + - name: skopeo-copy-pull-request taskRef: kind: ClusterTask name: skopeo-copy @@ -155,12 +150,7 @@ spec: - name: destImageURL value: docker://$(tasks.generate-image-name.results.image-name-timestamp) runAfter: - - buildah-push - when: - - input: "quay.io" - operator: in - values: - - "$(tasks.generate-image-name.results.repository)" + - buildah-pull-request finally: - name: send-slack-notification-request taskRef: