Skip to content

Commit

Permalink
feat: deploy with supervisor (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyb committed Feb 2, 2024
1 parent 873808d commit 0866b05
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
24 changes: 23 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
FROM python:3

ENV PYTHONUNBUFFERED 1
ENV \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100

# SUPERVISOR
# https://github.com/dockerfile/supervisor/blob/master/Dockerfile
RUN pip install --no-cache-dir supervisor \
&& mkdir /etc/supervisor/ /etc/supervisor/conf.d/ \
&& echo_supervisord_conf > /etc/supervisor/supervisord.conf \
&& sed -i 's/nodaemon=false/nodaemon=true/' /etc/supervisor/supervisord.conf \
&& echo '[include]' >> /etc/supervisor/supervisord.conf \
&& echo 'files = /etc/supervisor/conf.d/*.conf' >> /etc/supervisor/supervisord.conf
VOLUME ["/etc/supervisor/conf.d"]
ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]

RUN pip install --no-cache-dir gunicorn py-spy

WORKDIR /app
COPY ./requirements.txt /app/
RUN pip install --no-cache-dir \
--trusted-host mirrors.aliyun.com \
-i https://mirrors.aliyun.com/pypi/simple/ \
-r requirements.txt
ADD ./supervisor.conf /etc/supervisor/conf.d/app.conf
ADD ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["bash", "/entrypoint.sh"]
ADD . /app
EXPOSE 8000
CMD /app/entrypoint.sh
9 changes: 5 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash

sed -i "s/--workers [[:digit:]]* /--workers ${WORKERS:-2} /" /etc/supervisor/conf.d/app.conf

cd /app/
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py runserver 0.0.0.0:8000 &
wait -n
exit $?
supervisord --nodaemon -c /etc/supervisor/supervisord.conf
13 changes: 13 additions & 0 deletions supervisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[program:app]
command = gunicorn --workers 2 --bind 0.0.0.0:8000 drf_passwordless_jwt.wsgi:application
autostart = true
autorestart = true
startsecs = 0
stopwaitsecs = 0
stdout_logfile_maxbytes = 10MB
stdout_logfile_backups = 30
stdout_logfile = /tmp/app-access.log
stderr_logfile = /tmp/app-error.log
access_logfile = /tmp/app-access.log
error_logfile = -
log_level = info

0 comments on commit 0866b05

Please sign in to comment.