-
-
Notifications
You must be signed in to change notification settings - Fork 14
209 lines (177 loc) · 5.91 KB
/
build-and-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
name: Build and Deploy
on:
push:
branches:
- "*"
permissions:
packages: write
jobs:
build_api_srv:
runs-on: ubuntu-latest
env:
MACONDO_DATA_PATH: ${{ github.workspace }}/data
TEST_DB_HOST: localhost
TEST_DB_PREFIX: liwords_test
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: pass
DB_SSL_MODE: disable
DB_MIGRATIONS_PATH: file:///${{ github.workspace }}/db/migrations
REDIS_URL: redis://localhost:6379
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 3s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: pass
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v4
# - name: Clone macondo
# uses: actions/checkout@v4
# with:
# repository: domino14/macondo
# path: macondo
# - run: mv $GITHUB_WORKSPACE/macondo /opt/macondo
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ">=1.22"
- name: Build API
run: cd cmd/liwords-api && go build
- name: Test API
run: go test -race ./...
- name: Build Puzzle Generator
run: cd cmd/puzzlegen && go build
- name: Build Maintenance
run: cd cmd/maintenance && go build
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Backend built successfully for branch {{GITHUB_REF_NAME}}."
deploy_api_docker:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
needs: build_api_srv
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: domino14
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Tag Docker Image
run: cd deploy && ./build-and-tag.sh
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Backend docker container uploaded; tag = {{GITHUB_REF_NAME}}-gh{{GITHUB_RUN_NUMBER}}"
build_fe:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install Dependencies
run: cd liwords-ui && npm ci
- name: Test Frontend
run: cd liwords-ui && npm run test
- name: Build Frontend
run: cd liwords-ui && npm run build
- name: Persist Dist Directory
uses: actions/upload-artifact@v4
with:
path: liwords-ui/dist
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Front-end built successfully for branch {{GITHUB_REF_NAME}}."
deploy_fe:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
needs: build_fe
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Dist Directory
uses: actions/download-artifact@v4
with:
path: /tmp/liwords-ui
- name: Calculate UI Hash
run: |
ls -al /tmp/liwords-ui/artifact
UI_HASH=$(find /tmp/liwords-ui/artifact -type f -exec md5sum {} \; | sort -k 2 | md5sum | head -c 32)
echo $UI_HASH
sed -i "s:unknown:${UI_HASH}:" /tmp/liwords-ui/artifact/config.js
echo "export UI_HASH=$UI_HASH" >> $GITHUB_ENV
- name: Install AWS CLI
run: |
sudo apt-get update
sudo apt-get install -y awscli
- name: Sync to S3 (Cache Everything)
run: |
cd /tmp/liwords-ui/artifact &&
aws s3 sync --cache-control 'max-age=3024000' \
--exclude index.html --exclude config.js --exclude '*.wasm' \
--metadata FEHash=${UI_HASH} \
. s3://woogles.io
- name: Sync to S3 (No Cache Except Wasm)
run: |
cd /tmp/liwords-ui/artifact &&
aws s3 sync --cache-control 'no-cache' --exclude '*.wasm' \
--metadata FEHash=${UI_HASH} \
. s3://woogles.io
- name: Cache Wasm File Separately
run: |
cd /tmp/liwords-ui/artifact &&
aws s3 sync --cache-control 'max-age=3024000' --exclude '*' --include '*.wasm' \
--metadata FEHash=${UI_HASH} \
--content-type 'application/wasm' . s3://woogles.io
- name: Update Frontend Hash
run: |
curl -X POST -H "Content-Type: application/json" \
-H "X-Api-Key: $ADMIN_WOOGLES_API_KEY" \
https://woogles.io/api/config_service.ConfigService/SetFEHash \
-d "{\"hash\": \"$UI_HASH\"}"
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Front-end deployed successfully for branch {{GITHUB_REF_NAME}}."