From 58f1e11a599aab504dadf76dbf459febb78805ec Mon Sep 17 00:00:00 2001 From: Daniil Nedostup Date: Tue, 27 Aug 2024 22:33:44 +0300 Subject: [PATCH] feat: Add Tekton resources for deploy RPM Package via AWX (#277) --- .../pipelines/cd/deploy-ansible-awx.yaml | 83 +++++++++++++++++++ .../tasks/cd/deploy-ansible-awx.yaml | 63 ++++++++++++++ .../triggers/cd/deploy-ansible-awx.yaml | 38 +++++++++ 3 files changed, 184 insertions(+) create mode 100644 charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml create mode 100644 charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml create mode 100644 charts/pipelines-library/templates/triggers/cd/deploy-ansible-awx.yaml diff --git a/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml b/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml new file mode 100644 index 00000000..0c73b2aa --- /dev/null +++ b/charts/pipelines-library/templates/pipelines/cd/deploy-ansible-awx.yaml @@ -0,0 +1,83 @@ +apiVersion: tekton.dev/v1 +kind: Pipeline +metadata: + name: deploy-ansible-awx + labels: + app.edp.epam.com/pipelinetype: deploy +spec: + description: | + This Pipeline is designed for deploying RPM packages + to target servers (environments) using tower-cli tool. It automates + the deployment process by invoking Ansible AWX through the command line, + ensuring a streamlined and consistent installation of RPM packages across + the specified environment. + params: + - name: pipelineUrl + description: | + URL of the pipeline run in Tekton Dashboard. + type: string + default: https://portal-{{ .Release.Namespace }}.{{ .Values.global.dnsWildCard }}/c/main/pipelines/$(context.pipelineRun.namespace)/$(context.pipelineRun.name) + - name: CDPIPELINE + description: | + EDP kind:CDPipeline name used for deployment. For example: mypipe, myfeature + type: string + - name: CDSTAGE + description: | + EDP kind:Stage name of the kind:CDPipeline defined in the CDPIPELINE values. For example: dev, test, prod + type: string + - name: APPLICATIONS_PAYLOAD + description: | + Applications payload in format: {"codebase1": {"imageTag": "version1", "customValues": true}, "codebase2": {"imageTag": "version2", "customValues": true}}. For example: {"demo": {"imageTag": "main-20240103-141431", "customValues": true}, "myapp": {"imageTag": "0.1.0-SNAPSHOT.1", "customValues": true}} + type: string + tasks: + - name: pre-deploy + taskRef: + kind: Task + name: run-quality-gate + params: + - name: BASE_IMAGE + value: "bitnami/kubectl:1.25.4" + - name: EXTRA_COMMANDS + value: + echo "Hello World" + + - name: deploy-app + taskRef: + kind: Task + name: deploy-ansible-awx + runAfter: + - pre-deploy + params: + - name: PIPELINE + value: $(params.CDPIPELINE) + - name: STAGE + value: $(params.CDSTAGE) + - name: APPLICATIONS_PAYLOAD + value: $(params.APPLICATIONS_PAYLOAD) + + - name: post-deploy + taskRef: + kind: Task + name: run-quality-gate + runAfter: + - deploy-app + params: + - name: BASE_IMAGE + value: "bitnami/kubectl:1.25.4" + - name: EXTRA_COMMANDS + value: + echo "Hello World" + + - name: promote-images + taskRef: + kind: Task + name: promote-images + runAfter: + - post-deploy + params: + - name: APPLICATIONS_PAYLOAD + value: $(params.APPLICATIONS_PAYLOAD) + - name: CDPIPELINE_STAGE + value: $(params.CDSTAGE) + - name: CDPIPELINE_CR + value: $(params.CDPIPELINE) diff --git a/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml b/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml new file mode 100644 index 00000000..4c0c945b --- /dev/null +++ b/charts/pipelines-library/templates/tasks/cd/deploy-ansible-awx.yaml @@ -0,0 +1,63 @@ +apiVersion: tekton.dev/v1 +kind: Task +metadata: + name: deploy-ansible-awx +spec: + description: > + This Task is designed to configure the tower-cli tool and invoke + an Ansible AWX Template that runs an Ansible Playbook for installing + RPM packages on target servers. + params: + - description: > + Applications payload in format: {"codebase1": {"imageTag": "version1", + "customValues": true}, "codebase2": {"imageTag": "version2", + "customValues": true}}. + name: APPLICATIONS_PAYLOAD + type: string + - 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 + steps: + - name: deploy-ansible-awx + image: epamedp/tekton-ansible:0.1.1 + env: + - name: APPLICATIONS_PAYLOAD + value: $(params.APPLICATIONS_PAYLOAD) + - name: PIPELINE + value: $(params.PIPELINE) + - name: STAGE + value: $(params.STAGE) + - name: AWX_HOST + valueFrom: + secretKeyRef: + name: ci-awx + key: url + - name: AWX_USERNAME + valueFrom: + secretKeyRef: + name: ci-awx + key: username + - name: AWX_PASSWORD + valueFrom: + secretKeyRef: + name: ci-awx + key: password + script: | + #!/usr/bin/env sh + + set -eu + tower-cli config host ${AWX_HOST} + tower-cli config username ${AWX_USERNAME} + tower-cli config password ${AWX_PASSWORD} + tower-cli config verify_ssl false + + tower-cli job launch --job-template=package-install \ + --extra-vars="{\"APPLICATIONS_PAYLOAD\":${APPLICATIONS_PAYLOAD},\"STAGE\":\"${STAGE}\",\"PIPELINE\":\"${PIPELINE}\"}" \ + --inventory=${PIPELINE} --wait --limit=${PIPELINE}_${STAGE} diff --git a/charts/pipelines-library/templates/triggers/cd/deploy-ansible-awx.yaml b/charts/pipelines-library/templates/triggers/cd/deploy-ansible-awx.yaml new file mode 100644 index 00000000..19ea3c6a --- /dev/null +++ b/charts/pipelines-library/templates/triggers/cd/deploy-ansible-awx.yaml @@ -0,0 +1,38 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: deploy-ansible-awx + labels: + app.edp.epam.com/pipelinetype: deploy +spec: + params: + - name: APPLICATIONS_PAYLOAD + description: | + Applications payload in format: {"codebase1": {"imageTag": "version1", "customValues": true}, "codebase2": {"imageTag": "version2", "customValues": true}}. For example: {"demo": {"imageTag": "main-20240103-141431", "customValues": true}, "myapp": {"imageTag": "0.1.0-SNAPSHOT.1", "customValues": true}} + - name: CDPIPELINE + description: | + EDP kind:CDPipeline name used for deployment. For example: mypipe, myfeature + - name: CDSTAGE + description: | + EDP kind:Stage name of the kind:CDPipeline defined in the CDPIPELINE values. For example: dev, test, prod + resourcetemplates: + - apiVersion: tekton.dev/v1 + kind: PipelineRun + metadata: + generateName: deploy-$(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE)- + labels: + app.edp.epam.com/cdpipeline: $(tt.params.CDPIPELINE) + app.edp.epam.com/cdstage: $(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE) + app.edp.epam.com/pipelinetype: deploy + spec: + taskRunTemplate: + serviceAccountName: tekton + pipelineRef: + name: deploy-ansible-awx + params: + - name: APPLICATIONS_PAYLOAD + value: $(tt.params.APPLICATIONS_PAYLOAD) + - name: CDSTAGE + value: $(tt.params.CDSTAGE) + - name: CDPIPELINE + value: $(tt.params.CDPIPELINE)