diff --git a/Dockerfile b/Dockerfile index aa4902b..aa894ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,23 @@ FROM python:3.8-alpine WORKDIR /app -ADD . /app + +# set env +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 +EXPOSE 8000 + +# psycopg2 dependencies +RUN apk update \ + && apk add postgresql-dev gcc python3-dev musl-dev + +# install dependencies +ADD ./requirements.txt . RUN pip install -r requirements.txt + +# add user +RUN addgroup -S portier && adduser -S portier -G portier + +# add code +ADD --chown=portier:portier . /app + +CMD ["/app/start.sh", "migrate_start"] diff --git a/requirements.txt b/requirements.txt index a0410b5..f6d3d64 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ django>=3.0 celery>=4.4 +gunicorn>=20 diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..27c37b8 --- /dev/null +++ b/start.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +migrate() { + python manage.py makemigrations + python manage.py migrate +} + +case $1 in + "create_superuser" ) + python manage.py createsuperuser --no-input --username "${ADMIN_USER:-admin}" --email "${ADMIN_EMAIL:-post@chaoswest.tv}" + ;; + "migrate_start" ) + migrate + gunicorn -w 4 --bind 0.0.0.0:${EXPOSE_PORT:-8000} portier.wsgi + ;; + "only_start" ) + gunicorn -w 4 --bind 0.0.0.0:${EXPOSE_PORT:-8000} portier.wsgi + ;; +esac