-
Notifications
You must be signed in to change notification settings - Fork 37
165 lines (156 loc) · 6.22 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
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
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 }}