-
Notifications
You must be signed in to change notification settings - Fork 6
265 lines (245 loc) · 11.1 KB
/
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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Deep client Deployment
on:
push:
branches:
- main
jobs:
deploy_config:
name: Read deploy config
runs-on: ubuntu-latest
outputs:
deploy: ${{ steps.config.outputs.deploy }}
branch: ${{ steps.config.outputs.branch }}
repo: ${{ steps.config.outputs.repo }}
deep_version: ${{ steps.config.outputs.deep_version }}
deep_deploy_datetime: ${{ steps.config.outputs.deep_deploy_datetime }}
steps:
- uses: actions/checkout@v2
- name: Read deploy config
id: config
run: |
SUB_MODULES_DEP_FILE=./deploy.json
DEEP_CLIENT_DEPLOY=`jq -r '.client.deploy' ${SUB_MODULES_DEP_FILE}`
DEEP_CLIENT_REPO=`jq -r '.client.repo' ${SUB_MODULES_DEP_FILE}`
DEEP_CLIENT_BRANCH=`jq -r '.client.branch' ${SUB_MODULES_DEP_FILE}`
DEEP_VERSION=`jq -r '.deep_version' ${SUB_MODULES_DEP_FILE}`
DEEP_DEPLOY_DATETIME=`date +'%FT%T%z'`
echo "deploy=${DEEP_CLIENT_DEPLOY}" >> $GITHUB_OUTPUT
echo "branch=${DEEP_CLIENT_BRANCH}" >> $GITHUB_OUTPUT
echo "repo=${DEEP_CLIENT_REPO#https://github.com/}" >> $GITHUB_OUTPUT
echo "deep_version=${DEEP_VERSION}" >> $GITHUB_OUTPUT
echo "deep_deploy_datetime=${DEEP_DEPLOY_DATETIME}" >> $GITHUB_OUTPUT
test_build:
name: Lint + Test + Build
needs: deploy_config
if: ${{ needs.deploy_config.outputs.deploy == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Clone client
uses: actions/checkout@v2
with:
repository: ${{ needs.deploy_config.outputs.repo }}
ref: ${{ needs.deploy_config.outputs.branch }}
path: ./client
- name: 🐳 Prepare Docker
id: prep
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="docker.pkg.github.com/the-deep/client"
echo "tagged_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: 🐳 Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: 🐳 Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: 🐳 Build image
uses: docker/build-push-action@v2
with:
context: ./client/ # Custom
builder: ${{ steps.buildx.outputs.name }}
file: ./client/Dockerfile # Custom
push: false # This would be set to true in a real world deployment scenario.
load: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: 🤞 Run Build + Lint + Test 🧪
env:
DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }}
run: |
python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" && \
docker run --rm --workdir="/code/" $DOCKER_IMAGE sh -c 'yarn lint'
# Temp fix
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🐳 Move docker cache (🧙 Hack fix)
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# [End] From client .github/workflows/ci.yml
- name: Build [Staging]
env:
DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }}
REACT_APP_RELEASE_VERSION: ${{ needs.deploy_config.outputs.deep_version }}
REACT_APP_RELEASE_TIME: ${{ needs.deploy_config.outputs.deep_deploy_datetime }}
# Misc
REACT_APP_DEEP_ENVIRONMENT: staging
REACT_APP_DEBUG_MODE: true
# Endpoints
REACT_APP_API_HTTPS: https
REACT_APP_API_END: staging-api.thedeep.io
REACT_APP_GRAPHQL_ENDPOINT: https://staging-api.thedeep.io/graphql
REACT_APP_STATIC_ENDPOINT: https://deep-staging-web-addonsstack-qz1nywpr9fyp-media.s3.amazonaws.com
REACT_APP_SERVERLESS_DOMAIN: https://services-alpha.thedeep.io
REACT_APP_PDF_CACHE_ENDPOINT: https://snapshot-proxy.thedeep.io
# Iframes
REACT_APP_ASSESSMENT_REGISTRY_END: https://staging-ary.thedeep.io
REACT_APP_ASSESSMENT_VIZ_URL: https://the-deep.github.io/deepviz-assessments/
REACT_APP_ENTRY_VIZ_URL: https://the-deep.github.io/deepviz-entries/
# Chrome extension
REACT_APP_OLD_BROWSER_EXTENSION_ID: kafonkgglonkbldmcigbdojiadfcmcdc
REACT_APP_BROWSER_EXTENSION_ID: hkmakfhfikfhllpkfpkkaoonapclfajf
# Mapbox # FIXME: Make sure to use valid token for deep domain.
REACT_APP_MAPBOX_STYLE: mapbox://styles/deepmapz/cjc8oth8775tu2sr0eeymm3qv
REACT_APP_MAPBOX_ACCESS_TOKEN: pk.eyJ1IjoiZGVlcG1hcHoiLCJhIjoiY2pjMjN1bjBxMGJmYjJ3bnpwZXlydzNkeiJ9.vYTnFCIPiRCT8jA33Dti5A
# Google Analytics
REACT_APP_GA_TRACKING_ID: UA-112330910-1
# Sentry
REACT_APP_SENTRY_DSN: https://[email protected]/1220157
REACT_APP_SENTRY_TRACES_SAMPLE_RATE: 0.2
REACT_APP_SENTRY_NORMALIZE_DEPTH: 5
# HID
REACT_APP_HID_CLIENT_ID: deeper-staging
REACT_APP_HID_CLIENT_REDIRECT_URL: https://staging.thedeep.io/login/
REACT_APP_HID_AUTH_URI: https://auth.humanitarian.id
# Hcaptcha
REACT_APP_HCATPCHA_SITEKEY: ac332154-0c48-4fc1-9092-e52b291d903c
# Google Drive
REACT_APP_GOOGLE_DRIVE_DEVELOPER_KEY: AIzaSyAcaVOYWk0zGL9TVQfKXdziFI-5pEkw6X4
REACT_APP_GOOGLE_DRIVE_CLIENT_KEY: 642927279233-ht6v3t7h37cc4gjh336sbin6hdlup2vi.apps.googleusercontent.com
run: |
env > env && \
docker run --rm --env-file=./env -v `pwd`/client/build:/code/build $DOCKER_IMAGE sh -c 'yarn install && CI=false NODE_OPTIONS=--max_old_space_size=4096 yarn build'
- name: Upload artifacts [Staging]
uses: actions/upload-artifact@v2
with:
name: client-build-staging
path: ./client/build/
- name: Build [Prod]
env:
DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }}
REACT_APP_RELEASE_VERSION: ${{ needs.deploy_config.outputs.deep_version }}
REACT_APP_RELEASE_TIME: ${{ needs.deploy_config.outputs.deep_deploy_datetime }}
# Misc
REACT_APP_DEEP_ENVIRONMENT: prod
REACT_APP_DEBUG_MODE: false
# Endpoints
REACT_APP_API_HTTPS: https
REACT_APP_API_END: prod-api.thedeep.io
REACT_APP_GRAPHQL_ENDPOINT: https://prod-api.thedeep.io/graphql
REACT_APP_STATIC_ENDPOINT: https://deep-prod-web-addonsstack-1wxq3ye6f4n4b-media.s3.amazonaws.com
REACT_APP_SERVERLESS_DOMAIN: https://services.thedeep.io
REACT_APP_PDF_CACHE_ENDPOINT: https://snapshot-proxy.thedeep.io
# Iframes
REACT_APP_ASSESSMENT_REGISTRY_END: https://prod-ary.thedeep.io
REACT_APP_ASSESSMENT_VIZ_URL: https://the-deep.github.io/deepviz-assessments/
REACT_APP_ENTRY_VIZ_URL: https://the-deep.github.io/deepviz-entries/
# Chrome extension
REACT_APP_BROWSER_EXTENSION_ID: hkmakfhfikfhllpkfpkkaoonapclfajf
# Mapbox # FIXME: Make sure to use valid token for deep domain.
REACT_APP_MAPBOX_ACCESS_TOKEN: pk.eyJ1IjoiZGVlcG1hcHoiLCJhIjoiY2pjMjN1bjBxMGJmYjJ3bnpwZXlydzNkeiJ9.vYTnFCIPiRCT8jA33Dti5A
REACT_APP_MAPBOX_STYLE: mapbox://styles/deepmapz/cjc8oth8775tu2sr0eeymm3qv
# Google Analytics
REACT_APP_GA_TRACKING_ID: UA-112330910-1
# Sentry
REACT_APP_SENTRY_DSN: https://[email protected]/1220157
REACT_APP_SENTRY_TRACES_SAMPLE_RATE: 0.2
REACT_APP_SENTRY_NORMALIZE_DEPTH: 5
# HID
REACT_APP_HID_CLIENT_ID: deeper-prod
REACT_APP_HID_CLIENT_REDIRECT_URL: https://app.thedeep.io/login/
REACT_APP_HID_AUTH_URI: https://auth.humanitarian.id
# Hcaptcha
REACT_APP_HCATPCHA_SITEKEY: ac332154-0c48-4fc1-9092-e52b291d903c
# Google Drive
REACT_APP_GOOGLE_DRIVE_DEVELOPER_KEY: AIzaSyAcaVOYWk0zGL9TVQfKXdziFI-5pEkw6X4
REACT_APP_GOOGLE_DRIVE_CLIENT_KEY: 642927279233-ht6v3t7h37cc4gjh336sbin6hdlup2vi.apps.googleusercontent.com
run: |
env > env && \
docker run --rm --env-file=./env -v `pwd`/client/build:/code/build $DOCKER_IMAGE sh -c 'yarn install && CI=false NODE_OPTIONS=--max_old_space_size=4096 yarn build'
- name: Upload artifacts [Prod]
uses: actions/upload-artifact@v2
with:
name: client-build-prod
path: ./client/build/
staging_deploy:
name: Deploy (STAGING)
runs-on: ubuntu-latest
environment:
name: staging
url: https://staging.thedeep.io
needs: test_build
steps:
- uses: actions/download-artifact@v1
with:
name: client-build-staging
path: build
# Copy build to S3
- name: S3 Sync
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: deep-staging-client
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: './build'
# Invalidate Cloudfront (this action)
- name: Cloudfront Invalidate
uses: chetan/invalidate-cloudfront-action@master
env:
DISTRIBUTION: ${{ secrets.AWS_CDN_DISTRIBUTION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
PATHS: '/index.html'
prod_deploy:
name: Deploy (PROD)
runs-on: ubuntu-latest
environment:
name: prod
url: https://app.thedeep.io
needs: [test_build, staging_deploy]
steps:
- uses: actions/download-artifact@v1
with:
name: client-build-prod
path: build
# Copy build to S3
- name: S3 Sync
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: deep-prod-client
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: './build'
# Invalidate Cloudfront (this action)
- name: Cloudfront Invalidate
uses: chetan/invalidate-cloudfront-action@master
env:
DISTRIBUTION: ${{ secrets.AWS_CDN_DISTRIBUTION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
PATHS: '/index.html'