From d515fec4ef5fe5e33b802bfe8a6b2c5d6c118b96 Mon Sep 17 00:00:00 2001 From: Mykola Serdiuk Date: Wed, 18 Oct 2023 18:32:55 +0300 Subject: [PATCH] chore: Align helm tasks and pipelines for new config approach (#47) * Update helm tasks * Update parameter definition * Update default versioning for helm tasks Change-Id: Ic5f1fac20fe3935502fbf6f587325e56d159f82a --- .../gerrit-build-lib-default.yaml | 4 +- .../github-build-lib-default.yaml | 4 +- .../gitlab-build-lib-default.yaml | 4 +- .../pipelines/helm/gerrit-build-default.yaml | 12 +- .../pipelines/helm/gerrit-build-edp.yaml | 8 +- .../helm/gerrit-build-lib-default.yaml | 12 +- .../pipelines/helm/gerrit-build-lib-edp.yaml | 6 +- .../pipelines/helm/github-build-default.yaml | 12 +- .../pipelines/helm/github-build-edp.yaml | 8 +- .../helm/github-build-lib-default.yaml | 12 +- .../pipelines/helm/github-build-lib-edp.yaml | 6 +- .../pipelines/helm/gitlab-build-default.yaml | 14 +-- .../pipelines/helm/gitlab-build-edp.yaml | 8 +- .../helm/gitlab-build-lib-default.yaml | 10 +- .../pipelines/helm/gitlab-build-lib-edp.yaml | 6 +- .../defaulttype/GetVersionHelm.yaml | 47 ++++++++ .../tasks/helm-libraries/helm-push-lib.yaml | 53 +++++--- .../helm-libraries/helm-push-to-ecr-lib.yaml | 113 ------------------ .../templates/tasks/helm-push-to-ecr.yaml | 100 ---------------- .../templates/tasks/helm-push.yaml | 64 +++++++--- 20 files changed, 175 insertions(+), 328 deletions(-) create mode 100644 charts/pipelines-library/templates/tasks/getversion/defaulttype/GetVersionHelm.yaml delete mode 100644 charts/pipelines-library/templates/tasks/helm-libraries/helm-push-to-ecr-lib.yaml delete mode 100644 charts/pipelines-library/templates/tasks/helm-push-to-ecr.yaml diff --git a/charts/pipelines-library/templates/pipelines/helm-pipelines/gerrit-build-lib-default.yaml b/charts/pipelines-library/templates/pipelines/helm-pipelines/gerrit-build-lib-default.yaml index 3990707d..dea2fe14 100644 --- a/charts/pipelines-library/templates/pipelines/helm-pipelines/gerrit-build-lib-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm-pipelines/gerrit-build-lib-default.yaml @@ -83,11 +83,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - gerrit-notify params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) diff --git a/charts/pipelines-library/templates/pipelines/helm-pipelines/github-build-lib-default.yaml b/charts/pipelines-library/templates/pipelines/helm-pipelines/github-build-lib-default.yaml index ec28db7c..7dbad684 100644 --- a/charts/pipelines-library/templates/pipelines/helm-pipelines/github-build-lib-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm-pipelines/github-build-lib-default.yaml @@ -65,11 +65,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - fetch-repository params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) diff --git a/charts/pipelines-library/templates/pipelines/helm-pipelines/gitlab-build-lib-default.yaml b/charts/pipelines-library/templates/pipelines/helm-pipelines/gitlab-build-lib-default.yaml index 1e382e0f..3bf36915 100644 --- a/charts/pipelines-library/templates/pipelines/helm-pipelines/gitlab-build-lib-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm-pipelines/gitlab-build-lib-default.yaml @@ -65,11 +65,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - fetch-repository params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) diff --git a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-default.yaml b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-default.yaml index c90d5854..af0742c1 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-default.yaml @@ -52,11 +52,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - init-values params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) @@ -114,12 +114,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: image-tag + value: "$(tasks.get-version.results.IS_TAG)" + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-edp.yaml b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-edp.yaml index 3512d47c..b44d16af 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-edp.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-edp.yaml @@ -127,12 +127,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: image-tag + value: "$(tasks.get-version.results.IS_TAG)" + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-default.yaml b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-default.yaml index 71899a55..575a4dfb 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-default.yaml @@ -52,11 +52,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - init-values params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) @@ -73,12 +73,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR - value: $(params.CHART_DIR) - - name: IS_TAG + - name: image-tag value: $(tasks.get-version.results.VERSION) + - name: chart-dir + value: $(params.CHART_DIR) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-edp.yaml b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-edp.yaml index f0e3e45f..0aa0b111 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-edp.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gerrit-build-lib-edp.yaml @@ -71,12 +71,8 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/github-build-default.yaml b/charts/pipelines-library/templates/pipelines/helm/github-build-default.yaml index 61ff09e3..7b840c1b 100644 --- a/charts/pipelines-library/templates/pipelines/helm/github-build-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/github-build-default.yaml @@ -52,12 +52,10 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - init-values params: - - name: CHART_DIR - value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) workspaces: @@ -114,12 +112,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: image-tag + value: "$(tasks.get-version.results.IS_TAG)" + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/github-build-edp.yaml b/charts/pipelines-library/templates/pipelines/helm/github-build-edp.yaml index eac8dc13..3f220229 100644 --- a/charts/pipelines-library/templates/pipelines/helm/github-build-edp.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/github-build-edp.yaml @@ -127,12 +127,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: image-tag + value: "$(tasks.get-version.results.IS_TAG)" + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/github-build-lib-default.yaml b/charts/pipelines-library/templates/pipelines/helm/github-build-lib-default.yaml index f88c9fbe..426f4acc 100644 --- a/charts/pipelines-library/templates/pipelines/helm/github-build-lib-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/github-build-lib-default.yaml @@ -52,11 +52,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - init-values params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) @@ -73,12 +73,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR - value: $(params.CHART_DIR) - - name: IS_TAG + - name: image-tag value: $(tasks.get-version.results.VERSION) + - name: chart-dir + value: $(params.CHART_DIR) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/github-build-lib-edp.yaml b/charts/pipelines-library/templates/pipelines/helm/github-build-lib-edp.yaml index 4f986540..3f9fe39c 100644 --- a/charts/pipelines-library/templates/pipelines/helm/github-build-lib-edp.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/github-build-lib-edp.yaml @@ -71,12 +71,8 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-default.yaml b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-default.yaml index c25b732d..f837dca4 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-default.yaml @@ -52,11 +52,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - init-values params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) @@ -99,8 +99,6 @@ spec: runAfter: - helm-lint params: - - name: CHART_DIR - value: $(params.CHART_DIR) - name: release_name value: $(params.CODEBASE_NAME) workspaces: @@ -114,12 +112,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: image-tag + value: "$(tasks.get-version.results.IS_TAG)" + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-edp.yaml b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-edp.yaml index 535e71b2..635aaf37 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-edp.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-edp.yaml @@ -127,12 +127,10 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: image-tag + value: "$(tasks.get-version.results.IS_TAG)" + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-default.yaml b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-default.yaml index 06f86261..df7af344 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-default.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-default.yaml @@ -52,11 +52,11 @@ spec: - name: get-version taskRef: kind: Task - name: get-version-default + name: get-version-helm-default runAfter: - init-values params: - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - name: BRANCH_NAME value: $(params.git-source-revision) @@ -73,12 +73,8 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-edp.yaml b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-edp.yaml index 16baeb58..915d9ea0 100644 --- a/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-edp.yaml +++ b/charts/pipelines-library/templates/pipelines/helm/gitlab-build-lib-edp.yaml @@ -71,12 +71,8 @@ spec: runAfter: - helm-template params: - - name: TENANT_NAME - value: $(tasks.init-values.results.TENANT_NAME) - - name: CHART_DIR + - name: chart-dir value: $(params.CHART_DIR) - - name: IS_TAG - value: $(tasks.get-version.results.VERSION) workspaces: - name: source workspace: shared-workspace diff --git a/charts/pipelines-library/templates/tasks/getversion/defaulttype/GetVersionHelm.yaml b/charts/pipelines-library/templates/tasks/getversion/defaulttype/GetVersionHelm.yaml new file mode 100644 index 00000000..1a9296a1 --- /dev/null +++ b/charts/pipelines-library/templates/tasks/getversion/defaulttype/GetVersionHelm.yaml @@ -0,0 +1,47 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: get-version-helm-default +spec: + description: + workspaces: + - name: source + description: The workspace consisting of csharp project. + params: + - name: BRANCH_NAME + type: string + description: Codebasebranch name + - name: chart-dir + type: string + results: + - name: VERSION + description: "Application version" + - name: VCS_TAG + description: "VCS tag" + - name: IS_TAG + description: "CodebaseImageStream tag" + steps: + - name: get-version + image: linuxserver/yq + env: + - name: BRANCH_NAME + value: "$(params.BRANCH_NAME)" + - name: CHART_DIR + value: "$(params.chart-dir)" + workingDir: $(workspaces.source.path) + script: | + set -e + + BUILD_VERSION=$(grep -m 1 -oE 'version:[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)*' ${CHART_DIR}/Chart.yaml | awk '{print $2}') + BUILD_VERSION=$(cat ${CHART_DIR}/Chart.yaml | yq -r ".version") + + VCS_TAG="${BRANCH_NAME}-${BUILD_VERSION}" + IS_TAG="${BUILD_VERSION}" + + echo "VCS tag - ${VCS_TAG}" + echo "IS tag - ${IS_TAG}" + echo "VERSION tag - ${BUILD_VERSION}" + + printf "%s" "${VCS_TAG}" > "$(results.VCS_TAG.path)" + printf "%s" "${BUILD_VERSION}" > "$(results.VERSION.path)" + printf "%s" "${IS_TAG}" > "$(results.IS_TAG.path)" diff --git a/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-lib.yaml b/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-lib.yaml index 23859b7b..b7ad2a4c 100644 --- a/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-lib.yaml +++ b/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-lib.yaml @@ -1,4 +1,3 @@ -{{ if eq .Values.global.dockerRegistry.type "harbor" "dockerhub"}} apiVersion: tekton.dev/v1beta1 kind: Task metadata: @@ -19,26 +18,51 @@ spec: path: config.json optional: true params: - - name: IS_TAG - type: string - description: "Chart version" - - name: CHART_DIR + - name: chart-dir description: The directory in source that contains the helm chart default: "." - - name: registry-url - description: Helm registry url - default: "{{ .Values.global.dockerRegistry.url }}" steps: + - name: init-repository + image: amazon/aws-cli:2.7.35 + env: + - name: AWS_DEFAULT_REGION + valueFrom: + configMapKeyRef: + name: edp-config + key: aws_region + - name: CONTAINER_REGISTRY_GROUP + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_space + - name: CONTAINER_REGISTRY_TYPE + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_type + script: | + if [[ "$CONTAINER_REGISTRY_TYPE" == "ecr" ]]; then + aws ecr describe-repositories --repository-names "${CONTAINER_REGISTRY_GROUP}/${CODEBASE_NAME}" || aws ecr create-repository --repository-name "${CONTAINER_REGISTRY_GROUP}/${CODEBASE_NAME}"; + else + echo 'Registry not ECR, stage skipped'; + fi + - name: push-helm-chart image: alpine/k8s:1.23.17 workingDir: $(workspaces.source.path) env: - name: CHART_DIR - value: $(params.CHART_DIR) - - name: IS_TAG - value: $(params.IS_TAG) - - name: REGISTRY_URL - value: $(params.registry-url) + value: $(params.chart-dir) + - name: CONTAINER_REGISTRY_URL + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_host + - name: CONTAINER_REGISTRY_SPACE + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_space script: | #!/bin/bash set -ex @@ -48,7 +72,7 @@ spec: do if ! git diff --quiet HEAD^ HEAD -- $i; then helm package ${i} - helm push *-*.tgz oci://${REGISTRY_URL} --registry-config /.config/helm/registry/config.json + helm push *-*.tgz oci://${CONTAINER_REGISTRY_URL}/${CONTAINER_REGISTRY_SPACE} --registry-config /.config/helm/registry/config.json rm *-*.tgz fi done @@ -62,4 +86,3 @@ spec: - mountPath: /.config/helm/registry name: dockerconfig {{- include "resources" . | nindent 6 }} -{{ end }} diff --git a/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-to-ecr-lib.yaml b/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-to-ecr-lib.yaml deleted file mode 100644 index a04176fb..00000000 --- a/charts/pipelines-library/templates/tasks/helm-libraries/helm-push-to-ecr-lib.yaml +++ /dev/null @@ -1,113 +0,0 @@ -{{ if eq .Values.global.dockerRegistry.type "ecr" }} -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: helm-push-lib -spec: - description: | - This Task allows Uset to push a new version of the Helm Chart - to the repository with Snapshot versions. - workspaces: - - name: source - description: A workspace that contains the repository. - {{ if eq .Values.global.platform "openshift" }} - volumes: - - name: edp-tekton-helm-push-volume - secret: - secretName: edp-tekton-helm-push - {{ end }} - params: - - name: IS_TAG - type: string - description: "Chart version" - - name: CHART_DIR - description: The directory in source that contains the helm chart - default: "." - - name: edp-config - type: string - description: "This configmap holds aws_region and docker registry url parameters" - default: edp-config - - name: registry-url - description: Helm registry url - default: "{{ .Values.global.dockerRegistry.url }}" - steps: - - name: init-repository - image: amazon/aws-cli:2.7.35 - resources: {} - {{ if ne .Values.global.platform "openshift" }} - workingDir: $(workspaces.source.path) - env: - - name: CHART_DIR - value: $(params.CHART_DIR) - - name: REGISTRY_URL - value: $(params.registry-url) - - name: AWS_DEFAULT_REGION - valueFrom: - configMapKeyRef: - name: "$(params.edp-config)" - key: 'aws_region' - script: | - #!/bin/bash - set -ex - - chart_directory=(${CHART_DIR}/*) - for i in "${chart_directory[@]}" - do - REPO_NAME=$(awk '/^name:/ {print $2}' ${i}/Chart.yaml) - ECR_REPO_NAME=$(echo "${REGISTRY_URL}" | cut -d'/' -f2-) - aws ecr describe-repositories --region ${AWS_DEFAULT_REGION} --repository-names ${ECR_REPO_NAME}/${REPO_NAME} \ - || aws ecr create-repository --region ${AWS_DEFAULT_REGION} --repository-name ${ECR_REPO_NAME}/${REPO_NAME} - done - {{ else }} - command: [ "/bin/sh" ] - args: [ "-c", "echo 'Openshift cluster, create-ecr-repository stage skipped'" ] - {{ end }} - - - name: push-to-ecr - image: alpine/k8s:1.23.17 - workingDir: $(workspaces.source.path) - env: - - name: CHART_DIR - value: $(params.CHART_DIR) - - name: IS_TAG - value: $(params.IS_TAG) - - name: AWS_DEFAULT_REGION - valueFrom: - configMapKeyRef: - name: "$(params.edp-config)" - key: 'aws_region' - - name: REGISTRY_URL - value: $(params.registry-url) - script: | - #!/bin/bash - set -ex - - {{ if ne .Values.global.platform "openshift" }} - aws ecr get-login-password --region ${AWS_DEFAULT_REGION} \ - | helm registry login --username AWS --password-stdin ${REGISTRY_URL} - {{ else }} - update-ca-certificates - {{ end }} - - chart_directory=(${CHART_DIR}/*) - for i in "${chart_directory[@]}" - do - if ! git diff --quiet HEAD^ HEAD -- $i; then - helm package ${i} - helm push *-*.tgz oci://${REGISTRY_URL} - rm *-*.tgz - fi - done - - {{ if eq .Values.global.platform "openshift" }} - # Adding this securityContext makes it explicit that it needs to run as root. - # Required for Openshift. - securityContext: - runAsUser: 0 - # This secret mount is necessary for helm push to internal openshift registry - volumeMounts: - - name: edp-tekton-helm-push-volume - mountPath: /usr/local/share/ca-certificates/ - {{ end }} -{{- include "resources" . | nindent 6 }} -{{ end }} diff --git a/charts/pipelines-library/templates/tasks/helm-push-to-ecr.yaml b/charts/pipelines-library/templates/tasks/helm-push-to-ecr.yaml deleted file mode 100644 index c044cfcc..00000000 --- a/charts/pipelines-library/templates/tasks/helm-push-to-ecr.yaml +++ /dev/null @@ -1,100 +0,0 @@ -{{ if eq .Values.global.dockerRegistry.type "ecr" }} -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: helm-push -spec: - description: | - This Task allows Uset to push a new version of the Helm Chart - to the repository with Snapshot versions. - workspaces: - - name: source - description: A workspace that contains the repository. - {{ if eq .Values.global.platform "openshift" }} - volumes: - - name: edp-tekton-helm-push-volume - secret: - secretName: edp-tekton-helm-push - {{ end }} - params: - - name: IS_TAG - type: string - description: "Chart version" - - name: CHART_DIR - description: The directory in source that contains the helm chart - default: "." - - name: edp-config - type: string - description: "This configmap holds aws_region and docker registry url parameters" - default: edp-config - - name: registry-url - description: Helm registry url - default: "{{ .Values.global.dockerRegistry.url }}" - steps: - - name: init-repository - image: amazon/aws-cli:2.7.35 - resources: {} - {{ if ne .Values.global.platform "openshift" }} - workingDir: $(workspaces.source.path) - env: - - name: CHART_DIR - value: $(params.CHART_DIR) - - name: REGISTRY_URL - value: $(params.registry-url) - - name: AWS_DEFAULT_REGION - valueFrom: - configMapKeyRef: - name: "$(params.edp-config)" - key: 'aws_region' - script: | - set -ex - ECR_REPO_NAME=$(echo "${REGISTRY_URL}" | cut -d'/' -f2-) - REPO_NAME=$(awk '/^name:/ {print $2}' ${CHART_DIR}/Chart.yaml) - aws ecr describe-repositories --region ${AWS_DEFAULT_REGION} --repository-names ${ECR_REPO_NAME}/${REPO_NAME} \ - || aws ecr create-repository --region ${AWS_DEFAULT_REGION} --repository-name ${ECR_REPO_NAME}/${REPO_NAME} - {{ else }} - command: [ "/bin/sh" ] - args: [ "-c", "echo 'Openshift cluster, create-ecr-repository stage skipped'" ] - {{ end }} - - - name: push-to-ecr - image: alpine/k8s:1.23.17 - workingDir: $(workspaces.source.path) - env: - - name: CHART_DIR - value: $(params.CHART_DIR) - - name: IS_TAG - value: $(params.IS_TAG) - - name: AWS_DEFAULT_REGION - valueFrom: - configMapKeyRef: - name: "$(params.edp-config)" - key: 'aws_region' - - name: REGISTRY_URL - value: $(params.registry-url) - script: | - set -ex - ECR_REPO_NAME=$(echo "${REGISTRY_URL}" | cut -d'/' -f2-); - helm package ${CHART_DIR} --version ${IS_TAG} - - {{ if ne .Values.global.platform "openshift" }} - aws ecr get-login-password --region ${AWS_DEFAULT_REGION} \ - | helm registry login --username AWS --password-stdin ${REGISTRY_URL} - {{ else }} - update-ca-certificates - {{ end }} - - helm push *-${IS_TAG}.tgz oci://${REGISTRY_URL} - - {{ if eq .Values.global.platform "openshift" }} - # Adding this securityContext makes it explicit that it needs to run as root. - # Required for Openshift. - securityContext: - runAsUser: 0 - # This secret mount is necessary for helm push to internal openshift registry - volumeMounts: - - name: edp-tekton-helm-push-volume - mountPath: /usr/local/share/ca-certificates/ - {{ end }} -{{- include "resources" . | nindent 6 }} -{{ end }} diff --git a/charts/pipelines-library/templates/tasks/helm-push.yaml b/charts/pipelines-library/templates/tasks/helm-push.yaml index defb1560..51246de1 100644 --- a/charts/pipelines-library/templates/tasks/helm-push.yaml +++ b/charts/pipelines-library/templates/tasks/helm-push.yaml @@ -1,4 +1,3 @@ -{{ if eq .Values.global.dockerRegistry.type "harbor" "dockerhub"}} apiVersion: tekton.dev/v1beta1 kind: Task metadata: @@ -19,35 +18,63 @@ spec: path: config.json optional: true params: - - name: TENANT_NAME - type: string - description: "Tenant namespace" - - name: IS_TAG - type: string - description: "Chart version" - - name: CHART_DIR + - name: image-tag + description: Image tag + - name: chart-dir description: The directory in source that contains the helm chart default: "." - - name: registry-url - description: Helm registry url - default: "{{ .Values.global.dockerRegistry.url }}" steps: + - name: init-repository + image: amazon/aws-cli:2.7.35 + env: + - name: AWS_DEFAULT_REGION + valueFrom: + configMapKeyRef: + name: edp-config + key: aws_region + - name: CONTAINER_REGISTRY_GROUP + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_space + - name: CONTAINER_REGISTRY_TYPE + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_type + script: | + if [[ "$CONTAINER_REGISTRY_TYPE" == "ecr" ]]; then + aws ecr describe-repositories --repository-names "${CONTAINER_REGISTRY_GROUP}/${CODEBASE_NAME}" || aws ecr create-repository --repository-name "${CONTAINER_REGISTRY_GROUP}/${CODEBASE_NAME}"; + else + echo 'Registry not ECR, stage skipped'; + fi + - name: push-helm-chart image: alpine/k8s:1.23.17 workingDir: $(workspaces.source.path) env: + - name: IMAGE_TAG + value: "$(params.image-tag)" - name: CHART_DIR - value: $(params.CHART_DIR) - - name: IS_TAG - value: $(params.IS_TAG) - - name: REGISTRY_URL - value: $(params.registry-url) + value: $(params.chart-dir) + - name: CONTAINER_REGISTRY_URL + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_host + - name: CONTAINER_REGISTRY_SPACE + valueFrom: + configMapKeyRef: + name: edp-config + key: container_registry_space script: | + #!/bin/bash + set -ex - helm package ${CHART_DIR} --version ${IS_TAG} + helm package ${CHART_DIR} --version ${IMAGE_TAG} - helm push *-${IS_TAG}.tgz oci://${REGISTRY_URL} --registry-config /.config/helm/registry/config.json + helm push *-${IMAGE_TAG}.tgz oci://${CONTAINER_REGISTRY_URL}/${CONTAINER_REGISTRY_SPACE} --registry-config /.config/helm/registry/config.json # Adding this securityContext makes it explicit that it needs to run as root. # Required for Openshift. @@ -58,4 +85,3 @@ spec: - mountPath: /.config/helm/registry name: dockerconfig {{- include "resources" . | nindent 6 }} -{{ end }}