-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.toml
293 lines (249 loc) · 8.44 KB
/
Makefile.toml
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
DOCKER_IMAGE_NAME={ script = ["grep repository backend/Cargo.toml | sed 's/\"//g' | awk '{print $3}' | rev | cut -d'/' -f1-2 | rev"] }
[tasks.help]
workspace = false
script = '''
#!/usr/bin/env bash
echo ""
echo "Main commands"
echo " help display this help message"
echo " run-dev start both the frontend and the backend in dev mode"
echo " run-release start both the frontend and the backend in release mode"
echo " run-docker start the docker image (release mode)"
echo " deploy trigger the deployment of both the demo and live instances through a webhook"
echo " update-entities update seaorm entities"
echo " migration-down roll back the last seaorm migration"
echo " generate-migration generate a new seaorm migration"
echo ""
echo "Other commands"
echo " install-trunk install trunk"
echo " install-wasm32 install wasm32 target"
echo " postgres start postgres database"
echo " redis start redis database"
echo " update-ignored-get-params build/update the ignored get params list"
echo " dev-frontend starts the front-end in dev mode (auto-refresh)"
echo " dev-backend start the backe en in dev mode (auto-restart)"
echo " build-backend-release compile the backend in release mode"
echo " build-frontend-release compile the frontend in release mode"
echo " build-release compile both the fontend and the backend in release mode"
echo " prepare-docker-build prepare for a docker build"
echo " build-docker build the docker image (release mode)"
echo " docker-push push the docker image to docker registry"
echo " deploy-demo trigger the deployment of the demo instance through a webhook"
echo " deploy-live trigger the deployment of the live instance through a webhook"
echo " clean-docker-image delete the docker image"
echo " clean-docker delete the docker image and docker target folder"
echo " clean clean everything"
echo ""
'''
[tasks.install-trunk]
workspace = false
install_crate = { crate_name = "trunk", binary = "trunk", test_arg = "--help" }
[tasks.install-wasm32]
workspace = false
command = "rustup"
args = ["target", "add", "wasm32-unknown-unknown"]
[tasks.postgres]
workspace = false
script = '''
#!/usr/bin/env bash
docker network ls | grep shaarlot || docker network create shaarlot
if docker ps -a | grep shaarlot-postgres; then
docker start shaarlot-postgres
else
docker run -d \
--name shaarlot-postgres \
-e POSTGRES_PASSWORD=password \
-v shaarlot-postgres:/var/lib/postgresql/data \
-p 5432:5432 \
--network shaarlot \
postgres
fi
grep DATABASE_URL .env 2>/dev/null || echo "DATABASE_URL=postgres://postgres:password@localhost:5432/postgres" >> .env
'''
[tasks.redis]
workspace = false
script = '''
#!/usr/bin/env bash
docker network ls | grep shaarlot || docker network create shaarlot
if docker ps -a | grep shaarlot-redis; then
docker start shaarlot-redis
else
docker run -d \
--name shaarlot-redis \
-p 6379:6379 \
--network shaarlot \
redis
fi
'''
[tasks.update-ignored-get-params]
workspace = false
script = '''
#!/usr/bin/env bash
mkdir -p target/query_params_registry
wget https://raw.githubusercontent.com/mpchadwick/tracking-query-params-registry/master/_data/params.csv \
-O target/query_params_registry/mpchadwick__tracking-query-params-registry.csv
tail -n+2 target/query_params_registry/mpchadwick__tracking-query-params-registry.csv \
| cut -d ',' -f 1 \
>> backend/src/query-params-registry.txt
echo "" >> backend/src/query-params-registry.txt
sort -u backend/src/query-params-registry.txt | grep "\S" > backend/src/query-params-registry.txt.new
mv backend/src/query-params-registry.txt.new backend/src/query-params-registry.txt
'''
[tasks.dev-frontend]
workspace = false
dependencies = ["prepare-frontend-dev"]
cwd = "./frontend"
command = "trunk"
args = ["serve", "--public-url", "/", "--address", "0.0.0.0", "--proxy-backend=http://localhost:3000/api/"]
[tasks.prepare-frontend-dev]
workspace = false
dependencies = ["install-trunk", "install-wasm32"]
cwd = "./frontend"
command = "mkdir"
args = ["-p", "../target/debug/wasm"]
[tasks.dev-backend]
workspace = false
env_files = ["./.env"]
env = { "PUBLIC_URL" = "http://localhost:8080", "ROOT_PATH" = "target/debug/wasm" }
dependencies = ["postgres", "redis"]
command = "cargo"
args = ["run", "--bin", "backend"]
watch = true
[tasks.run-dev]
workspace = false
run_task = { name = ["dev-frontend", "dev-backend"], fork = true, parallel = true }
[tasks.build-backend-release]
workspace = false
dependencies = ["compress-assets"]
command = "cargo"
args = ["build", "--bin", "backend", "--release"]
[tasks.prepare-frontend-release]
workspace = false
dependencies = ["install-trunk", "install-wasm32"]
cwd = "./frontend"
command = "mkdir"
args = ["-p", "../target/release/wasm"]
[tasks.build-frontend-release]
workspace = false
dependencies = ["prepare-frontend-release"]
cwd = "./frontend"
command = "trunk"
args = ["build", "--public-url", "/", "--dist", "../target/release/wasm", "--release"]
[tasks.compress-assets]
workspace = false
dependencies = ["build-frontend-release"]
cwd = "./target/release/wasm"
script = [
"for f in $(ls); do",
" command -v gzip >/dev/null && gzip \"$f\" -c > \"$f.gz\"",
" command -v brotli >/dev/null && brotli \"$f\"",
"done",
]
[tasks.build-release]
workspace = false
clear = true
dependencies = ["build-backend-release"]
[tasks.run-release]
workspace = false
env_files = ["./.env"]
env = { "PUBLIC_URL" = "http://localhost:8000", "HTTP_PORT" = "8000" }
dependencies = ["postgres", "redis", "build-release"]
command = "cargo"
args = ["run", "--release", "--bin", "backend"]
[tasks.prepare-docker-build]
workspace = false
dependencies = ["clean-docker", "build-release"]
script = [
"mkdir -p docker/target",
"cp target/release/backend docker/target/backend",
]
[tasks.build-docker]
workspace = false
cwd = "./docker"
dependencies = ["prepare-docker-build"]
command = "docker"
args = ["build", "-t", "${DOCKER_IMAGE_NAME}", "."]
[tasks.docker-push]
workspace = false
dependencies = ["build-docker"]
command = "docker"
args = ["push", "${DOCKER_IMAGE_NAME}"]
[tasks.run-docker]
workspace = false
dependencies = ["postgres", "redis", "build-docker"]
command = "docker"
args = ["run", "--rm", "--name", "shaarlot",
"--env-file", "./.env",
"-e", "DATABASE_HOST=shaarlot-postgres",
"-e", "REDIS_HOST=shaarlot-redis",
"-e", "HTTP_PORT=8001",
"-e", "PUBLIC_URL=http://localhost:8001",
"-p", "8001:8001",
"--network", "shaarlot",
"${DOCKER_IMAGE_NAME}"]
[tasks.deploy]
workspace = false
dependencies = ["docker-push", "deploy-demo", "deploy-live"]
[tasks.deploy-demo]
workspace = false
dependencies = ["docker-push"]
env_files = ["./.env"]
script = '''
#!/usr/bin/env bash
curl "$DEMO_WEBHOOK_URL"
while ! curl --silent --fail "$DEMO_HEALTH_URL" &>/dev/null; do
sleep 2
done
curl "$DEMO_HEALTH_URL"; echo
'''
[tasks.deploy-live]
workspace = false
dependencies = ["docker-push"]
env_files = ["./.env"]
script = '''
#!/usr/bin/env bash
curl "$LIVE_WEBHOOK_URL"
while ! curl --silent --fail "$LIVE_HEALTH_URL" &>/dev/null; do
sleep 2
done
curl "$LIVE_HEALTH_URL"; echo
'''
[tasks.clean-docker-image]
workspace = false
ignore_errors = true
command = "docker"
args = ["rmi", "${DOCKER_IMAGE_NAME}"]
[tasks.clean-docker]
workspace = false
command = "rm"
dependencies = ["clean-docker-image"]
args = ["-rf", "docker/target"]
[tasks.clean]
workspace = false
dependencies = ["clean-docker"]
command = "cargo"
args = ["clean"]
[tasks.update-entities]
workspace = false
env_files = ["./.env"]
dependencies = ["postgres"]
command = "sea-orm-cli"
args = ["generate", "entity", "-l", "-o", "entity/src/"]
[tasks.migration-down]
workspace = false
env_files = ["./.env"]
dependencies = ["postgres"]
command = "cargo"
args = ["run", "-p", "migration", "--", "down", "-n1"]
[tasks.migration-up]
workspace = false
env_files = ["./.env"]
dependencies = ["postgres"]
command = "cargo"
args = ["run", "-p", "migration", "--", "up"]
[tasks.generate-migration]
workspace = false
command = "sea-orm-cli"
args = ["migrate", "generate", "MIGRATION_NAME", "--local-time"]