-
Notifications
You must be signed in to change notification settings - Fork 112
179 lines (148 loc) · 6.33 KB
/
web.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
# Build web app and deploy it
name: web
on:
push:
branches: [ "master", "release" ]
repository_dispatch:
types: web
workflow_dispatch:
workflow_call:
concurrency:
group: web-${{ github.workflow }}-${{ github.ref_type }}-${{ github.event.pull_request.number || github.ref || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash -euxo pipefail {0}
env:
GITHUB_REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
AWS_MAX_ATTEMPTS: 10
PROD_ENABLE_TYPE_CHECKS: 0
VERBOSE: 1
jobs:
build-web:
name: "build-web"
runs-on: ubuntu-22.04
environment:
name: ${{ github.ref }}
steps:
- name: "[init] Check disk space"
run: |
echo ""
df -Th | awk 'NR == 1; NR > 1 {print $0 | "sort -n"}'
echo ""
lsblk -o MOUNTPOINT,FSTYPE,FSSIZE,FSAVAIL,FSUSE%,TYPE,NAME,ROTA,SIZE,MODEL,UUID
- name: "[init] Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: true
- name: "[build] Setup environment (release)"
if: endsWith(github.ref, '/release')
run: |
echo "ENV_NAME=release" >> $GITHUB_ENV
echo "FULL_DOMAIN=https://covariants.org" >> $GITHUB_ENV
echo "PLAUSIBLE_IO_DOMAIN=covariants.org" >> $GITHUB_ENV
- name: "[build] Setup environment (master)"
if: endsWith(github.ref, '/master')
run: |
echo "ENV_NAME=master" >> $GITHUB_ENV
echo "FULL_DOMAIN=https://covariants.org" >> $GITHUB_ENV
echo "PLAUSIBLE_IO_DOMAIN=master.covariants.org" >> $GITHUB_ENV
- name: "[build] Setup Node.js"
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
cache-dependency-path: "web/yarn.lock"
- name: "[build] Setup cache for web app"
uses: actions/cache@v4
with:
path: |
web/.cache
web/.build/production/tmp/cache
key: cache-v1-web-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
cache-v1-web-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
cache-v1-web-${{ runner.os }}-
- name: "[build] Prepare .env file"
run: |
cd web/
cp .env.example .env
sed -i -e "s|FULL_DOMAIN=autodetect|FULL_DOMAIN=${FULL_DOMAIN}|g" .env
- name: "[build] Install Node.js packages"
run: |
cd web
yarn install --frozen-lockfile
- name: "[build] Build web application"
run: |
cd web
yarn prod:build
- name: "[deployment] Setup environment (release)"
if: endsWith(github.ref, '/release')
run: |
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
echo "AWS_CLOUDFRONT_DISTRIBUTION_ID=${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}" >> $GITHUB_ENV
echo "AWS_DEFAULT_REGION=${{ secrets.AWS_DEFAULT_REGION }}" >> $GITHUB_ENV
echo "AWS_S3_BUCKET=${{ secrets.AWS_S3_BUCKET }}" >> $GITHUB_ENV
- name: "[deployment] Setup environment (master)"
if: endsWith(github.ref, '/master')
run: |
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
echo "AWS_CLOUDFRONT_DISTRIBUTION_ID=${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}" >> $GITHUB_ENV
echo "AWS_DEFAULT_REGION=${{ secrets.AWS_DEFAULT_REGION }}" >> $GITHUB_ENV
echo "AWS_S3_BUCKET=${{ secrets.AWS_S3_BUCKET }}" >> $GITHUB_ENV
- name: "[deployment] Install dependencies"
run: |
pushd /tmp >/dev/null
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -oqq awscliv2.zip
sudo ./aws/install --update
popd >/dev/null
aws --version
- name: "[deployment] Clear AWS S3 bucket: html files, web root, app bundle"
run: |
aws s3 rm s3://${AWS_S3_BUCKET} --recursive --exclude "proteins/*" --exclude "acknowledgements/*"
- name: "[deployment] Copy to AWS S3: app bundle"
run: |
cd web/.build/production/web
aws s3 cp --recursive --cache-control "max-age=2592000, public" "_next/" "s3://${AWS_S3_BUCKET}/_next/"
- name: "[deployment] Copy to AWS S3: web root"
run: |
cd web/.build/production/web
aws s3 cp --recursive \
--exclude "_next/*" \
--exclude "*.html" \
--exclude "acknowledgements/*" \
--exclude "proteins/*" \
"./" "s3://${AWS_S3_BUCKET}/"
- name: "[deployment] Copy to AWS S3: html files"
run: |
cd web/.build/production/web
find * -type f -name "*.html" -print0 | xargs -0 -P4 -n1 -I '{}' -- bash -c '\
file={}; \
aws s3 cp \
--content-type "text/html" \
--cache-control "no-cache" \
--metadata-directive REPLACE \
$file \
s3://${AWS_S3_BUCKET}/${file%.html}'
- name: "[deployment] Invalidate AWS Cloudfront cache: html files, web root, app bundle"
run: |
aws cloudfront create-invalidation \
--distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID} \
--paths "/*"
- name: "[deployment] Clear AWS S3 bucket: large static files"
run: |
aws s3 rm s3://${AWS_S3_BUCKET} --recursive --exclude "*" --include "proteins/" --include "acknowledgements/"
- name: "[deployment] Copy to AWS S3: large static files "
run: |
cd web/.build/production/web
aws s3 cp --recursive --cache-control "max-age=7200, public" --metadata-directive REPLACE "proteins/" "s3://${AWS_S3_BUCKET}/proteins/"
aws s3 cp --recursive --cache-control "max-age=7200, public" --metadata-directive REPLACE "acknowledgements/" "s3://${AWS_S3_BUCKET}/acknowledgements/"
- name: "[deployment] Invalidate AWS Cloudfront cache: large static files"
run: |
aws cloudfront create-invalidation \
--distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID} \
--paths "/acknowledgements/*" "/proteins/*"