Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions {{ cookiecutter.name }}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ FROM base AS web
HEALTHCHECK --interval=15s --timeout=15s --start-period=15s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost:8000/api/v1/healthchecks/

CMD ["sh", "-c", "python manage.py migrate && uwsgi --master --http=:8000 --venv=/code/.venv/ --wsgi=app.wsgi --workers=2 --threads=2 --harakiri=25 --max-requests=1000 --log-x-forwarded-for --logformat '%(addr) - - [%(ltime)] \"%(method) %(uri) %(proto)\" %(status) %(size) \"%(referer)\" \"%(uagent)\"'"]
CMD ["sh", "-c", "python manage.py migrate \
&& exec uwsgi \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь и в других местах: exec убирает sh из цепочки tini → sh → приложение.

Почему нужно: dash (shell-оболочка в контейнере) не передаёт SIGTERM дальше, а выходит сам, и uwsgi с celery про остановку не узнают. То есть когда добавили tini, контейнеры стали быстро завершаться, но по факту убивались, т.к. сигнал для корректной остановки не доходил до приложения.

--master \
--die-on-term \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

без этого uwsgi релоадит воркеров, а не останавливается

--http=:8000 \
--venv=/code/.venv/ \
--wsgi=app.wsgi \
--workers=2 \
--threads=2 \
--harakiri=25 \
--max-requests=1000 \
--log-x-forwarded-for \
--logformat '%(addr) - - [%(ltime)] \"%(method) %(uri) %(proto)\" %(status) %(size) \"%(referer)\" \"%(uagent)\"'"]

#
# worker image
Expand All @@ -81,9 +93,17 @@ FROM base AS worker

ENV _CELERY_APP=app.celery
HEALTHCHECK --interval=15s --timeout=15s --start-period=5s --retries=3 \
CMD celery --app=${_CELERY_APP} inspect ping --destination=$QUEUE@$HOSTNAME

CMD ["sh", "-c", "celery --app=${_CELERY_APP} worker --concurrency=${CONCURRENCY:-2} --hostname=celery@%h --max-tasks-per-child=${MAX_REQUESTS_PER_CHILD:-50} --time-limit=${TIME_LIMIT:-900} --soft-time-limit=${SOFT_TIME_LIMIT:-45}"]
CMD celery --app=${_CELERY_APP} inspect ping --destination=${WORKER_NAME:-celery}@$HOSTNAME

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут поправили healthcheck у воркеров: было$QUEUE@$HOSTNAME, но $QUEUE никто не выставляет — оставалось @hostname и хэлсчек падал.


CMD ["sh", "-c", "exec celery \
--app=${_CELERY_APP} \
worker \
--queues=${QUEUES:-celery} \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил флаг с очередями. Его не было, и чтобы запустить второй воркер на другой очереди, приходилось переписывать CMD в Dockerfile. Теперь очередь задаётся через QUEUES, а по умолчанию всё как раньше — celery

--hostname=${WORKER_NAME:-celery}@%h \
--concurrency=${CONCURRENCY:-2} \
--max-tasks-per-child=${MAX_REQUESTS_PER_CHILD:-50} \
--time-limit=${TIME_LIMIT:-900} \
--soft-time-limit=${SOFT_TIME_LIMIT:-45}"]

#
# scheduler image
Expand All @@ -98,4 +118,8 @@ VOLUME ${_SCHEDULER_DB_PATH}

ENV _CELERY_APP=app.celery
HEALTHCHECK NONE
CMD ["sh", "-c", "celery --app=${_CELERY_APP} beat --pidfile=/tmp/celerybeat.pid --schedule=${_SCHEDULER_DB_PATH}/celerybeat-schedule.db"]
CMD ["sh", "-c", "exec celery \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь и везде переписал аргументы в столбик: так понятнее дифы и блеймы смотреть, что к чему относиться и комментить в PR :)

--app=${_CELERY_APP} \
beat \
--pidfile=/tmp/celerybeat.pid \
--schedule=${_SCHEDULER_DB_PATH}/celerybeat-schedule.db"]
Loading