-
Notifications
You must be signed in to change notification settings - Fork 4
/
workflow.yaml
178 lines (175 loc) · 6.52 KB
/
workflow.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: post-sync
spec:
entrypoint: handle-sync-event
onExit: exit-handler
retryStrategy:
expression: "asInt(lastRetry.exitCode) > 1"
limit: 3
backoff:
duration: "2m"
factor: 2
maxDuration: "16m"
arguments:
parameters:
- name: application
- name: repoName
- name: imageTag
podSpecPatch: |
containers:
- name: main
resources:
limits:
memory: 2Gi
templates:
- name: handle-sync-event
podSpecPatch: '{"containers":[{"name":"main","resources":{"limits":{"cpu":2,"memory":"2Gi"},"requests":{"cpu":1,"memory":"1Gi"}}}]}'
dag:
tasks:
- name: smoke-test
templateRef:
name: smoke-test
template: smoke-test
arguments:
parameters:
- name: extra-args
value: "{{"@app-{{workflow.parameters.application}}"}}"
- name: govuk-e2e-tests
templateRef:
name: govuk-e2e-tests
template: govuk-e2e-tests
arguments:
parameters:
- name: grep
value: "{{"@app-{{workflow.parameters.application}}"}}"
{{ if .Values.nextEnvironment }}
- name: check-for-promotion
depends: smoke-test.Succeeded
when: "{{"'{{workflow.parameters.application}}' !~ '^draft-'"}}"
template: check-for-promotion
arguments:
parameters:
- name: environment
value: "{{ .Values.govukEnvironment }}"
- name: repoName
value: "{{"{{workflow.parameters.repoName}}"}}"
- name: promote-release
depends: check-for-promotion.Succeeded
when: "{{"'{{tasks.check-for-promotion.outputs.result}}' == 'true'"}}"
template: send-webhook
arguments:
parameters:
- name: environment
value: "{{ .Values.nextEnvironment }}"
- name: repoName
value: "{{"{{workflow.parameters.repoName}}"}}"
- name: imageTag
value: "{{"{{workflow.parameters.imageTag}}"}}"
- name: promoteDeployment
value: "true"
- name: check-for-promotion
inputs:
parameters:
- name: environment
- name: repoName
script:
image: 172025368201.dkr.ecr.eu-west-1.amazonaws.com/github/alphagov/govuk/toolbox:latest
command: [/bin/bash]
env:
- name: ENVIRONMENT
value: "{{"{{inputs.parameters.environment}}"}}"
- name: REPO_NAME
value: "{{"{{inputs.parameters.repoName}}"}}"
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: govuk-ci-github-creds
key: token
source: |
{{- .Files.Get "scripts/check-for-promotion.sh" | nindent 14 }}
- name: send-webhook
inputs:
parameters:
- name: environment
- name: repoName
- name: imageTag
- name: promoteDeployment
script:
image: curlimages/curl
command:
- sh
source: >
curl -s "${WEBHOOK_URL}/update-image-tag" \
-H "Authorization: Bearer ${WEBHOOK_TOKEN}" \
--json '{
"environment": "{{"{{inputs.parameters.environment}}"}}",
"repoName": "{{"{{inputs.parameters.repoName}}"}}",
"imageTag": "{{"{{inputs.parameters.imageTag}}"}}",
"promoteDeployment": "{{"{{inputs.parameters.promoteDeployment}}"}}"
}'
env:
- name: WEBHOOK_TOKEN
valueFrom:
secretKeyRef:
name: deploy-image-webhook-endpoint
key: token
- name: WEBHOOK_URL
valueFrom:
secretKeyRef:
name: deploy-image-webhook-endpoint
key: url
{{- end }}
- name: parse-failures
inputs: {}
outputs:
parameters:
- name: message
valueFrom:
path: /tmp/message.txt
script:
image: 172025368201.dkr.ecr.eu-west-1.amazonaws.com/github/alphagov/govuk/toolbox:latest
command:
- /bin/bash
resources: {}
source: >
#!/usr/bin/env bash
echo {{"{{workflow.failures}}"}} | jq -r 'group_by(.templateName) | map({templateName: .[0].templateName, errorMessages: [.[].message | select(length > 0)] | unique}) | map("- \(.templateName): " + (["\(.errorMessages[])"] | join(",")) ) | .[]' > /tmp/message.txt
- name: exit-handler
steps:
- - name: parse-failures
template: parse-failures
when: "{{"{{workflow.status}}"}} != Succeeded"
- - name: notify-slack
when: "{{"{{workflow.status}}"}} != Succeeded"
templateRef:
name: notify-slack
template: notify-slack
arguments:
parameters:
- name: slackChannel
# NOTE: Change to {{"{{workflow.parameters.slackChannel}}"}} to
# send to team slack channel.
value: "govuk-deploy-alerts"
- name: text
value: "Post-deploy workflow for {{"{{workflow.parameters.application}}"}} in {{ .Values.govukEnvironment }} has {{"{{= sprig.lower(workflow.status) }}"}}. \n\n {{"{{ steps.parse-failures.outputs.parameters.message }}"}}"
- name: blocks
value: |
[{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Post-deploy workflow for {{"{{workflow.parameters.application}}"}} in {{ .Values.govukEnvironment }} has {{"{{= sprig.lower(workflow.status) }}"}}. \n\n {{"{{ steps.parse-failures.outputs.parameters.message }}"}}"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View workflow",
"emoji": true
},
"url": "https://argo-workflows.eks.{{ .Values.govukEnvironment }}.govuk.digital/workflows/apps/{{"{{ workflow.name }}"}}",
"action_id": "view-workflow"
}
}]