forked from ts-factory/bublik-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
541 lines (492 loc) · 16.7 KB
/
Taskfile.yml
File metadata and controls
541 lines (492 loc) · 16.7 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
version: "3"
dotenv:
- .env
vars:
API_URL:
sh: |
fqdn="{{.BUBLIK_FQDN}}"
prefix="{{.URL_PREFIX}}"
port="{{.BUBLIK_DOCKER_PROXY_PORT}}"
fqdn="${fqdn%/}"
prefix="${prefix#/}"
prefix="${prefix%/}"
if [ -n "$prefix" ]; then
echo "$fqdn:$port/$prefix"
else
echo "$fqdn:$port"
fi
BACKUP_DIR:
sh: echo "${CLI_ARGS:-backups}"
LOGS_URL:
sh: |
fqdn="{{.BUBLIK_FQDN}}"
prefix="{{.URL_PREFIX}}"
port="{{.BUBLIK_DOCKER_PROXY_PORT}}"
fqdn="${fqdn%/}"
prefix="${prefix#/}"
prefix="${prefix%/}"
if [ "$port" = "80" ] || [ "$port" = "443" ]; then
if [ -n "$prefix" ]; then
echo "$fqdn/$prefix/logs/"
else
echo "$fqdn/logs/"
fi
else
if [ -n "$prefix" ]; then
echo "$fqdn:$port/$prefix/logs/"
else
echo "$fqdn:$port/logs/"
fi
fi
tasks:
default:
desc: Show available tasks
cmds:
- task --list
###########################################
# Git #
###########################################
init:
desc: Initialize Git submodules
summary: Initialize and update all Git submodules recursively
aliases: [i]
status:
- |
# Check if all submodules are initialized and up to date
test -z "$(git submodule status | grep '^-\|^+')"
cmds:
- git submodule init
- git submodule update --init --recursive
update:
desc: Update Git submodules to latest commits
summary: Update all Git submodules to their latest remote commits
aliases: [u]
status:
- |
# Check if any submodule needs updating
test -z "$(git submodule status | grep '^+')"
cmds:
- git submodule update --remote
###########################################
# Docker Environment #
###########################################
docker:setup:
desc: Setup Docker environment (copy env and settings files)
summary: |
Prepare Docker environment by copying necessary configuration files
Uses BUBLIK_DOCKER_DATA_DIR from env
aliases: [setup]
deps: [check-deps]
silent: true
cmds:
- task: docker:setup:env
- task: docker:setup:django-settings
docker:setup:django-settings:
desc: Copy django settings template
internal: true
silent: true
cmds:
- ./scripts/setup_settings.sh
docker:setup:env:
desc: Copy .env.local to .env
internal: true
status:
- test -f .env
silent: true
cmds:
- ./scripts/setup_env.sh
- task: docker:setup:env:uid
docker:setup:env:uid:
desc: Add host UID/GID to .env
internal: true
silent: true
vars:
HOST_UID:
sh: id -u
HOST_GID:
sh: id -g
cmds:
- |
OS_TYPE="$(uname -s)"
if [ "$OS_TYPE" = "Darwin" ]; then
if dscl . -read /Groups/www-data PrimaryGroupID 2>/dev/null | grep -q PrimaryGroupID; then
GID_TO_USE=$(dscl . -read /Groups/www-data PrimaryGroupID | awk '{print $2}')
else
if dscl . -read /Groups/_www PrimaryGroupID 2>/dev/null | grep -q PrimaryGroupID; then
GID_TO_USE=$(dscl . -read /Groups/_www PrimaryGroupID | awk '{print $2}')
echo "ℹ️ Using macOS _www group (GID: $GID_TO_USE)"
else
echo "⚠️ Warning: Neither www-data nor _www group exists on this system"
echo "Using your primary group (GID: {{.HOST_GID}}) instead"
GID_TO_USE="{{.HOST_GID}}"
fi
fi
else
WWW_DATA_GID=$(getent group www-data 2>/dev/null | cut -d: -f3)
if [ -z "$WWW_DATA_GID" ]; then
echo "⚠️ Warning: www-data group does not exist on this system"
echo "Please create it with: sudo groupadd -g 33 www-data"
echo "Or add your user to an existing web server group"
exit 1
fi
GID_TO_USE="$WWW_DATA_GID"
fi
if [ -f .env ]; then
tmp_env=$(mktemp)
while IFS= read -r line || [ -n "$line" ]; do
if [[ ! "$line" =~ ^HOST_(UID|GID)= ]]; then
echo "$line" >> "$tmp_env"
fi
done < .env
echo "HOST_UID={{.HOST_UID}}" >> "$tmp_env"
echo "HOST_GID=$GID_TO_USE" >> "$tmp_env"
mv "$tmp_env" .env
fi
docker:dev:watch:
desc: Start development environment in watch mode
summary: |
Start development environment with live reload capability
Environment will be accessible at {{.API_URL}}
deps: [docker:setup]
aliases: [dev:watch]
cmds:
- docker compose -f docker-compose.dev.yml -f docker-compose.db.yml up --build --watch
- echo "🚀 Development environment started at {{.API_URL}}"
docker:dev:up:
desc: Start development environment
deps: [docker:setup]
aliases: [dev:up]
silent: true
cmds:
- docker compose -f docker-compose.dev.yml -f docker-compose.db.yml up --build -d
- echo "🚀 Development environment started at {{.API_URL}}"
docker:dev:start:
desc: Start development environment
deps: [docker:setup]
aliases: [dev:start]
silent: true
cmds:
- docker compose -f docker-compose.dev.yml -f docker-compose.db.yml start
- echo "🚀 Development environment started at {{.API_URL}}"
docker:start:
desc: Start production environment
deps: [docker:setup]
aliases: [start]
silent: true
cmds:
- docker compose -f docker-compose.yml start
- echo "🚀 Development environment started at {{.API_URL}}"
docker:up:
desc: Start production environment
summary: |
Start production environment with optimized settings
Environment will be accessible at BUBLIK_FQDN
deps: [docker:setup]
aliases: [up]
silent: true
cmds:
- docker compose -f docker-compose.yml -f docker-compose.db.yml up --force-recreate -d
- echo "🚀 Production environment started at {{.API_URL}}"
docker:up:with-external-db:
desc: Start production environment
summary: |
Start production environment with externally deployed database
Environment will be accessible at BUBLIK_FQDN
deps: [docker:setup]
aliases: [up:with-external-db]
silent: true
cmds:
- docker compose -f docker-compose.yml up --force-recreate -d
- echo "🚀 Production environment started at {{.API_URL}}"
docker:pull:
desc: Pull Docker images
aliases: [pull]
cmds:
- docker compose -f docker-compose.yml -f docker-compose.db.yml pull
docker:dev:stop:
desc: Stop Docker development environment
summary: Stop development containers while preserving data
aliases: [dev:stop]
cmds:
- docker compose -f docker-compose.dev.yml -f docker-compose.db.yml stop
docker:stop:
desc: Stop Docker production environment
summary: Stop and remove production containers while preserving data
aliases: [stop]
cmds:
- docker compose -f docker-compose.yml stop
docker:down:
desc: Stop Docker development environment
summary: Stop and remove production containers while preserving data
aliases: [down]
cmds:
- docker compose -f docker-compose.yml -f docker-compose.db.yml down
docker:dev:down:
desc: Stop Docker development environment
summary: Stop and remove development containers while preserving data
aliases: [dev:down]
cmds:
- docker compose -f docker-compose.dev.yml -f docker-compose.db.yml down
management:shell:
desc: Launch a bash shell inside the Django container for interactive management
aliases: [shell]
cmd: docker compose exec -it django bash
management:delete-run:
desc: Delete a test run from the database by providing its ID
aliases: [delete-run]
vars:
ID: "{{.CLI_ARGS}}"
cmd: docker compose exec -it django bash -c 'python manage.py delete_run -i {{ .ID }}'
logs:import-log:
desc: Import logs from a specified .tar file
aliases: [import]
summary: |
Import logs from a specified .tar file
Usage: task logs:import-log -- ./path/to/file.tar
silent: true
vars:
FILE: "{{.CLI_ARGS}}"
cmds:
- ./scripts/import_logs.sh {{.FILE}}
logs:import-log-remote:
desc: Import log from remote URL
aliases: [import-remote]
vars:
URL: "{{.CLI_ARGS}}"
cmd: curl http://localhost/api/v2/importruns/source/?url={{.URL}}
logs:import-via-command:
desc: Import log from remote URL
aliases: [import-command]
vars:
URL: "{{.CLI_ARGS}}"
cmd: docker compose exec -it django bash -c 'python manage.py importruns {{ .URL }}'
logs:publish-incoming-logs:
desc: Publish logs from incoming directory
aliases: [publish]
silent: true
cmds:
- ./scripts/publish_logs.sh
###########################################
# Deps #
###########################################
check-deps:
desc: Check if system dependencies are installed
summary: Verify that all required system and Docker dependencies are available
cmds:
- task: system:check-deps
- task: docker:check-deps
system:check-deps:
desc: Check if system dependencies are installed
internal: true
silent: true
cmds:
- ./scripts/check_deps.sh system
docker:check-deps:
desc: Check if Docker and Docker Compose are installed
internal: true
silent: true
cmds:
- ./scripts/check_deps.sh docker
###########################################
# Shortcuts #
###########################################
meta-categorization:
desc: Trigger meta-categorization process
summary: Start the meta-categorization process for test results
cmd: docker compose exec -it django bash -c 'python manage.py meta_categorization'
###########################################
# Bootstrap #
###########################################
bootstrap-dev:
desc: Bootstrap the application and deploy to development environment
summary: |
Complete development deployment process:
1. Start Docker containers in dev mode
2. Initialize configurations
3. Import initial sessions
4. Display admin credentials
preconditions:
- test -f .env
- test -f ./bublik/bublik/settings.py
cmds:
- task: docker:dev:up
- cmd: echo "Waiting for 15 seconds for services to start..." && sleep 15
- task: bootstrap:init-configs
- task: bootstrap:import-sessions
- task: bootstrap:print-credentials
bootstrap:
desc: Bootstrap the application and deploy to production
summary: |
Complete production deployment process:
1. Start Docker containers
2. Initialize configurations
3. Import initial sessions
4. Display admin credentials
preconditions:
- test -f .env
- test -f ./bublik/bublik/settings.py
cmds:
- task: docker:up
- cmd: echo "Waiting for 15 seconds for services to start..." && sleep 15
- task: bootstrap:init-configs
- task: print-env-info
migrations:transition_1.8.0_to_1.9.0:
desc: Handle migrations when updating to version 1.9.0 and higher from 1.8.0 and lower
cmds:
- ./scripts/create_migrations.sh
print-env-info:
desc: Print environment information
silent: true
cmds:
- |
echo "🔑 Admin credentials:"
echo " Email: {{.DJANGO_SUPERUSER_EMAIL}}"
echo " Password: {{.DJANGO_SUPERUSER_PASSWORD}}"
echo "🔑 Data directory:"
echo " {{.BUBLIK_DOCKER_DATA_DIR}}"
echo "🔑 INSTANCE URL:"
echo " {{.API_URL}}"
bootstrap:import-sessions:
desc: Import Test Sessions from specified file
summary: |
Import test sessions from a specified file containing URLs
Usage: task bootstrap:import-sessions -- /path/to/import.txt
Default file: bootstrap/import.txt
deps: [auth:get-token]
silent: true
vars:
IMPORT_FILE:
sh: echo "${CLI_ARGS:-bootstrap/import.txt}"
cmds:
- ./scripts/import_sessions.sh "{{.API_URL}}" "{{.IMPORT_FILE}}"
- defer: { task: auth:get-token:clean }
bootstrap:init-configs:
desc: Bootstrap Configs from specified directory
summary: |
Bootstrap configuration files from a specified directory
Usage: task bootstrap:init-configs -- /path/to/config/dir
Default directory: bootstrap/
silent: true
deps: [auth:get-token]
vars:
CONFIG_DIR:
sh: echo "${CLI_ARGS:-bootstrap}"
cmds:
- ./scripts/bootstrap_configs.sh "{{.API_URL}}" "{{.EMAIL}}" "{{.PASSWORD}}" "{{.CONFIG_DIR}}" "{{.LOGS_URL}}"
- defer: { task: auth:get-token:clean }
auth:get-token:
desc: Get access token by logging in
summary: |
Get authentication token by logging in with provided credentials
Uses DJANGO_SUPERUSER_EMAIL and DJANGO_SUPERUSER_PASSWORD from env
internal: true
silent: true
vars:
EMAIL: '{{.DJANGO_SUPERUSER_EMAIL | default "admin@bublik.com"}}'
PASSWORD: '{{.DJANGO_SUPERUSER_PASSWORD | default "admin"}}'
cmds:
- mkdir -p ./tmp
- |
echo "🔑 Logging in with {{.EMAIL}}..."
response=$(curl -s -c ./tmp/cookies.txt "{{.API_URL}}/auth/login/" \
-H 'Content-Type: application/json' \
--data-raw "{\"email\":\"{{.EMAIL}}\",\"password\":\"{{.PASSWORD}}\"}")
if grep -q "access_token" ./tmp/cookies.txt; then
echo "✅ Successfully logged in"
token=$(grep "access_token" ./tmp/cookies.txt | cut -f7)
echo "$token" > ./tmp/.access_token
echo "✅ Token saved to ./tmp/.access_token"
else
echo "❌ Login failed"
echo "$response"
exit 1
fi
auth:get-token:clean:
desc: Clean up access token
summary: Remove temporary authentication files
internal: true
cmds:
- rm -f ./tmp/cookies.txt ./tmp/.access_token
###########################################
# Backup Operations #
###########################################
backup:create:
desc: Create a complete backup of database and TE logs
silent: true
summary: |
Create a complete backup archive containing database
Usage: task backup:create -- /path/to/backup/dir
Default directory: ./backups/
cmds:
- ./scripts/backup_operations.sh create {{.BACKUP_DIR}}
backup:restore:
desc: Restore database from a backup archive
silent: true
summary: |
Restore complete backup from an archive
Usage: task backup:restore -- /path/to/backup.tar.gz
cmds:
- ./scripts/backup_operations.sh restore {{.CLI_ARGS}}
backup:list:
desc: List available backup archives
silent: true
summary: |
List all backup archives in the backup directory
Usage: task backup:list -- /path/to/backup/dir
Default directory: ./backups/
cmds:
- ./scripts/backup_operations.sh list {{.BACKUP_DIR}}
###########################################
# Docker Images #
###########################################
docker:build-images:
desc: Build Docker images
summary: Build Runner, Log Server, and Nginx images
aliases: [build]
silent: true
cmds:
- task: docker:setup:django-settings
- task: docker:build:runner
- task: docker:build:log-server
- task: docker:build:nginx
docker:build:runner:
desc: Build Runner image
internal: true
cmds:
- >
docker build
--target runner
--build-arg URL_PREFIX=${URL_PREFIX}
--build-arg DOCS_URL=${DOCS_URL}
-t ${DOCKER_REGISTRY}/${DOCKER_ORG}/${RUNNER_IMAGE_NAME}:${IMAGE_TAG}
.
docker:build:log-server:
desc: Build Log Server image
internal: true
cmds:
- >
docker build
--target log-server
--build-arg URL_PREFIX=${URL_PREFIX}
--build-arg DOCS_URL=${DOCS_URL}
-t ${DOCKER_REGISTRY}/${DOCKER_ORG}/${LOG_SERVER_IMAGE_NAME}:${IMAGE_TAG}
.
docker:build:nginx:
desc: Build Nginx image
internal: true
cmds:
- >
docker build
--build-arg URL_PREFIX=${URL_PREFIX}
--build-arg DOCS_URL=${DOCS_URL}
-t ${DOCKER_REGISTRY}/${DOCKER_ORG}/${NGINX_IMAGE_NAME}:${IMAGE_TAG}
-f ./nginx/Dockerfile
.
docker:push-images:
desc: Push Docker images to registry
summary: Push Runner, Log Server, and Nginx images to container registry
aliases: [push]
cmds:
- docker push ${DOCKER_REGISTRY}/${DOCKER_ORG}/${RUNNER_IMAGE_NAME}:${IMAGE_TAG}
- docker push ${DOCKER_REGISTRY}/${DOCKER_ORG}/${LOG_SERVER_IMAGE_NAME}:${IMAGE_TAG}
- docker push ${DOCKER_REGISTRY}/${DOCKER_ORG}/${NGINX_IMAGE_NAME}:${IMAGE_TAG}