-
Notifications
You must be signed in to change notification settings - Fork 37
201 lines (191 loc) · 7.65 KB
/
dev_on_dispatch_release_deploy.yml
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: "0 [on_dispatch/CD] Deploy release or hotfix"
run-name: "Deploy ${{ github.ref }} to ${{ github.event.inputs.target_environment }} by @${{ github.actor }}"
on:
workflow_dispatch:
inputs:
target_environment:
type: choice
description: "Environnement cible"
required: true
options:
- staging
- production
- testing
permissions: write-all
jobs:
check-worflow-ref:
name: "Check worflow ref"
runs-on: ubuntu-latest
steps:
- name: "Check worflow ref"
run: |
echo "Deploying to ${{ github.event.inputs.target_environment }} from ref: ${{ github.ref }}"
if ! [[ ${{ github.ref }} == refs\/tags\/v* ]]; then
echo "This workflow can only be triggered from a tag (starting with a 'v')"
exit 1
fi
ask-for-review-on-slack:
name: "Ask for deployment review on Slack"
runs-on: ubuntu-latest
needs: check-worflow-ref
continue-on-error: true
steps:
- name: "Authentification to Google"
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ secrets.GCP_EHP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_EHP_SERVICE_ACCOUNT }}
- name: "Get Slackbot token Secret"
id: 'slackbot-token-secret'
uses: 'google-github-actions/get-secretmanager-secrets@v2'
with:
secrets: |-
SLACK_BOT_TOKEN:passculture-metier-ehp/passculture-ci-slack-bot-token
- name: "Post a link to Slack for the deployment review"
uses: slackapi/[email protected]
with:
channel-id: "CU0SQ8Y58"
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":rocket: Un déploiement de '${{ github.ref }}' a été demandé sur `${{ github.event.inputs.target_environment }}`: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ steps.secrets.outputs.SLACK_BOT_TOKEN }}
version:
name: "Version"
needs: check-worflow-ref
environment: ${{ fromJSON('["deploy", "testing"]')[github.event.inputs.target_environment == 'testing'] }}
runs-on: ubuntu-latest
outputs:
APP_VERSION: ${{ steps.app-version.outputs.APP_VERSION }}
steps:
- name: "Checkout Release"
uses: actions/[email protected]
with:
ref: "${{ github.ref }}"
fetch-depth: 0
- name: "Get app version"
id: "app-version"
run: echo APP_VERSION="$(cat ./api/version.txt)" | tee -a $GITHUB_OUTPUT
deploy-ehp:
name: "Deploy on EHP environnement"
needs: version
if: github.event.inputs.target_environment != 'production'
uses: ./.github/workflows/dev_on_workflow_deploy.yml
with:
environment: ${{ github.event.inputs.target_environment }}
app_version: ${{ needs.version.outputs.APP_VERSION }}
teleport_version: 15.2.5
teleport_proxy: teleport.ehp.passculture.team:443
teleport_kubernetes_cluster: passculture-metier-ehp
deploy_api: true
deploy_pro: true
doc-api-entrypoint: 'api/documentation'
secrets:
GCP_EHP_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_EHP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_EHP_SERVICE_ACCOUNT: ${{ secrets.GCP_EHP_SERVICE_ACCOUNT }}
deploy-integration:
name: "Deploy on integration environnement"
needs: version
if: github.event.inputs.target_environment == 'production'
uses: ./.github/workflows/dev_on_workflow_deploy.yml
with:
environment: integration
app_version: ${{ needs.version.outputs.APP_VERSION }}
teleport_version: 15.2.5
teleport_proxy: teleport.ehp.passculture.team:443
teleport_kubernetes_cluster: passculture-metier-ehp
deploy_api: true
deploy_pro: true
doc-api-entrypoint: 'api/documentation'
secrets:
GCP_EHP_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_EHP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_EHP_SERVICE_ACCOUNT: ${{ secrets.GCP_EHP_SERVICE_ACCOUNT }}
deploy-prod:
name: "Deploy on production environnement"
needs: version
if: github.event.inputs.target_environment == 'production'
uses: ./.github/workflows/dev_on_workflow_deploy.yml
with:
environment: ${{ github.event.inputs.target_environment }}
app_version: ${{ needs.version.outputs.APP_VERSION }}
teleport_version: 15.2.5
teleport_proxy: teleport.passculture.team:443
teleport_kubernetes_cluster: passculture-metier-prod
deploy_api: true
deploy_pro: true
secrets:
GCP_EHP_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_EHP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_EHP_SERVICE_ACCOUNT: ${{ secrets.GCP_EHP_SERVICE_ACCOUNT }}
slack-notification:
name: "Send Slack notification"
runs-on: ubuntu-latest
if: always()
needs:
- version
- deploy-prod
- deploy-ehp
steps:
- uses: technote-space/workflow-conclusion-action@v3
- name: "Authentification to Google"
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ secrets.GCP_EHP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_EHP_SERVICE_ACCOUNT }}
- name: "Get Secret"
id: 'secrets'
uses: 'google-github-actions/get-secretmanager-secrets@v2'
with:
secrets: |-
SLACK_BOT_TOKEN:passculture-metier-ehp/passculture-ci-slack-bot-token
- name: "Post outcome on #alertes-deploiement"
if: always()
uses: slackapi/[email protected]
with:
channel-id: "CQAMNFVPS"
payload: |
{
"attachments": [
{
"mrkdwn_in": ["text"],
"color": "${{ fromJSON('["#36a64f", "#A30002"]')[ env.WORKFLOW_CONCLUSION == 'failure'] }}",
"author_name": "${{github.actor}}",
"author_link": "https://github.com/${{github.actor}}",
"author_icon": "https://github.com/${{github.actor}}.png",
"title": "PCAPI Deployment",
"title_link": "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
"text": "Le déploiement de la version `v${{ needs.version.outputs.APP_VERSION }}` a ${{ fromJSON('["réussi", "échoué"]')[env.WORKFLOW_CONCLUSION != 'success'] }} sur `${{ github.event.inputs.target_environment }}` ${{ fromJSON('[":muscle:", ":boom:"]')[env.WORKFLOW_CONCLUSION != 'success'] }}"
}
],
"unfurl_links": false,
"unfurl_media": false
}
env:
SLACK_BOT_TOKEN: ${{ steps.secrets.outputs.SLACK_BOT_TOKEN }}
- name: "Post success on #shérif"
if: env.WORKFLOW_CONCLUSION == 'success'
uses: slackapi/[email protected]
with:
channel-id: "CU0SQ8Y58"
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":white_check_mark: La version `v${{ needs.version.outputs.APP_VERSION }}` a été déployée sur `${{ github.event.inputs.target_environment }}`"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ steps.secrets.outputs.SLACK_BOT_TOKEN }}