-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
336 lines (311 loc) · 15.4 KB
/
Copy pathTaskfile.yml
File metadata and controls
336 lines (311 loc) · 15.4 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
version: '3'
silent: true
tasks:
default:
desc: The default task that shows help
cmds:
- echo "Available tasks (in preferred order):"
- echo " install Install the project"
- echo " reinstall Reinstall from scratch. WARNING Deletes the database!"
- echo " up Start the environment"
- echo " down Remove all containers"
- echo " purge Remove all containers and volumes. WARNING Deletes the database!"
- echo " stop Stop all containers"
- echo " logs Follow docker logs"
- echo " cc Clear the cache"
- echo " tenant_add Add a new tenant group"
- echo " user_add Add a new user"
- echo " load_templates Load templates and screen layouts"
- echo " backup_db Performs a database dump, if you use the default internal mariadb."
- echo " upgrade_check Pre-flight checks before the 3.x upgrade (run before env_migrate)"
- echo " env_migrate Convert the running 2.x config to .env.symfony.migrated (for the 3.x upgrade)"
- echo ""
install:
desc: Install the project
deps:
- _dc_compile
cmds:
- task _show_preinstall_notes
- echo "Installing"
- |
# Check if the external network 'frontend' exists, create if not
if ! docker network ls --format '{{.Name}}' | grep -wq frontend; then
echo "Creating external network 'frontend'"
docker network create frontend
else
echo "External network 'frontend' already exists"
fi
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml pull
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml up --force-recreate --detach --remove-orphans
- echo "Waiting for database to be ready"
- sleep 20
- echo "Initialize the database"
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec api bin/console doctrine:schema:create
- echo "Clearing the cache"
- task cc
- echo "Create jwt key pair"
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec api bin/console lexik:jwt:generate-keypair --skip-if-exists
- task tenant_add
- echo "CREATE AN ADMIN USER. CHOOSE THE TENANT YOU JUST CREATED."
- task user_add
- task load_templates
- task _show_notes
reinstall:
desc: Reinstall from scratch. Removes the database, all containers, and volumes.
deps:
- purge
cmds:
- task install
down:
desc: Remove all containers
deps:
- stop
cmds:
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml down
- rm -f docker-compose.yml .env.local
purge:
desc: Remove all containers and volumes
deps:
- stop
cmds:
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml down --volumes --remove-orphans
- |
# Check if the external network 'frontend' exists, remove if it does
if docker network ls --format '{{.Name}}' | grep -wq frontend; then
echo "Removing external network 'frontend'"
docker network rm frontend
else
echo "External network 'frontend' does not exist"
fi
- rm -f docker-compose.yml .env.local
up:
desc: Take the environment up without altering the existing state of the containers
cmds:
- task _dc_compile
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml up -d
stop:
desc: Stop all containers without altering anything else
cmds:
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml stop
tenant_add:
desc: Add a new tenant group
cmds:
- echo ""
- echo "Add a tenant"
- echo "===================================================="
- echo "A tenant is a group of users that share the same configuration. F. ex. IT, Library, Schools etc."
- echo "You have to provide tenant id, tenant title and optionally a description."
- echo "===================================================="
- echo ""
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec -T api bin/console app:tenant:add
user_add:
desc: Add a new user (editor or admin)
cmds:
- echo ""
- echo "Add a user"
- echo "===================================================="
- echo "You have to provide email, password, full name, role (editor or admin) and the tenant id."
- echo "===================================================="
- echo ""
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec -T api bin/console app:user:add
load_templates:
desc: Load templates and screen layouts
cmds:
- |
TEMPLATES_RELEASE=$(grep ^TASK_VERSION_TEMPLATES= .env.docker.local | cut -d '=' -f 2)
TEMPLATES=$(grep ^TASK_TEMPLATES= .env.docker.local | cut -d '=' -f 2 | tr -d ' "' | tr ',' ' ')
if [ -z "$TEMPLATES_RELEASE" ]; then
echo "Error: TASK_VERSION_TEMPLATES is not set in .env.docker.local"
exit 1
fi
if [ -z "$TEMPLATES" ]; then
echo "Error: TASK_TEMPLATES is not set or empty in .env.docker.local"
exit 1
fi
echo "Using TEMPLATES_RELEASE=$TEMPLATES_RELEASE"
echo "Using TEMPLATES=$TEMPLATES"
for TEMPLATE in $TEMPLATES; do
if [ "$TEMPLATES_RELEASE" = "develop" ]; then
CONFIG_URL="https://raw.githubusercontent.com/os2display/display-templates/refs/heads/$TEMPLATES_RELEASE/build/$TEMPLATE-config-main.json"
else
CONFIG_URL="https://raw.githubusercontent.com/os2display/display-templates/refs/tags/$TEMPLATES_RELEASE/build/$TEMPLATE-config-main.json"
fi
echo "Loading template: $TEMPLATE"
docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec --user deploy api bin/console app:template:load -p $CONFIG_URL
done
SCREEN_LAYOUTS=$(grep ^TASK_SCREEN_LAYOUTS= .env.docker.local | cut -d '=' -f 2 | tr -d ' "' | tr ',' ' ')
if [ -z "$SCREEN_LAYOUTS" ]; then
echo "Error: TASK_SCREEN_LAYOUTS is not set or empty in .env.docker.local"
exit 1
fi
echo "Using SCREEN_LAYOUTS=$SCREEN_LAYOUTS"
for SCREEN_LAYOUT in $SCREEN_LAYOUTS; do
if [ "$TEMPLATES_RELEASE" = "develop" ]; then
CONFIG_URL="https://raw.githubusercontent.com/os2display/display-templates/refs/heads/$TEMPLATES_RELEASE/src/screen-layouts/$SCREEN_LAYOUT.json"
else
CONFIG_URL="https://raw.githubusercontent.com/os2display/display-templates/refs/tags/$TEMPLATES_RELEASE/src/screen-layouts/$SCREEN_LAYOUT.json"
fi
echo "Loading screen layout: $SCREEN_LAYOUT"
docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec --user deploy api bin/console app:screen-layouts:load --update --cleanup-regions $CONFIG_URL
done
logs:
desc: Follow docker logs from the containers
cmds:
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml logs -f --tail=50
cc:
desc: Clear the cache
cmds:
- docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec api bin/console cache:clear
backup_db:
desc: Perform a database dump, if you use the default internal mariadb. The dump file will be saved in the 'db_backups' directory with a timestamp in the filename.
cmds:
- |
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
DB_BACKUP_DIR=$(pwd)/db_backups
FILENAME=$DB_BACKUP_DIR/db_backup_$TIMESTAMP.sql
echo "Performing database backup..."
mkdir -p $DB_BACKUP_DIR # Ensure the backup directory exists
DB_USER=$(grep ^MARIADB_USER= .env.docker.local | cut -d '=' -f 2)
DB_NAME=$(grep ^MARIADB_DATABASE= .env.docker.local | cut -d '=' -f 2)
DB_PASSWORD=$(grep ^MARIADB_PASSWORD= .env.docker.local | cut -d '=' -f 2)
echo "Using database user: $DB_USER and database name: $DB_NAME"
docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec mariadb mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > $FILENAME
if [ $? -eq 0 ]; then
echo "Database backup saved to $FILENAME"
fi
env_migrate:
desc: Convert the running 2.x configuration to a 3.x-shaped .env.symfony.migrated on the host. Extra args are forwarded to the console command, e.g. 'task env_migrate -- --skip-config-json'.
cmds:
- |
OUT=.env.symfony.migrated
# The console command ships with display-api-service >= 2.8; fail with
# a hint instead of a stack trace on older images.
if ! docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec -T api bin/console list app:utils --raw 2>/dev/null | grep -q '^app:utils:convert-env-to-3x'; then
echo "Error: the api container does not provide app:utils:convert-env-to-3x."
echo "Update COMPOSE_VERSION_API to a release that includes it (>= 2.8) and run 'task up' first."
exit 1
fi
# The site's public URL is needed to fetch admin/client config.json;
# default --app-url from COMPOSE_SERVER_DOMAIN unless the caller set it.
ARGS="{{.CLI_ARGS}}"
case "$ARGS" in *--app-url*) ;; *)
DOMAIN=$(grep ^COMPOSE_SERVER_DOMAIN= .env.docker.local | cut -d '=' -f 2)
if [ -n "$DOMAIN" ]; then
ARGS="$ARGS --app-url=https://$DOMAIN"
fi
;; esac
# --output=env writes the dotenv document to stdout and all warnings
# to stderr. Go through a temp file so a failed run cannot leave a
# truncated $OUT behind.
TMP=$(mktemp "$OUT.XXXXXX")
if docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec -T api bin/console app:utils:convert-env-to-3x --output=env $ARGS > "$TMP"; then
mv "$TMP" "$OUT"
echo ""
echo "Wrote $OUT."
echo "Review it and use it as the starting point for the 3.x application env."
else
rm -f "$TMP"
echo "Error: conversion failed; $OUT was not written."
exit 1
fi
upgrade_check:
desc: Pre-flight checks before the 3.x upgrade. Run while the stack is up, before env_migrate.
cmds:
- echo ""
- echo "Upgrade pre-flight (1.x -> 3.x)"
- echo "===================================================="
- |
FAIL=0
# The conversion command (used by 'task env_migrate') ships with
# os2display-api-service 2.8.0.
if docker compose --env-file .env.local --env-file .env.docker.local -f docker-compose.yml exec -T api bin/console list app:utils --raw 2>/dev/null | grep -q app:utils:convert-env-to-3x; then
echo "OK The api image provides app:utils:convert-env-to-3x"
else
echo "FAIL The api image does not provide app:utils:convert-env-to-3x."
echo " Set COMPOSE_VERSION_API=2.8.0 (or a later 2.x) in .env.docker.local,"
echo " run 'task install' to pull and recreate, then re-run this task."
FAIL=1
fi
# The 3.x stack reuses the mariadb docker volume in place. It resolves
# the volume as <COMPOSE_PROJECT_NAME>_mariadb, so the 3.x .env MUST
# carry the same project name — a different name silently boots an
# EMPTY database. Record the volume name printed below.
if grep -q '^INTERNAL_DATABASE=true' .env.docker.local; then
PROJECT=$(grep ^COMPOSE_PROJECT_NAME= .env.local | cut -d '=' -f 2)
if docker volume ls -q | grep -wq "${PROJECT}_mariadb"; then
echo "OK MariaDB volume found: ${PROJECT}_mariadb"
echo " Keep COMPOSE_PROJECT_NAME=${PROJECT} in the 3.x .env, or the new"
echo " stack will create a fresh, empty database volume."
else
echo "FAIL Expected mariadb volume '${PROJECT}_mariadb' not found."
echo " Check 'docker volume ls' for the volume your database lives in"
echo " and which COMPOSE_PROJECT_NAME produces it."
FAIL=1
fi
else
echo "SKIP INTERNAL_DATABASE is not 'true' — no bundled mariadb volume to check."
fi
echo "===================================================="
if [ "$FAIL" -ne 0 ]; then
echo "Pre-flight FAILED — fix the items above before 'task env_migrate'."
exit 1
fi
echo "Pre-flight passed. Next steps (while the stack is still up):"
echo " 1. task backup_db (keep the dump somewhere safe)"
echo " 2. task env_migrate (writes .env.symfony.migrated)"
_show_preinstall_notes:
cmds:
- echo ""
- echo "===================================================="
- echo "Pre-installation Requirements"
- echo "===================================================="
- echo ""
- echo "To proceed with the installation, ensure the following steps are completed:"
- echo "1. Update '.env.docker.local' with local settings and set secure passwords."
- echo "2. Place your SSL certificate files ('docker.crt' and 'docker.key') in the 'traefik/ssl' directory."
- echo ""
- echo "Have you completed the above pre-installation steps? (yes/no)"
- |
read answer && case $answer in
[Yy][Ee][Ss]) ;;
*) echo "Please complete the pre-install tasks before continuing."; exit 1;;
esac
_show_notes:
cmds:
- |
DOMAIN=$(grep ^COMPOSE_SERVER_DOMAIN= .env.docker.local | cut -d '=' -f 2)
echo ""
echo "===================================================="
echo "OS2display now is available via the URLs below"
echo "===================================================="
echo "Admin: https://$DOMAIN/admin"
echo "Screen: https://$DOMAIN/client"
echo "===================================================="
_env_files:
cmds:
- |
echo "Copying .env.example to .env.local..."
cp .env.example .env.local
- |
if [ ! -f .env.docker.local ]; then
echo ".env.docker.local does not exist. Copying .env.docker.example to .env.docker.local..."
cp .env.docker.example .env.docker.local
fi
_dc_compile:
deps:
- _env_files
cmds:
- |
COMPOSE_FILES="-f docker-compose.server.yml"
if grep -q '^INTERNAL_DATABASE=true' .env.docker.local; then
COMPOSE_FILES="$COMPOSE_FILES -f docker-compose.mariadb.yml"
fi
if grep -q '^INTERNAL_PROXY=true' .env.docker.local; then
COMPOSE_FILES="$COMPOSE_FILES -f docker-compose.traefik.yml"
fi
docker compose --env-file .env.local --env-file .env.docker.local $COMPOSE_FILES config > docker-compose.yml
# Replace all occurrences of demo.os2display.dk with the value of COMPOSE_SERVER_DOMAIN
DOMAIN=$(grep ^COMPOSE_SERVER_DOMAIN= .env.docker.local | cut -d '=' -f 2)
if [ -n "$DOMAIN" ]; then
sed -i "s/demo\.os2display\.dk/$DOMAIN/g" docker-compose.yml
fi