Skip to content

Commit ae7ffa6

Browse files
committed
feat: update postDeploy solution SD-1405
1 parent 5a8cf64 commit ae7ffa6

File tree

12 files changed

+204
-83
lines changed

12 files changed

+204
-83
lines changed

charts/tekton-pipelines/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type: application
66
# This is the chart version. This version number should be incremented each time you make changes
77
# to the chart and its templates, including the app version.
88
# Versions are expected to follow Semantic Versioning (https://semver.org/)
9-
version: 2.2.14-test.4
9+
version: 2.2.16-dev.1
1010

1111
maintainers:
1212
- url: https://www.saritasa.com/
@@ -110,7 +110,7 @@ description: |
110110
script: |
111111
#!/bin/bash
112112
echo "hello world"
113-
extraPostDeployTaskSteps:
113+
postDeployTaskSteps:
114114
- name: post-deploy-hello-world
115115
image: node:22
116116
imagePullPolicy: IfNotPresent

charts/tekton-pipelines/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ saritasa-tekton-pipelines
3131

3232
## `chart.version`
3333

34-
![Version: 2.2.14-test.4](https://img.shields.io/badge/Version-2.2.14-test.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
34+
![Version: 2.2.16-dev.1](https://img.shields.io/badge/Version-2.2.16-dev.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
3535

3636
## Maintainers
3737

@@ -132,7 +132,7 @@ buildpacks:
132132
script: |
133133
#!/bin/bash
134134
echo "hello world"
135-
extraPostDeployTaskSteps:
135+
postDeployTaskSteps:
136136
- name: post-deploy-hello-world
137137
image: node:22
138138
imagePullPolicy: IfNotPresent
@@ -216,7 +216,7 @@ After configuring these values, you will have an extra `sentry-release` step aft
216216
|-----|------|---------|-------------|
217217
| buildkit.build_args | list | `[]` | |
218218
| buildkit.enabled | bool | `true` | should we enable the buildkit pipeline |
219-
| buildkit.extraPostDeployTaskSteps | string | `nil` | |
219+
| buildkit.postDeployTaskSteps | string | `nil` | |
220220
| buildkit.preDeployTaskSteps | list | `[]` | steps to run in the `pre-deploy` task prior to ArgoCD sync command can be useful to prepare different backups and tests before real deploy |
221221
| buildpacks.cnbPlatformAPI | string | `"0.10"` | cnb (cloud native buildpacks) platform API to support see more details [here](https://buildpacks.io/docs/reference/spec/platform-api/) and [here](https://github.com/buildpacks/spec/blob/main/platform.md) |
222222
| buildpacks.enabled | bool | `false` | should we enable buildpack based pipelines |

charts/tekton-pipelines/templates/buildkit/pipeline.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ spec:
152152
{{ include "pipeline.sentryRelease" . | nindent 4 }}
153153
{{ end }}
154154

155-
{{ if .Values.postDeployTask.enabled }}
155+
{{- if (.Values.buildkit).postDeployTaskSteps }}
156156
{{ include "pipeline.postDeploy" (dict "name" "buildkit-post-deploy" "sentry_enabled" .Values.sentry.enabled) | nindent 4 }}
157157
{{ end }}
158158

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{{ if and .Values.buildkit.enabled }}
2-
{{ $data := dict "extraSteps" .Values.buildkit.extraPostDeployTaskSteps
3-
"namespace" $.Release.Namespace
4-
"namePrefix" "buildkit" }}
1+
{{ if and .Values.buildkit.enabled (.Values.buildkit).postDeployTaskSteps }}
2+
{{ $data := dict "namespace" $.Release.Namespace
3+
"namePrefix" "buildkit"
4+
"pipeline" .Values.buildkit }}
55
{{ include "task.postDeploy" $data }}
66
{{ end }}

charts/tekton-pipelines/templates/buildpacks/pipelines/_buildpack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ spec:
271271
{{- end }}
272272
{{ end }}
273273

274-
{{- if .postDeployTask.enabled }}
274+
{{- if (.pipeline).postDeployTaskSteps }}
275275
{{ include "pipeline.postDeploy" (dict "name" (printf "%s-post-deploy" .pipeline.name) "sentry_enabled" .sentry.enabled) | nindent 4 }}
276276
{{- end }}
277277

charts/tekton-pipelines/templates/buildpacks/pipelines/buildpack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- range $pipeline := .Values.buildpacks.generate }}
2-
{{$data := dict "pipeline" $pipeline "namespace" $.Release.Namespace "sentry" $.Values.sentry "postDeployTask" $.Values.postDeployTask}}
2+
{{$data := dict "pipeline" $pipeline "namespace" $.Release.Namespace "sentry" $.Values.sentry}}
33
{{ if and $.Values.buildpacks.enabled $pipeline.enabled }}
44
{{ include "pipeline.buildpack" $data }}
55
{{ end }}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{{- range $pipeline := $.Values.buildpacks.generate }}
2-
{{ $data := dict "extraSteps" $pipeline.extraPostDeployTaskSteps
3-
"namespace" $.Release.Namespace
4-
"namePrefix" $pipeline.name }}
5-
{{ if and (and $.Values.buildpacks.enabled $pipeline.enabled) }}
2+
{{ $data := dict "namespace" $.Release.Namespace
3+
"namePrefix" $pipeline.name
4+
"pipeline" $pipeline }}
5+
{{ if and $.Values.buildpacks.enabled $pipeline.enabled ($pipeline).postDeployTaskSteps }}
66
{{ include "task.postDeploy" $data }}
77
{{ end }}
88
{{- end}}

charts/tekton-pipelines/templates/common/tasks/_post-deploy.yaml

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,21 @@ spec:
3535
envFrom:
3636
- configMapRef:
3737
name: $(params.application)-build-pipeline-config # project specific values
38-
38+
env:
39+
- name: application
40+
value: $(params.application)
41+
- name: project
42+
value: $(params.project)
43+
- name: namespace
44+
value: $(params.namespace)
45+
- name: sha
46+
value: $(params.sha)
47+
- name: environment
48+
value: $(params.environment)
3949
steps:
40-
- name: argo-events
41-
image: badouralix/curl-jq
42-
imagePullPolicy: IfNotPresent
43-
resources: {}
44-
script: |
45-
#!/usr/bin/env sh
46-
47-
ENDPOINT="build-succeed-eventsource-svc.argo-events.svc.cluster.local:12000/build-succeed"
48-
49-
# Try HEAD request to check if endpoint is reachable
50-
if ! curl -Is --max-time 5 "${ENDPOINT}" >/dev/null 2>&1; then
51-
echo "Endpoint ${ENDPOINT} not reachable"
52-
exit 0
53-
fi
54-
55-
# Env contains params passed from '*-build-pipeline-config' ConfigMap,
56-
# here we convert them to lowercased json and pass to JSON_PAYLOAD as 'extra'.
57-
58-
# This workflow allows us to pass any dynamic custom parameters needed to argo-events
59-
# sensors without changing tekton helm charts all the time, so any project may have
60-
# any custom parameter, which will be passed to argo-events and then corresponding Sensor
61-
# would be triggered based on this 'extra' params.
62-
EXTRA=$(jq -n env | jq 'walk(if type=="object" then with_entries(.key|=ascii_downcase) else . end)')
63-
JSON_TEMPLATE='{
64-
"namespace": "$(params.namespace)",
65-
"project": "$(params.project)",
66-
"environment": "$(params.environment)",
67-
"application": "$(params.application)",
68-
"sha": "$(params.sha)",
69-
"extra": %s
70-
}'
71-
JSON_PAYLOAD=$(printf "$JSON_TEMPLATE" "$EXTRA")
72-
73-
echo "Payload: $JSON_PAYLOAD"
74-
75-
OUTPUT=$(curl -s -o /dev/null -w httpcode=%{http_code} --location \
76-
--request POST "${ENDPOINT}" \
77-
--header 'Content-Type: application/json' \
78-
--data-raw "$JSON_PAYLOAD")
79-
80-
STATUS_CODE=$(echo "${OUTPUT}" | sed -e 's/.*\httpcode=//')
81-
if [ ${STATUS_CODE} -ne 204 ] && [ ${STATUS_CODE} -ne 200 ]; then
82-
echo "Curl operation/command failed due to server return code - ${STATUS_CODE}"
83-
exit 0
84-
fi
85-
86-
echo "Sent 'build-succeed' webhook"
87-
88-
# insert customized steps as defined in the values.yaml of the helm chart
89-
{{ if .extraSteps }}
90-
{{ .extraSteps | toYaml | nindent 4 }}
91-
{{ end }}
50+
# insert customized steps as defined in the values.yaml of the helm chart
51+
{{- if (.pipeline).postDeployTaskSteps }}
52+
{{- .pipeline.postDeployTaskSteps | toYaml | nindent 4}}
53+
{{ end }}
9254
---
9355
{{- end }}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: argo-events
5+
namespace: {{ .Release.Namespace }}
6+
7+
spec:
8+
description: >-
9+
Task sends a `build-succeed` webhook event to Argo Events after `build` pipeline
10+
completes successfully, by posting params to the EventSource endpoint
11+
12+
params:
13+
- name: application
14+
type: string
15+
description: name of the argocd application we're going to deploy/sync
16+
17+
- name: project
18+
type: string
19+
description: name of the project, which component is deployed
20+
21+
- name: namespace
22+
type: string
23+
description: project's namespace
24+
25+
- name: sha
26+
type: string
27+
description: sha commit ID of the image deployed in cluster
28+
29+
- name: environment
30+
type: string
31+
description: environment name of the app being built, i.e. dev/staging/prod
32+
33+
stepTemplate:
34+
envFrom:
35+
- configMapRef:
36+
name: $(params.application)-build-pipeline-config # project specific values
37+
steps:
38+
- name: argo-events
39+
image: badouralix/curl-jq
40+
imagePullPolicy: IfNotPresent
41+
resources: {}
42+
script: |
43+
#!/usr/bin/env sh
44+
45+
ENDPOINT="build-succeed-eventsource-svc.argo-events.svc.cluster.local:12000/build-succeed"
46+
47+
# Try HEAD request to check if endpoint is reachable
48+
if ! curl -Is --max-time 5 "${ENDPOINT}" >/dev/null 2>&1; then
49+
echo "Endpoint ${ENDPOINT} not reachable"
50+
exit 0
51+
fi
52+
53+
# Env contains params passed from '*-build-pipeline-config' ConfigMap,
54+
# here we convert them to lowercased json and pass to JSON_PAYLOAD as 'extra'.
55+
56+
# This workflow allows us to pass any dynamic custom parameters needed to argo-events
57+
# sensors without changing tekton helm charts all the time, so any project may have
58+
# any custom parameter, which will be passed to argo-events and then corresponding Sensor
59+
# would be triggered based on this 'extra' params.
60+
EXTRA=$(jq -n env | jq 'walk(if type=="object" then with_entries(.key|=ascii_downcase) else . end)')
61+
JSON_TEMPLATE='{
62+
"namespace": "$(params.namespace)",
63+
"project": "$(params.project)",
64+
"environment": "$(params.environment)",
65+
"application": "$(params.application)",
66+
"sha": "$(params.sha)",
67+
"extra": %s
68+
}'
69+
JSON_PAYLOAD=$(printf "$JSON_TEMPLATE" "$EXTRA")
70+
71+
echo "Payload: $JSON_PAYLOAD"
72+
73+
OUTPUT=$(curl -s -o /dev/null -w httpcode=%{http_code} --location \
74+
--request POST "${ENDPOINT}" \
75+
--header 'Content-Type: application/json' \
76+
--data-raw "$JSON_PAYLOAD")
77+
78+
STATUS_CODE=$(echo "${OUTPUT}" | sed -e 's/.*\httpcode=//')
79+
if [ ${STATUS_CODE} -ne 204 ] && [ ${STATUS_CODE} -ne 200 ]; then
80+
echo "Curl operation/command failed due to server return code - ${STATUS_CODE}"
81+
exit 0
82+
fi
83+
84+
echo "Sent 'build-succeed' webhook"

charts/tekton-pipelines/templates/kaniko/pipeline.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ spec:
152152
{{ include "pipeline.sentryRelease" . | nindent 4 }}
153153
{{ end }}
154154

155-
{{ if .Values.postDeployTask.enabled }}
155+
{{- if (.Values.kaniko).postDeployTaskSteps }}
156156
{{ include "pipeline.postDeploy" (dict "name" "kaniko-post-deploy" "sentry_enabled" .Values.sentry.enabled) | nindent 4 }}
157157
{{ end }}
158158

0 commit comments

Comments
 (0)