-
Notifications
You must be signed in to change notification settings - Fork 10
252 lines (224 loc) · 11 KB
/
webchat-deploy.yml
File metadata and controls
252 lines (224 loc) · 11 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# Copyright (C) 2021-2023 Technology Matters
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.
# Upload Webchat to S3 bucket with Github Actions
name: Webchat Deploy
on:
workflow_dispatch:
inputs:
helpline_code:
description: "The short (usually 2 character) upper case code used to identify the helpline internally, e.g. ZA, IN, BR."
required: true
type: string
environment:
description: "Helpline Environment: development, staging, production"
required: true
type: string
recaptcha_verify_url:
description: "Recaptcha Verify URL"
required: false
type: string
workflow_call:
inputs:
helpline_code:
description: "The short (usually 2 character) upper case code used to identify the helpline internally, e.g. ZA, IN, BR."
required: true
type: string
environment:
description: "Helpline Environment"
required: true
type: string
recaptcha_verify_url:
description: "Recaptcha Verify URL"
required: false
type: string
send-slack-message:
description: If set to false a slack message will not be sent - useful for E2E test deploys.
default: 'true'
type: string
env:
recaptcha_verify_url_default: https://hrm-${{ inputs.environment }}.tl.techmatters.org/lambda/recaptchaVerify
# this is part of a dirty hack to get the right recaptcha_verify_url
recaptcha_verify_url_ca: https://hrm-production-ca.tl.techmatters.org/lambda/recaptchaVerify
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Change String Case for Helpline Code
- name: Change String Case for Helpline Code
id: helpline_code
uses: "ASzc/change-string-case-action@v6"
with:
string: "${{ inputs.helpline_code }}"
# Set SHORT_ENVIRONMENT_CODE
- name: Production Environment
if: inputs.environment == 'production'
run: echo "SHORT_ENVIRONMENT_CODE=prod" >> $GITHUB_ENV
- name: Staging Environment
if: inputs.environment == 'staging'
run: echo "SHORT_ENVIRONMENT_CODE=stg" >> $GITHUB_ENV
- name: Development Environment
if: inputs.environment == 'development'
run: echo "SHORT_ENVIRONMENT_CODE=dev" >> $GITHUB_ENV
# Setup credentials to access AWS for parameters
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-1"
# Get AWS parameters
- name: Set GITHUB_ACTIONS_SLACK_BOT_TOKEN
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "GITHUB_ACTIONS_SLACK_BOT_TOKEN"
env_variable_name: "GITHUB_ACTIONS_SLACK_BOT_TOKEN"
- name: Set ASELO_DEPLOYS_CHANNEL_ID
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "ASELO_DEPLOYS_CHANNEL_ID"
env_variable_name: "ASELO_DEPLOYS_CHANNEL_ID"
- name: Set IP_FIND_API_KEY
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "IP_FIND_API_KEY"
env_variable_name: "IP_FIND_API_KEY"
- name: Set ACCOUNT_SID
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "/${{ inputs.environment }}/twilio/${{ inputs.helpline_code }}/account_sid"
env_variable_name: "ACCOUNT_SID"
- name: Set SERVERLESS_URL
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "/${{ inputs.environment }}/serverless/${{ env.ACCOUNT_SID }}/base_url"
env_variable_name: "SERVERLESS_URL"
- name: Set RECAPTCHA_KEY
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "/global/google/recaptcha/site_key"
env_variable_name: "RECAPTCHA_KEY"
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "18.x"
# Create and fill secret.ts
- name: Create secret.ts
run: |
touch ./private/secret.ts
working-directory: ./webchat
# this is part of a dirty hack to get the right recaptcha_verify_url
- name: set FALLBACK_RECAPTCHA_VERIFY_URL
id: set_fallback_recaptcha_verify_url
run: echo "FALLBACK_RECAPTCHA_VERIFY_URL=${{ inputs.helpline_code == 'CA' && env.recaptcha_verify_url_ca || env.recaptcha_verify_url_default }}" >> $GITHUB_ENV
# This includes a dirty hack to get the recaptcha_verify_url into the secret.ts file with the correct region for CA
# We should really start adding a helpline specific HRM url to the SSM parameters as part of twilio_iac and pulling
# that in here, but this will do for now.
- name: Fill secret.ts
run: |
cat <<EOT >> ./private/secret.ts
export const API_KEY = '${{ env.IP_FIND_API_KEY }}';
export const SERVERLESS_URL = '${{ env.SERVERLESS_URL }}';
export const RECAPTCHA_KEY = '${{ env.RECAPTCHA_KEY }}';
export const RECAPTCHA_VERIFY_URL = '${{ inputs.recaptcha_verify_url || env.FALLBACK_RECAPTCHA_VERIFY_URL }}';
EOT
working-directory: ./webchat
# Run a single command using the runners shell to install dependencies
- name: Install dependencies
run: npm ci
working-directory: ./webchat
# Get the blockedIps for as-dev account
- name: Get blockedIps for as-dev
if: ${{ steps.helpline_code.outputs.lowercase }}-$SHORT_ENVIRONMENT_CODE == as-dev
run: curl -o ./src/blockedIps.json https://tl-public-chat-as-dev.s3.amazonaws.com/blockedIps.json
working-directory: ./webchat
shell: bash
# Get the blockedIps for jm-prod account
- name: Get blockedIps for jm-prod
if: ${{ steps.helpline_code.outputs.lowercase }}-$SHORT_ENVIRONMENT_CODE == jm-prod
run: curl -o ./src/blockedIps.json https://tl-public-chat-jm-prod.s3.amazonaws.com/blockedIps.json
working-directory: ./webchat
shell: bash
# Build and compile Webchat using the corresponding config file
- name: Run build command
run: CONFIG=${{ steps.helpline_code.outputs.lowercase }}-${{ inputs.environment }} npm run build
working-directory: ./webchat
# Rename the builded js file
- name: Rename js
run: mv bundle.js aselo-chat.min.js
working-directory: ./webchat/build
# Upload Webchat to S3 bucket
- name: Upload Webchat to S3 bucket
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --exclude '*' --include '*.js' --content-type 'application/javascript; charset=utf-8'
env:
AWS_S3_BUCKET: tl-public-chat-${{ steps.helpline_code.outputs.lowercase }}-$SHORT_ENVIRONMENT_CODE
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "${{ secrets.AWS_DEFAULT_REGION }}"
SOURCE_DIR: "webchat/build"
- name: Upload Webchat bundle to assets S3 bucket
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --exclude '*' --include '*.js' --content-type 'application/javascript; charset=utf-8'
env:
AWS_S3_BUCKET: assets-${{ inputs.environment }}.tl.techmatters.org
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "${{ secrets.AWS_DEFAULT_REGION }}"
SOURCE_DIR: "webchat/build"
DEST_DIR: "webchat/${{ steps.helpline_code.outputs.lowercase }}"
- name: Upload e2e-chat html file to assets S3 bucket
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --exclude '*' --include 'e2e-chat.html' --include 'test-chat.html' --content-type 'text/html; charset=utf-8'
env:
AWS_S3_BUCKET: assets-${{ inputs.environment }}.tl.techmatters.org
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "${{ secrets.AWS_DEFAULT_REGION }}"
SOURCE_DIR: "webchat/build"
DEST_DIR: "webchat/${{ steps.helpline_code.outputs.lowercase }}"
- name: Clear cloudfront cache
run: |
CF_DISTRO=$(aws cloudfront list-distributions --query "DistributionList.Items[*].{id:Id,origin:Origins.Items[0].DomainName}[?origin=='assets-${{ inputs.environment }}.tl.techmatters.org.s3-website.us-east-1.amazonaws.com'].id" --output text)
aws cloudfront create-invalidation --distribution-id $CF_DISTRO --paths /webchat/${{ steps.helpline_code.outputs.lowercase }}/*
# Send Slack notifying success
- name: Slack Aselo channel
id: slack
uses: slackapi/slack-github-action@v2.0.0
if: ${{ inputs.send-slack-message != 'false' }}
with:
method: chat.postMessage
token: ${{ env.GITHUB_ACTIONS_SLACK_BOT_TOKEN }}
payload: |
channel: ${{ env.ASELO_DEPLOYS_CHANNEL_ID }}
text: '`[WEBCHAT]` Deployment to `${{inputs.helpline_code}}-${{inputs.environment}}` of ${{ github.ref_type }} `${{ github.ref_name }}` requested by `${{ github.triggering_actor }}` completed using workflow '${{ github.workflow }}' with SHA ${{ github.sha }} :rocket:.'
# Update deployment matrix
- name: Update deployment matrix
uses: ./.github/actions/deployment-matrix
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
identifier: ${{ inputs.helpline_code }}
environment: ${{ inputs.environment}}
service_repo: 'webchat'
version_tag: ${{ github.ref_name }}