Skip to content

Commit

Permalink
feat: Make possible run autotest from deploy pipeline (#133)
Browse files Browse the repository at this point in the history
Change-Id: If46ec58c3f5ecdfaa1aa966c00827bd039fe8874
  • Loading branch information
Mykola Serdiuk committed Feb 29, 2024
1 parent 30f4a78 commit c8a88a4
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: cd-stage-deploy-auto
labels:
app.edp.epam.com/pipeline: general-deployment
app.edp.epam.com/pipelinetype: deploy
spec:
description: |
This Pipeline is used to deploy applications to the target Stage (Environment).
workspaces:
- name: shared-workspace
params:
- name: pipelineUrl
description: |
URL of the pipeline run in Tekton Dashboard.
type: string
default: https://tekton-{{ .Release.Namespace }}.{{ .Values.global.dnsWildCard }}/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(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
- name: KUBECONFIG_SECRET_NAME
description: The name of secret with Kubeconfig to connect to the remote cluster
type: string
- name: autotes-pipeline
default: "autotes-pipeline"
- name: codebase_tags
default: "codebase_tags"
- name: parent-pipeline-name
default: $(context.pipelineRun.name)
tasks:
- name: pre-deploy
taskRef:
kind: Task
name: run-quality-gate
params:
- name: KUBECONFIG_SECRET_NAME
value: $(params.KUBECONFIG_SECRET_NAME)
- name: BASE_IMAGE
value: "bitnami/kubectl:1.25.4"
- name: EXTRA_COMMANDS
value:
echo "Hello World"

- name: deploy-app
taskRef:
kind: Task
name: deploy-applicationset-cli
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: KUBECONFIG_SECRET_NAME
value: $(params.KUBECONFIG_SECRET_NAME)
- name: BASE_IMAGE
value: "bitnami/kubectl:1.25.4"
- name: EXTRA_COMMANDS
value:
echo "Hello World"

- name: init-autotest
taskRef:
kind: Task
name: init-autotest
runAfter:
- post-deploy
params:
- name: stage-name
value: $(params.CDSTAGE)
- name: cd-pipeline-name
value: $(params.CDPIPELINE)
- name: AUTOTEST_PIPELINES
value: $(params.autotes-pipeline)
- name: codebase_tags
value: $(params.codebase_tags)
- name: parent-pipeline-name
value: $(params.parent-pipeline-name)
workspaces:
- name: source
workspace: shared-workspace


- name: wait-for-autotests
taskRef:
kind: Task
name: wait-for-autotests
runAfter:
- init-autotest
params:
- name: AUTOTEST_PIPELINES
value: $(params.autotes-pipeline)
workspaces:
- name: source
workspace: shared-workspace

- name: promote-images
taskRef:
kind: Task
name: promote-images
runAfter:
- wait-for-autotests
params:
- name: APPLICATIONS_PAYLOAD
value: $(params.APPLICATIONS_PAYLOAD)
- name: CDPIPELINE_STAGE
value: $(params.CDSTAGE)
- name: CDPIPELINE_CR
value: $(params.CDPIPELINE)
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ spec:
value: $(params.stage-name)
- name: CD_PIPELINE_NAME
value: $(params.cd-pipeline-name)
- name: GIT_PROVIDER
value: "{{ .Values.global.gitProvider }}"
- name: PARENT_PIPELINE_NAME
value: $(params.parent-pipeline-name)

Expand Down Expand Up @@ -75,14 +73,14 @@ spec:
}
cdPipelineName = os.getenv('CD_PIPELINE_NAME')
stage = os.getenv('STAGE_NAME')
gitProvider = os.getenv('GIT_PROVIDER')
parentPipelineName = os.getenv('PARENT_PIPELINE_NAME')
codebaseFileTags = os.getenv('CODEBASE_TAGS')
autotests = json.loads(subprocess.check_output(["kubectl", "get", "stage", cdPipelineName + "-" + stage, "-o=jsonpath='{.spec}'"]).decode("utf-8").strip("'"))
gitserver = json.loads(subprocess.check_output(["kubectl", "get", "gitserver", gitProvider , "-o=jsonpath='{.spec}'"]).decode("utf-8").strip("'"))
for element in autotests["qualityGates"]:
autotestGitServer = subprocess.check_output(["kubectl", "get", "codebase", element["autotestName"], "-o=jsonpath='{.spec.gitServer}'"]).decode("utf-8").strip("'")
gitserver = json.loads(subprocess.check_output(["kubectl", "get", "gitserver", autotestGitServer , "-o=jsonpath='{.spec}'"]).decode("utf-8").strip("'"))
autotestsList.append(element["autotestName"])
autotestsBranch.append(element["branchName"])
autotest = json.loads(subprocess.check_output(["kubectl", "get", "codebase", element["autotestName"], "-o=jsonpath='{.spec}'"]).decode("utf-8").strip("'"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: cd-stage-deploy-auto
labels:
app.edp.epam.com/pipelinetype: deploy
spec:
params:
- 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
- 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: KUBECONFIG_SECRET_NAME
description: The name of secret with Kubeconfig to connect to the remote cluster
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: deploy-$(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE)-auto-
labels:
app.edp.epam.com/cdpipeline: $(tt.params.CDPIPELINE)
app.edp.epam.com/cdstage: $(tt.params.CDSTAGE)
app.edp.epam.com/pipelinetype: deploy
spec:
taskRunTemplate:
serviceAccountName: tekton
pipelineRef:
name: cd-stage-deploy-auto
params:
- name: APPLICATIONS_PAYLOAD
value: $(tt.params.APPLICATIONS_PAYLOAD)
- name: CDSTAGE
value: $(tt.params.CDSTAGE)
- name: CDPIPELINE
value: $(tt.params.CDPIPELINE)
- name: KUBECONFIG_SECRET_NAME
value: $(tt.params.KUBECONFIG_SECRET_NAME)
timeouts:
pipeline: 1h00m0s
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "1Gi"
subPath: codebase
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: cd-stage-deploy
labels:
app.edp.epam.com/pipelinetype: deploy
spec:
params:
- name: CDPIPELINE
Expand Down

0 comments on commit c8a88a4

Please sign in to comment.