From b21ecf7451aa35dbe5492ceb2473ca82b04fd71e Mon Sep 17 00:00:00 2001 From: oleksandr_taruraiev Date: Thu, 14 Nov 2024 20:27:53 +0200 Subject: [PATCH] chore: Enable deployment env variables in CD pipelines(#360) --- .../templates/pipelines/cd-autotests/autotest.yaml | 4 ++++ .../templates/pipelines/cd/clean.yaml | 12 ++++++++++-- .../templates/pipelines/cd/deploy-ansible-awx.yaml | 12 ++++++++++++ .../templates/pipelines/cd/deploy-ansible.yaml | 8 ++++++++ .../templates/pipelines/cd/deploy-with-approve.yaml | 4 ++++ .../pipelines/cd/deploy-with-autotests.yaml | 8 ++++++++ .../templates/pipelines/cd/deploy.yaml | 8 ++++++++ .../tasks/autotest-cd-pipeline/init-autotests.yaml | 5 ++++- .../autotest-cd-pipeline/run-autotests-java.yaml | 7 +++++++ .../pipelines-library/templates/tasks/cd/clean.yaml | 3 +++ .../templates/tasks/cd/deploy-ansible-awx.yaml | 5 ++++- .../templates/tasks/cd/deploy-ansible.yaml | 3 +++ .../templates/tasks/{ => cd}/run-quality-gate.yaml | 13 +++++++++++++ .../tasks/cd/run-\321\201leanup-gate.yaml" | 13 +++++++++++++ 14 files changed, 101 insertions(+), 4 deletions(-) rename charts/pipelines-library/templates/tasks/{ => cd}/run-quality-gate.yaml (70%) rename "charts/pipelines-library/templates/tasks/run-\321\201leanup-gate.yaml" => "charts/pipelines-library/templates/tasks/cd/run-\321\201leanup-gate.yaml" (70%) diff --git a/charts/pipelines-library/templates/pipelines/cd-autotests/autotest.yaml b/charts/pipelines-library/templates/pipelines/cd-autotests/autotest.yaml index e7315515..8637ab16 100644 --- a/charts/pipelines-library/templates/pipelines/cd-autotests/autotest.yaml +++ b/charts/pipelines-library/templates/pipelines/cd-autotests/autotest.yaml @@ -21,6 +21,8 @@ spec: default: "master" - name: stage-name default: "dev" + - name: cd-pipeline-name + default: "dev" - name: base-image default: "" tasks: @@ -48,6 +50,8 @@ spec: params: - name: base-image value: "$(params.base-image)" + - name: cd-pipeline-name + value: "$(params.cd-pipeline-name)" - name: stage-name value: "$(params.stage-name)" workspaces: diff --git a/charts/pipelines-library/templates/pipelines/cd/clean.yaml b/charts/pipelines-library/templates/pipelines/cd/clean.yaml index 209d80cf..fa140e5f 100644 --- a/charts/pipelines-library/templates/pipelines/cd/clean.yaml +++ b/charts/pipelines-library/templates/pipelines/cd/clean.yaml @@ -29,10 +29,14 @@ spec: kind: Task name: run-clean-gate params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE - value: "bitnami/kubectl:1.25.4" + value: "{{ include "edp-tekton.registry" . }}/bitnami/kubectl:1.25.4" - name: EXTRA_COMMANDS value: echo "Hello World" @@ -56,10 +60,14 @@ spec: runAfter: - clean params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE - value: "bitnami/kubectl:1.25.4" + value: "{{ include "edp-tekton.registry" . }}/bitnami/kubectl:1.25.4" - name: EXTRA_COMMANDS value: echo "Hello World" diff --git a/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml b/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml index 01709287..fd0e21ea 100644 --- a/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml +++ b/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml @@ -35,6 +35,10 @@ spec: kind: Task name: run-quality-gate params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: BASE_IMAGE value: "{{ include "edp-tekton.registry" . }}/bitnami/kubectl:1.25.4" - name: EXTRA_COMMANDS @@ -62,6 +66,10 @@ spec: runAfter: - deploy-app params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: BASE_IMAGE value: "{{ include "edp-tekton.registry" . }}/bitnami/kubectl:1.25.4" - name: EXTRA_COMMANDS @@ -75,6 +83,10 @@ spec: runAfter: - post-deploy params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: APPLICATIONS_PAYLOAD value: $(params.APPLICATIONS_PAYLOAD) - name: CDPIPELINE_STAGE diff --git a/charts/pipelines-library/templates/pipelines/cd/deploy-ansible.yaml b/charts/pipelines-library/templates/pipelines/cd/deploy-ansible.yaml index c9f6ca0c..5555224b 100644 --- a/charts/pipelines-library/templates/pipelines/cd/deploy-ansible.yaml +++ b/charts/pipelines-library/templates/pipelines/cd/deploy-ansible.yaml @@ -31,6 +31,10 @@ spec: kind: Task name: run-quality-gate params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: BASE_IMAGE value: "{{ include "edp-tekton.registry" . }}/bitnami/kubectl:1.25.4" - name: EXTRA_COMMANDS @@ -58,6 +62,10 @@ spec: runAfter: - deploy-app params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: BASE_IMAGE value: "{{ include "edp-tekton.registry" . }}/bitnami/kubectl:1.25.4" - name: EXTRA_COMMANDS diff --git a/charts/pipelines-library/templates/pipelines/cd/deploy-with-approve.yaml b/charts/pipelines-library/templates/pipelines/cd/deploy-with-approve.yaml index 8aab86cf..af751371 100644 --- a/charts/pipelines-library/templates/pipelines/cd/deploy-with-approve.yaml +++ b/charts/pipelines-library/templates/pipelines/cd/deploy-with-approve.yaml @@ -36,6 +36,10 @@ spec: kind: Task name: run-quality-gate params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE diff --git a/charts/pipelines-library/templates/pipelines/cd/deploy-with-autotests.yaml b/charts/pipelines-library/templates/pipelines/cd/deploy-with-autotests.yaml index 1d31ed63..fa907469 100644 --- a/charts/pipelines-library/templates/pipelines/cd/deploy-with-autotests.yaml +++ b/charts/pipelines-library/templates/pipelines/cd/deploy-with-autotests.yaml @@ -42,6 +42,10 @@ spec: kind: Task name: run-quality-gate params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE @@ -71,6 +75,10 @@ spec: runAfter: - deploy-app params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE diff --git a/charts/pipelines-library/templates/pipelines/cd/deploy.yaml b/charts/pipelines-library/templates/pipelines/cd/deploy.yaml index bae2058d..d229908a 100644 --- a/charts/pipelines-library/templates/pipelines/cd/deploy.yaml +++ b/charts/pipelines-library/templates/pipelines/cd/deploy.yaml @@ -34,6 +34,10 @@ spec: kind: Task name: run-quality-gate params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE @@ -63,6 +67,10 @@ spec: runAfter: - deploy-app params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) - name: KUBECONFIG_SECRET_NAME value: $(params.KUBECONFIG_SECRET_NAME) - name: BASE_IMAGE diff --git a/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/init-autotests.yaml b/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/init-autotests.yaml index 49b54e0d..ac2c0cd5 100644 --- a/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/init-autotests.yaml +++ b/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/init-autotests.yaml @@ -46,7 +46,9 @@ spec: value: $(params.cd-pipeline-name) - name: PARENT_PIPELINE_NAME value: $(params.parent-pipeline-name) - + envFrom: + - configMapRef: + name: $(params.cd-pipeline-name)-$(params.stage-name) script: | #!/usr/bin/env python @@ -103,6 +105,7 @@ spec: -p git-source-url=" + gitAutotesUrl[count] + " \ -p git-source-revision=" + autotestsBranch[count] + " \ -p stage-name=" + stage +" \ + -p cd-pipeline-name=" + cdPipelineName +" \ -p base-image=" + frameworks[autotestBuildTool[count] + "-" + autotestFramework[count]] + " \ --labels app.edp.epam.com/pipeline=" + cdPipelineName + " \ --labels app.edp.epam.com/stage=" + stage + " \ diff --git a/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/run-autotests-java.yaml b/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/run-autotests-java.yaml index 057cef13..2d064d5b 100644 --- a/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/run-autotests-java.yaml +++ b/charts/pipelines-library/templates/tasks/autotest-cd-pipeline/run-autotests-java.yaml @@ -19,6 +19,8 @@ spec: - name: source description: A workspace that contains the repository. params: + - name: cd-pipeline-name + type: string - name: stage-name type: string - name: base-image @@ -30,6 +32,11 @@ spec: env: - name: STAGE_NAME value: $(params.stage-name) + - name: CD_PIPELINE_NAME + value: $(params.cd-pipeline-name) + envFrom: + - configMapRef: + name: $(params.cd-pipeline-name)-$(params.stage-name) script: | #!/bin/bash diff --git a/charts/pipelines-library/templates/tasks/cd/clean.yaml b/charts/pipelines-library/templates/tasks/cd/clean.yaml index 831ce75b..9339f90e 100644 --- a/charts/pipelines-library/templates/tasks/cd/clean.yaml +++ b/charts/pipelines-library/templates/tasks/cd/clean.yaml @@ -29,6 +29,9 @@ spec: secretKeyRef: name: ci-argocd key: token + envFrom: + - configMapRef: + name: $(params.PIPELINE)-$(params.STAGE) script: | set -ex diff --git a/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml b/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml index 7f303f90..af23387e 100644 --- a/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml +++ b/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml @@ -49,12 +49,15 @@ spec: secretKeyRef: name: ci-awx key: password + envFrom: + - configMapRef: + name: $(params.PIPELINE)-$(params.STAGE) script: | #!/usr/bin/env sh set -eu tower-cli config host ${AWX_HOST} - tower-cli config username ${AWX_USERNAME} + tower-cli config username ${AWX_USERNAME} tower-cli config password ${AWX_PASSWORD} tower-cli config verify_ssl false diff --git a/charts/pipelines-library/templates/tasks/cd/deploy-ansible.yaml b/charts/pipelines-library/templates/tasks/cd/deploy-ansible.yaml index 5b86ab60..6c4f7624 100644 --- a/charts/pipelines-library/templates/tasks/cd/deploy-ansible.yaml +++ b/charts/pipelines-library/templates/tasks/cd/deploy-ansible.yaml @@ -44,6 +44,9 @@ spec: secretKeyRef: name: ci-nexus key: password + envFrom: + - configMapRef: + name: $(params.PIPELINE)-$(params.STAGE) script: | #!/usr/bin/env python import os diff --git a/charts/pipelines-library/templates/tasks/run-quality-gate.yaml b/charts/pipelines-library/templates/tasks/cd/run-quality-gate.yaml similarity index 70% rename from charts/pipelines-library/templates/tasks/run-quality-gate.yaml rename to charts/pipelines-library/templates/tasks/cd/run-quality-gate.yaml index 57839228..f50edaed 100644 --- a/charts/pipelines-library/templates/tasks/run-quality-gate.yaml +++ b/charts/pipelines-library/templates/tasks/cd/run-quality-gate.yaml @@ -11,6 +11,16 @@ spec: secretName: $(params.KUBECONFIG_SECRET_NAME) optional: true params: + - description: > + EDP kind:CDPipeline name used for deployment. For example: mypipe, + myfeature + name: PIPELINE + type: string + - description: > + EDP kind:Stage name of the kind:CDPipeline defined in the CDPIPELINE + values. For example: dev, test, prod + name: STAGE + type: string - name: BASE_IMAGE description: The base image for the task (different for buildtools). type: string @@ -29,6 +39,9 @@ spec: volumeMounts: - name: kubeconfig mountPath: /workspace/source/kube + envFrom: + - configMapRef: + name: $(params.PIPELINE)-$(params.STAGE) script: | set -ex export KUBECONFIG="workspace/source/kube/config" diff --git "a/charts/pipelines-library/templates/tasks/run-\321\201leanup-gate.yaml" "b/charts/pipelines-library/templates/tasks/cd/run-\321\201leanup-gate.yaml" similarity index 70% rename from "charts/pipelines-library/templates/tasks/run-\321\201leanup-gate.yaml" rename to "charts/pipelines-library/templates/tasks/cd/run-\321\201leanup-gate.yaml" index 7be9f1a1..ed4f1355 100644 --- "a/charts/pipelines-library/templates/tasks/run-\321\201leanup-gate.yaml" +++ "b/charts/pipelines-library/templates/tasks/cd/run-\321\201leanup-gate.yaml" @@ -11,6 +11,16 @@ spec: secretName: $(params.KUBECONFIG_SECRET_NAME) optional: true params: + - description: > + EDP kind:CDPipeline name used for deployment. For example: mypipe, + myfeature + name: PIPELINE + type: string + - description: > + EDP kind:Stage name of the kind:CDPipeline defined in the CDPIPELINE + values. For example: dev, test, prod + name: STAGE + type: string - name: BASE_IMAGE description: The base image for the task (different for buildtools). type: string @@ -29,6 +39,9 @@ spec: volumeMounts: - name: kubeconfig mountPath: /workspace/source/kube + envFrom: + - configMapRef: + name: $(params.PIPELINE)-$(params.STAGE) script: | set -ex export KUBECONFIG="workspace/source/kube/config"