generated from twilio-professional-services/flex-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (199 loc) · 6.96 KB
/
flex_deploy.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Deploy Flex
# Within this file, FEATURE and END FEATURE blocks are used only by the remove-features script.
on:
# To run this workflow via automated triggers, see the .github/examples directory.
workflow_call:
inputs:
environment:
required: true
type: string
deploy_terraform:
required: true
type: boolean
overwrite_config:
required: true
type: boolean
secrets:
TWILIO_ACCOUNT_SID:
required: true
TWILIO_API_KEY:
required: true
TWILIO_API_SECRET:
required: true
TF_ENCRYPTION_KEY:
required: true
# Enables running this workflow manually from the Actions tab
workflow_dispatch:
inputs:
environment:
required: true
type: environment
description: "Environment to use for deployment"
deploy_terraform:
required: true
type: boolean
default: false
description: Deploy Terraform?
initial_release:
required: true
type: boolean
description: Is this the first release to the environment?
default: false
overwrite_config:
required: true
type: boolean
default: false
description: Overwrite config set by Admin UI Panel?
concurrency:
group: flex-deploy-${{ inputs.environment || github.event.inputs.environment }}
jobs:
# When performing an initial release
# the serverless backend needs an initial deploy so
# the domain name can be pulled in for the terraform deploy
perform-initial-serverless-release:
if: |
(inputs.initial_release == true &&
inputs.deploy_terraform == true)
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
ENVIRONMENT: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: set github environment variables
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
VARS_CONTEXT: ${{ toJson(vars) }}
run: scripts/github-set-env.sh
- name: install top-level packages
run: |
echo "### Job summary" >> $GITHUB_STEP_SUMMARY
echo " - Environment: ${{ env.ENVIRONMENT }}" >> $GITHUB_STEP_SUMMARY
npm install --ignore-scripts
npm run install-serverless-plugin
echo "### Configuration output" >> $GITHUB_STEP_SUMMARY
npm run postinstall -- --skip-plugin >> $GITHUB_STEP_SUMMARY
- name: deploy addons
run: |
npm run deploy-addons
- name: deploy serverless
working-directory: serverless-functions
run: |
npm run deploy
deploy-terraform:
needs: [perform-initial-serverless-release]
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
inputs.deploy_terraform == true
uses: ./.github/workflows/terraform_deploy.yaml
with:
environment: ${{ inputs.environment }}
secrets:
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_API_KEY: ${{ secrets.TWILIO_API_KEY }}
TWILIO_API_SECRET: ${{ secrets.TWILIO_API_SECRET }}
TF_ENCRYPTION_KEY: ${{ secrets.TF_ENCRYPTION_KEY }}
deploy-packages:
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
ENVIRONMENT: ${{ inputs.environment }}
needs: [deploy-terraform]
steps:
- uses: actions/checkout@v4
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: set github environment variables
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
VARS_CONTEXT: ${{ toJson(vars) }}
run: scripts/github-set-env.sh
- name: install npm and apply missing environment variables
id: initial-env
run: |
echo "### Job summary" >> $GITHUB_STEP_SUMMARY
echo " - Environment: ${{ env.ENVIRONMENT }}" >> $GITHUB_STEP_SUMMARY
echo "### Configuration output" >> $GITHUB_STEP_SUMMARY
npm install --ignore-scripts
npm run install-serverless-plugin
npm run postinstall -- --skip-plugin >> $GITHUB_STEP_SUMMARY
- name: deploy addons
run: |
npm run deploy-addons
- name: deploy serverless
working-directory: serverless-functions
run: |
npm run deploy
deploy-flex-config:
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
env:
ENVIRONMENT: ${{ inputs.environment }}
OVERWRITE_CONFIG: ${{ inputs.initial_release == true || inputs.overwrite_config == true }}
needs:
- deploy-packages
steps:
- uses: actions/checkout@v4
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: set github environment variables
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
VARS_CONTEXT: ${{ toJson(vars) }}
run: scripts/github-set-env.sh
- name: install root npm
run: |
echo "### Job summary" >> $GITHUB_STEP_SUMMARY
echo " - Environment: ${{ env.ENVIRONMENT }}" >> $GITHUB_STEP_SUMMARY
echo " - Overwrite Config: ${{ env.OVERWRITE_CONFIG }}" >> $GITHUB_STEP_SUMMARY
echo "### Configuration output" >> $GITHUB_STEP_SUMMARY
npm install --ignore-scripts
npm run postinstall -- --packages=flex-config >> $GITHUB_STEP_SUMMARY
- name: deploy flex config
working-directory: flex-config
run: |
npm run deploy
deploy-release-plugin:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_API_KEY: ${{ secrets.TWILIO_API_KEY }}
TWILIO_API_SECRET: ${{ secrets.TWILIO_API_SECRET }}
PLUGIN_FOLDER: plugin-flex-ts-template-v2
steps:
- uses: actions/checkout@v4
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: install twilio cli
run: npm install --ignore-scripts
- name: deploy and release flex-plugin
run: |
echo "### Job summary" >> $GITHUB_STEP_SUMMARY
echo " - Environment: ${{ inputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo " - Plugin Folder: ${{ env.PLUGIN_FOLDER }}" >> $GITHUB_STEP_SUMMARY
cd $PLUGIN_FOLDER
npm install
npm run install-flex-plugin
npm run deploy -- --changelog="Deploy from CI/CD for commit ${{ github.sha }}"
npm run release -- --name="Release from CI/CD for commit ${{ github.sha }}" --description="Release from CI/CD for commit ${{ github.sha }}"