Skip to content

Commit 5c62799

Browse files
dev: hot reloading improvements celery/html/tpl (#12714)
* hot reloading improvements celery/html/tpl * typo * add new entrypoint script
1 parent bccd795 commit 5c62799

8 files changed

+42
-2
lines changed

Dockerfile.django-alpine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ RUN export PYCURL_SSL_LIBRARY=openssl && \
6767
COPY \
6868
docker/entrypoint-celery-beat.sh \
6969
docker/entrypoint-celery-worker.sh \
70+
docker/entrypoint-celery-worker-dev.sh \
7071
docker/entrypoint-initializer.sh \
7172
docker/entrypoint-first-boot.sh \
7273
docker/entrypoint-uwsgi.sh \

Dockerfile.django-debian

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ RUN export PYCURL_SSL_LIBRARY=openssl && \
7070
COPY \
7171
docker/entrypoint-celery-beat.sh \
7272
docker/entrypoint-celery-worker.sh \
73+
docker/entrypoint-celery-worker-dev.sh \
7374
docker/entrypoint-initializer.sh \
7475
docker/entrypoint-first-boot.sh \
7576
docker/entrypoint-uwsgi.sh \

docker-compose.override.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
DD_ADMIN_PASSWORD: "${DD_ADMIN_PASSWORD:-admin}"
1212
DD_EMAIL_URL: "smtp://mailhog:1025"
1313
celeryworker:
14+
entrypoint: ['/wait-for-it.sh', '${DD_DATABASE_HOST:-postgres}:${DD_DATABASE_PORT:-5432}', '-t', '30', '--', '/entrypoint-celery-worker-dev.sh']
1415
volumes:
1516
- '.:/app:z'
1617
environment:

docker-compose.override.integration_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ services:
3838
environment:
3939
DD_DATABASE_URL: ${DD_TEST_DATABASE_URL:-postgresql://defectdojo:defectdojo@postgres:5432/test_defectdojo}
4040
celeryworker:
41+
entrypoint: ['/wait-for-it.sh', '${DD_DATABASE_HOST:-postgres}:${DD_DATABASE_PORT:-5432}', '-t', '30', '--', '/entrypoint-celery-worker-dev.sh']
4142
environment:
4243
DD_DATABASE_URL: ${DD_TEST_DATABASE_URL:-postgresql://defectdojo:defectdojo@postgres:5432/test_defectdojo}
4344
initializer:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
umask 0002
3+
4+
id
5+
6+
set -e # needed to handle "exit" correctly
7+
8+
. /secret-file-loader.sh
9+
. /reach_database.sh
10+
11+
wait_for_database_to_be_reachable
12+
echo
13+
14+
if [ "${DD_CELERY_WORKER_POOL_TYPE}" = "prefork" ]; then
15+
EXTRA_PARAMS=("--autoscale=${DD_CELERY_WORKER_AUTOSCALE_MAX},${DD_CELERY_WORKER_AUTOSCALE_MIN}"
16+
"--prefetch-multiplier=${DD_CELERY_WORKER_PREFETCH_MULTIPLIER}")
17+
else
18+
EXTRA_PARAMS=()
19+
fi
20+
21+
# do the check with Django stack
22+
python3 manage.py check
23+
24+
# hot reload using watmedo as we don't want to install celery[dev] and have that end up in our production images
25+
watchmedo auto-restart --directory=./ --pattern="*.py;*.tpl" --recursive -- \
26+
celery --app=dojo worker --loglevel="${DD_CELERY_LOG_LEVEL}" --pool="${DD_CELERY_WORKER_POOL_TYPE}" --concurrency="${DD_CELERY_WORKER_CONCURRENCY:-1}" "${EXTRA_PARAMS[@]}"

docker/entrypoint-uwsgi-dev.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ if [ "${DD_DEBUG}" = "True" ]; then
2121
DD_UWSGI_NUM_OF_THREADS=1
2222
fi
2323

24+
# hot reload also on html/template changes
25+
watchmedo shell-command \
26+
--patterns="*.html;*.tpl" \
27+
--recursive \
28+
--command='touch /app/dojo/settings/settings.py' \
29+
/app/dojo &
30+
31+
2432
exec uwsgi \
2533
"--${DD_UWSGI_MODE}" "${DD_UWSGI_ENDPOINT}" \
2634
--protocol uwsgi \
@@ -33,5 +41,5 @@ exec uwsgi \
3341
--py-autoreload 1 \
3442
--buffer-size="${DD_UWSGI_BUFFER_SIZE:-8192}" \
3543
--lazy-apps \
36-
--touch-reload="/app/dojo/setting/settings.py" \
44+
--touch-reload="/app/dojo/settings/settings.py" \
3745
--logformat "${DD_UWSGI_LOGFORMAT:-$DD_UWSGI_LOGFORMAT_DEFAULT}"

readme-docs/DOCKER.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ This will run the application based on merged configurations from docker-compose
109109
* python code (uwsgi and celeryworker containers).
110110

111111
* The `--py-autoreload 1` parameter in entrypoint-uwsgi-dev.sh will make uwsgi handle python hot-reloading for the **uwsgi** container.
112-
* Hot-reloading for the **celeryworker** container is not yet implemented. When working on deduplication for example, restart the celeryworker container with:
112+
* Hot-reloading for the **celeryworker** container is implemented via `watchmedo` from the `watchdog` package.
113+
* Changes in `.html` and `.tpl` files will also trigger a roload.
113114

114115
```
115116
docker compose restart celeryworker

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ fontawesomefree==6.6.0
7676
PyYAML==6.0.2
7777
pyopenssl==25.1.0
7878
parameterized==0.9.0
79+
watchdog==6.0.0 # only needed for development, but would require some docker refactoring if we want to exclude it for production images

0 commit comments

Comments
 (0)