Skip to content

Commit

Permalink
add sample docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 21, 2024
1 parent a2d6ec7 commit 8dfabfc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
53 changes: 11 additions & 42 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,16 @@ x-common: &common
build:
context: .
dockerfile: docker/Dockerfile
target: tests
target: dist
platform: linux/amd64
develop:
watch:
- action: sync
path: .
target: /app/
ignore:
- ./.venv/
- action: sync
path: ./src/country_workspace
target: /app/.venv/lib/python3.12/site-packages/country_workspace
ignore:
- ./.venv/
- action: rebuild
path: uv.lock
environment:
- DEBUG=true
- ADMIN_EMAIL=adm@hcw.org
- ADMIN_PASSWORD=123
- ALLOWED_HOSTS=localhost
- CSRF_COOKIE_SECURE=False
- CSRF_TRUSTED_ORIGINS=http://localhost
- AUTHENTICATION_BACKENDS="country_workspace.security.backends.AnyUserAuthBackend"
- AUTHENTICATION_BACKENDS=country_workspace.security.backends.AnyUserAuthBackend
- HOPE_API_TOKEN=${HOPE_API_TOKEN}
- CACHE_URL=redis://redis:6379/1
- CELERY_BROKER_URL=redis://redis:6379/9
Expand All @@ -52,16 +38,7 @@ services:
<<: *common
ports:
- 8000:8000
# stdin_open: true # docker run -i
# tty: true # docker run -t -
command: ["ls", "-al", "/app/"]
# command: ["ls", "-al", "/app/.venv/lib/python3.12/site-packages/"]
# command: >
# bash -c "
# django-admin upgrade &&
# django-admin demo &&
# django-admin runserver 0.0.0.0:8000
# "
command: run
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/healthcheck"]
interval: 10s
Expand Down Expand Up @@ -99,23 +76,15 @@ services:
interval: 5s
timeout: 4s
retries: 5
#
# celery_worker:
# <<: *common
# # entrypoint: ["sh", "-c", "exec docker-entrypoint.sh \"$0\" \"$@\""]
# # command: worker
# command: >
# sh -c '
# gosu user:app celery -A country_workspace.config.celery worker -E --loglevel=INFO --concurrency=4
# '
#
# celery-beat:
# <<: *common
# command: >
# sh -c '
# gosu user:app celery -A country_workspace.config.celery beat --loglevel=INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
# '

celery_worker:
<<: *common
# entrypoint: ["sh", "-c", "exec docker-entrypoint.sh \"$0\" \"$@\""]
command: worker

celery-beat:
<<: *common
command: beat

volumes:
postgres_data:
8 changes: 5 additions & 3 deletions docker/bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export MEDIA_ROOT="${MEDIA_ROOT:-/var/run/app/media}"
export STATIC_ROOT="${STATIC_ROOT:-/var/run/app/static}"
export UWSGI_PROCESSES="${UWSGI_PROCESSES:-"4"}"
export DJANGO_SETTINGS_MODULE="${DJANGO_SETTINGS_MODULE:-"country_workspace.config.settings"}"
export DJANGO_SETTINGS_MODULE="${DJANGO_SETTINGS_MODULE:-country_workspace.config.settings}"

case "$1" in
run)
Expand All @@ -21,10 +21,12 @@ case "$1" in
$MAPPING
;;
worker)
exec celery -A country_workspace.celery worker -E --loglevel=ERROR --concurrency=4
set -- tini -- "$@"
set -- gosu user:app celery -A country_workspace.config.celery worker -E --loglevel=ERROR --concurrency=4
;;
beat)
exec celery -A country_workspace.celery beat -E --loglevel=ERROR ---scheduler django_celery_beat.schedulers:DatabaseScheduler
set -- tini -- "$@"
set -- gosu user:app celery -A country_workspace.config.celery beat --loglevel=ERROR --scheduler django_celery_beat.schedulers:DatabaseScheduler
;;
esac

Expand Down
31 changes: 31 additions & 0 deletions docker/bin/~docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh -e


export MEDIA_ROOT="${MEDIA_ROOT:-/var/run/app/media}"
export STATIC_ROOT="${STATIC_ROOT:-/var/run/app/static}"
export UWSGI_PROCESSES="${UWSGI_PROCESSES:-"4"}"
export DJANGO_SETTINGS_MODULE="${DJANGO_SETTINGS_MODULE:-"country_workspace.config.settings"}"

case "$1" in
run)
django-admin upgrade --with-check
set -- tini -- "$@"
MAPPING=""
if [ "${STATIC_URL}" = "/static/" ]; then
MAPPING="--static-map ${STATIC_URL}=${STATIC_ROOT}"
fi
uwsgi --http :8000 \
--module country_workspace.config.wsgi \
--uid user \
--gid app \
$MAPPING
;;
worker)
exec celery -A country_workspace.celery worker -E --loglevel=ERROR --concurrency=4
;;
beat)
exec celery -A country_workspace.celery beat -E --loglevel=ERROR ---scheduler django_celery_beat.schedulers:DatabaseScheduler
;;
esac

exec "$@"

0 comments on commit 8dfabfc

Please sign in to comment.