-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
285 lines (227 loc) · 14.1 KB
/
Copy pathjustfile
File metadata and controls
285 lines (227 loc) · 14.1 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
project_name := "devture-nagadmin"
# A small throwaway image used for preparing `var/` directory ownership.
alpine_container_image := "docker.io/alpine:3.23.5"
# mise data directory - can be overridden via environment variable for CI
mise_data_dir := env("MISE_DATA_DIR", justfile_directory() / "var/mise")
# Auto-trust the project's mise.toml via MISE_TRUSTED_CONFIG_PATHS env var
# (avoids needing `mise trust` on first run)
mise_trusted_config_paths := justfile_directory() / "mise.toml"
# The uid:gid that the php and nagios containers run as (the nagios user inside the
# manios/nagios image). The php container must own the `var/` directories it writes
# to (the Twig cache and the generated Nagios configuration).
container_user := "100:101"
# show help by default
default:
@{{ just_executable() }} --list --justfile {{ justfile() }}
# Runs all components (in the foreground). Defaults to the dev environment;
# pass `prod` (e.g. `just run prod`) to run the production configuration.
run env='dev': _require_app_env_file_or_fail _prepare_deps _prepare_run (docker-compose env "up")
# Runs all components (in the background)
run-bg env='dev': _require_app_env_file_or_fail _prepare_deps _prepare_run (docker-compose env "up -d")
# Stops all components
stop env='dev': (docker-compose env "down")
# Installs PHP dependencies via composer
composer-install: _var-composer-cache
./bin/composer install --optimize-autoloader --ignore-platform-req=php
# Updates PHP dependencies via composer
composer-update: _var-composer-cache
./bin/composer update --optimize-autoloader --ignore-platform-req=php
# Runs static analysis (PHPStan) against the app's PHP code
php-analyze: _prepare_deps
docker compose -f compose.yml -p {{ project_name }} run -T --rm --no-deps --user='{{ container_user }}' php sh -c "cd /code/app && vendor/bin/phpstan analyse -c phpstan.neon"
# Checks PHP code formatting and style (PHP CS Fixer)
php-format-check: _prepare_deps
docker compose -f compose.yml -p {{ project_name }} run -T --rm --no-deps --user='{{ container_user }}' php sh -c "cd /code/app && vendor/bin/php-cs-fixer check --config=.php-cs-fixer.dist.php"
# Fixes PHP code formatting and style (PHP CS Fixer)
php-format: _prepare_deps
docker compose -f compose.yml -p {{ project_name }} run -T --rm --no-deps --user="$(id -u):$(id -g)" php sh -c "cd /code/app && vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php"
# Checks Twig template formatting and style (Twig CS Fixer)
twig-format-check: _prepare_deps
docker compose -f compose.yml -p {{ project_name }} run -T --rm --no-deps --user='{{ container_user }}' php sh -c "cd /code/app && vendor/bin/twig-cs-fixer lint --config=.twig-cs-fixer.dist.php"
# Fixes Twig template formatting and style (Twig CS Fixer)
twig-format: _prepare_deps
docker compose -f compose.yml -p {{ project_name }} run -T --rm --no-deps --user="$(id -u):$(id -g)" php sh -c "cd /code/app && vendor/bin/twig-cs-fixer fix --config=.twig-cs-fixer.dist.php"
# Populates app/frontend/node_modules, so that IDE autocompletion works
js-pull-dependencies: _public-assets-frontend
./bin/node /bin/sh -c 'if [ -d /app/src/node_modules ]; then rm -rf /app/src/node_modules; fi && cp -r /app/node_modules /app/src/node_modules'
# Transpiles React files from the jsx/tsx classes to regular js
js-build: _public-assets-frontend
./bin/node /bin/sh -c 'esbuild /app/src/*.*sx --bundle --minify --sourcemap --external:'react' --outdir=/app/build/'
# Watches and transpiles React files from the jsx/tsx classes to regular js
js-build-continuously: _public-assets-frontend
./bin/node /bin/sh -c 'esbuild /app/src/*.*sx --bundle --minify --sourcemap --external:'react' --outdir=/app/build/ --watch'
# Runs comprehensive analysis on React/TypeScript code (lint + type check)
js-analyze: js-analyze-lint js-analyze-type-check
# Runs ESLint on React/TypeScript code
js-analyze-lint: _public-assets-frontend
./bin/node /bin/sh -c 'cd /app/src && eslint .'
# Runs TypeScript compiler type checking
js-analyze-type-check: _public-assets-frontend
./bin/node /bin/sh -c 'cd /app/src && tsc --noEmit'
# Runs ESLint on React/TypeScript code and auto-fixes issues
js-autofix: _public-assets-frontend
./bin/node /bin/sh -c 'cd /app/src && eslint . --fix'
# Clears the Symfony cache (Symfony rebuilds it on the next request)
cache-clear:
@docker run \
--rm \
--mount type=bind,src={{ justfile_directory() }},dst=/justfile_directory \
{{ alpine_container_image }} \
/bin/sh -c 'rm -rf /justfile_directory/var/cache'
@{{ just_executable() }} --justfile {{ justfile() }} _var-cache
# Initializes the MongoDB database (initial data-set import and indexes creation)
init-database: _var-mongodb-io
docker compose -f compose.yml -p {{ project_name }} run --rm --no-TTY -v $(pwd)/app/src/Devture/Bundle/NagiosBundle/Resources/database:/db-import mongodb /usr/bin/mongoimport -h mongodb -d nagadmin -c time_period --jsonArray --file=/db-import/time_period.json
docker compose -f compose.yml -p {{ project_name }} run --rm --no-TTY -v $(pwd)/app/src/Devture/Bundle/NagiosBundle/Resources/database:/db-import mongodb /usr/bin/mongoimport -h mongodb -d nagadmin -c command --jsonArray --file=/db-import/command.json
docker compose -f compose.yml -p {{ project_name }} run --rm --no-TTY -v $(pwd)/app/src/Devture/Bundle/NagiosBundle/Resources/database:/db-import mongodb /usr/bin/mongoimport -h mongodb -d nagadmin -c host --jsonArray --file=/db-import/host.json
docker compose -f compose.yml -p {{ project_name }} run --rm --no-TTY -v $(pwd)/app/src/Devture/Bundle/NagiosBundle/Resources/database:/db-import mongodb /usr/bin/mongoimport -h mongodb -d nagadmin -c service --jsonArray --file=/db-import/service.json
./bin/container-console init-database
# Performs initial installation and Nagios configuration deployment
install:
./bin/container-console install
# Starts a MongoDB shell
mongodb-shell env='dev': (docker-compose env "exec mongodb sh -c 'mongosh nagadmin'")
# Creates a new gzipped MongoDB database dump (stored in `var/mongodb-io/latest-dump`)
mongodb-dump env='dev': _var-mongodb-io (docker-compose env "exec -T mongodb sh -c 'rm -rf /mongodb-io/latest-dump > /dev/null 2>&1 && mkdir /mongodb-io/latest-dump'") (docker-compose env "exec -T mongodb sh -c 'mongodump --quiet -d nagadmin --gzip -o /mongodb-io/latest-dump'")
# Imports a gzipped MongoDB database dump (found in `var/mongodb-io/import`)
mongodb-import env='dev': _var-mongodb-io (docker-compose env "exec -T mongodb sh -c 'mongorestore --gzip --dir=/mongodb-io/import'")
# Upgrades MongoDB to the version specified in compose.yml by doing a dump and re-import
mongodb-upgrade: _var-mongodb-io
{{ justfile_directory() }}/bin/mongodb-upgrade.sh {{ justfile_directory() }} {{ just_executable() }}
# Internal (not meant to be called directly, but are part of the dependency setup chain)
# Internal - runs a `docker compose` command for the given environment (dev|prod),
# combining the shared compose.yml with the matching compose.<env>.yml override.
docker-compose env *extra_args: _require_root_env_file_or_fail
docker compose -f compose.yml -f compose.{{ env }}.yml -p {{ project_name }} {{ extra_args }}
# Internal - fails early (with guidance) if the repository-root `.env` is missing.
_require_root_env_file_or_fail:
#!/bin/sh
if [ ! -f "{{ justfile_directory() }}/.env" ]; then
echo "Error: missing .env file at {{ justfile_directory() }}/.env" >&2
echo "Copy .env.dist to .env and adjust the values before running this command." >&2
exit 1
fi
# Internal - fails early (with guidance) if the Symfony app `app/.env` is missing.
# Without it, Symfony silently falls back to the committed `app/.env.dist`, whose
# development defaults (APP_ENV=dev, the mailcrab MAILER_DSN, suppressed SMS, a
# public api_secret) are unsafe to run with — especially in production.
_require_app_env_file_or_fail:
#!/bin/sh
if [ ! -f "{{ justfile_directory() }}/app/.env" ]; then
echo "Error: missing app/.env file at {{ justfile_directory() }}/app/.env" >&2
echo "Copy app/.env.dist to app/.env and adjust the values before running this command." >&2
exit 1
fi
# Internal - makes sure PHP dependencies are installed
_prepare_deps:
#!/bin/sh
if [ ! -f app/vendor/autoload.php ]; then
{{ just_executable() }} --justfile {{ justfile() }} composer-install
fi
# Internal - makes sure the runtime directories exist and have the correct ownership
_prepare_run: _var-cache _var-mongodb-io _var-container-data-mongodb _var-nagadmin-generated-config _var-nagios-var _var-container-data-nagios-etc _var-exim-spool _var-nagios-custom-plugins _var-nginx-labels _var-nagios-labels _public-assets-frontend-completed
_public-assets-frontend: (_ensure_dir_created "app/public/assets/frontend")
# Internal - builds the JS bundles once (the `completed` marker prevents rebuilds on every run)
_public-assets-frontend-completed: _public-assets-frontend
#!/bin/sh
if [ ! -f app/public/assets/frontend/completed ]; then
{{ just_executable() }} --justfile {{ justfile() }} js-build
touch app/public/assets/frontend/completed
fi
# Drop-in directory for custom check plugins, mounted read-only into the nagios
# container at /opt/nagios/libexec/custom ($USER1$/custom). Left owned by the
# invoking user (the container only reads it).
_var-nagios-custom-plugins: (_ensure_dir_created "var/nagios-custom-plugins")
# Internal - the nginx (Nagadmin UI) container's reverse-proxy labels. Empty by
# default; populate var/nginx-labels in production to attach a container-native
# reverse proxy such as Traefik (see the README). The empty file is required for
# the compose `label_file` reference to resolve.
_var-nginx-labels:
#!/bin/sh
if [ ! -f var/nginx-labels ]; then
touch var/nginx-labels
fi
# Internal - the nagios (Nagios UI) container's reverse-proxy labels. Empty by
# default; populate var/nagios-labels in production (see _var-nginx-labels).
_var-nagios-labels:
#!/bin/sh
if [ ! -f var/nagios-labels ]; then
touch var/nagios-labels
fi
# The exim-relay mail spool (persistent store-and-forward queue); written by the
# mailer container (runs as {{ container_user }}). Only mounted in production, but
# prepared unconditionally (an empty, correctly-owned directory is harmless in dev).
_var-exim-spool: (_ensure_dir_prepared_recursive "var/container-data/exim-spool")
# The Twig cache, written by the php container (runs as {{ container_user }}).
_var-cache: (_ensure_dir_prepared_recursive "var/cache")
# Composer's download cache, left owned by the invoking user (composer runs as them).
_var-composer-cache: (_ensure_dir_created "var/composer-cache")
# Used for MongoDB dump/import I/O; written by the mongodb container (runs as root).
_var-mongodb-io: (_ensure_dir_created "var/mongodb-io")
# The MongoDB data directory; written by the mongodb container (runs as root).
_var-container-data-mongodb: (_ensure_dir_created "var/container-data/mongodb")
# The generated Nagios configuration, written by the php container (runs as {{ container_user }}).
# The php container writes both into this directory (resource.cfg) and its `configuration/`
# subdirectory, so the whole tree (including this parent dir) must be owned by it.
_var-nagadmin-generated-config: (_ensure_dir_created "var/container-data/nagadmin-generated-config/configuration")
#!/bin/sh
if [ ! -f var/container-data/nagadmin-generated-config/resource.cfg ]; then
touch var/container-data/nagadmin-generated-config/resource.cfg
fi
{{ just_executable() }} --justfile {{ justfile() }} _ensure_dir_prepared_recursive "var/container-data/nagadmin-generated-config"
# The Nagios var directory (state/retention); written by the nagios container.
_var-nagios-var: (_ensure_dir_prepared_recursive "var/container-data/nagios/var")
# The live Nagios base config dir mounted at /opt/nagios/etc. Seeded from the `.dist`
# templates in etc/services/nagios/etc/ on first run (only copying a file if it's missing,
# so the container's runtime changes — use_timezone, htpasswd.users — are preserved across
# runs). The whole dir is owned by {{ container_user }}, as the container writes into it.
_var-container-data-nagios-etc: (_ensure_dir_created "var/container-data/nagios/etc")
#!/bin/sh
for f in nagios.cfg cgi.cfg; do
if [ ! -f "var/container-data/nagios/etc/$f" ]; then
cp "etc/services/nagios/etc/$f.dist" "var/container-data/nagios/etc/$f"
fi
done
{{ just_executable() }} --justfile {{ justfile() }} _ensure_dir_prepared_recursive "var/container-data/nagios/etc"
# Internal - ensures a directory exists (created if missing).
_ensure_dir_created path:
#!/bin/sh
if [ ! -d {{ path }} ]; then
mkdir -p {{ path }}
fi
# Internal - ensures a directory exists and (re-)asserts its ownership recursively.
# Runs on every `_prepare_run`, so a pre-existing mis-owned directory gets corrected.
_ensure_dir_prepared_recursive path: (_ensure_dir_created path)
@docker run \
--rm \
--mount type=bind,src={{ justfile_directory() }},dst=/justfile_directory \
{{ alpine_container_image }} \
/bin/sh -c 'chown -R {{ container_user }} /justfile_directory/{{ path }}'
# Pre-commit hooks (prek)
# Invokes mise with the project-local data directory
mise *args: _ensure_mise_data_directory
#!/bin/sh
export MISE_DATA_DIR="{{ mise_data_dir }}"
export MISE_TRUSTED_CONFIG_PATHS="{{ mise_trusted_config_paths }}"
mise {{ args }}
# Runs prek (pre-commit hooks manager) with the given arguments
prek *args: _ensure_mise_tools_installed
@just --justfile {{ justfile() }} mise exec -- prek {{ args }}
# Runs pre-commit hooks on staged files
prek-run-on-staged *args: _ensure_mise_tools_installed
@just --justfile {{ justfile() }} mise exec -- prek run {{ args }}
# Runs pre-commit hooks on all files
prek-run-on-all *args: _ensure_mise_tools_installed
@just --justfile {{ justfile() }} mise exec -- prek run --all-files {{ args }}
# Installs the git pre-commit hook (runs prek automatically before each commit)
prek-install-git-pre-commit-hook: _ensure_mise_tools_installed
@just --justfile {{ justfile() }} mise exec -- prek install
# Internal - ensures the mise data directory exists
_ensure_mise_data_directory:
#!/bin/sh
if [ ! -d "{{ mise_data_dir }}" ]; then
mkdir -p "{{ mise_data_dir }}"
fi
# Internal - ensures mise tools are installed
_ensure_mise_tools_installed: _ensure_mise_data_directory
@just --justfile {{ justfile() }} mise install --quiet