run nginx and gunicorn with supervisord in container
This commit is contained in:
parent
92bf7fbf75
commit
805e2911f8
11
Dockerfile
11
Dockerfile
|
@ -4,23 +4,24 @@ WORKDIR /app
|
|||
# set env
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
EXPOSE 8000
|
||||
|
||||
RUN apk update \
|
||||
&& apk add postgresql-dev gcc python3-dev musl-dev gettext postgresql-client
|
||||
# install required packages
|
||||
RUN apk add --no-cache postgresql-dev gcc python3-dev musl-dev gettext postgresql-client nginx supervisor
|
||||
|
||||
# install dependencies
|
||||
ADD ./requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
# add supervisor and nginx configs
|
||||
ADD ./docker/nginx.conf /etc/nginx/nginx.conf
|
||||
ADD ./docker/supervisord.conf /etc/supervisord.conf
|
||||
|
||||
# add user
|
||||
RUN addgroup -S portier && adduser -S portier -G portier
|
||||
|
||||
# add code
|
||||
ADD --chown=portier:portier . /app
|
||||
|
||||
RUN ./manage.py collectstatic --noinput --link
|
||||
RUN ./manage.py compilemessages
|
||||
USER portier
|
||||
|
||||
CMD ["/app/start.sh", "migrate_start"]
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
version: '2.4'
|
||||
|
||||
services:
|
||||
web:
|
||||
app:
|
||||
build: .
|
||||
ports:
|
||||
- 8000:8000
|
||||
- 80:80
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
user nginx;
|
||||
worker_processes auto;
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile on;
|
||||
tcp_nodelay on;
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8000;
|
||||
}
|
||||
location /static {
|
||||
alias /app/staticfiles;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
[supervisord]
|
||||
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
|
||||
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
|
||||
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
|
||||
loglevel=info ; (log level;default info; others: debug,warn,trace)
|
||||
nodaemon=true ; (start in foreground if true;default false)
|
||||
user=root
|
||||
|
||||
[program:gunicorn]
|
||||
directory=/app
|
||||
command=/usr/local/bin/gunicorn -w 4 --bind 127.0.0.1:8000 portier.wsgi
|
||||
autostart=true
|
||||
autorestart=true
|
||||
priority=5
|
||||
stdout_events_enabled=true
|
||||
stderr_events_enabled=true
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
user=portier
|
||||
|
||||
[program:nginx]
|
||||
command=/usr/sbin/nginx -g 'pid /tmp/nginx.pid; daemon off;'
|
||||
autostart=true
|
||||
autorestart=true
|
||||
priority=10
|
||||
stdout_events_enabled=true
|
||||
stderr_events_enabled=true
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
32
start.sh
32
start.sh
|
@ -1,10 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
migrate() {
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
}
|
||||
|
||||
wait_for_redis() {
|
||||
echo "Trying to connect to redis at ${REDIS_HOST:-redis}:${REDIS_PORT:-6379} ..."
|
||||
while ! nc -z ${REDIS_HOST:-redis} ${REDIS_PORT:-6379};
|
||||
|
@ -23,21 +18,12 @@ wait_for_database() {
|
|||
echo "Successfully connected to database. Continuing.";
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"create_superuser" )
|
||||
wait_for_redis
|
||||
wait_for_database
|
||||
python manage.py createsuperuser --no-input --username "${ADMIN_USER:-admin}" --email "${ADMIN_EMAIL:-post@chaoswest.tv}"
|
||||
;;
|
||||
"migrate_start" )
|
||||
wait_for_redis
|
||||
wait_for_database
|
||||
migrate
|
||||
gunicorn -w 4 --bind 0.0.0.0:${EXPOSE_PORT:-8000} portier.wsgi
|
||||
;;
|
||||
"only_start" )
|
||||
wait_for_redis
|
||||
wait_for_database
|
||||
gunicorn -w 4 --bind 0.0.0.0:${EXPOSE_PORT:-8000} portier.wsgi
|
||||
;;
|
||||
esac
|
||||
migrate() {
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
}
|
||||
|
||||
wait_for_redis
|
||||
wait_for_database
|
||||
migrate
|
||||
supervisord -n -c /etc/supervisord.conf
|
||||
|
|
Loading…
Reference in New Issue