-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
65 lines (41 loc) · 1.42 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
FROM python:latest as base
ARG PYTHONDONTWRITEBYTECODE=1
ARG PYTHONUNBUFFERED=1
WORKDIR railway/
RUN python -m venv venv
ENV PATH=/railway/venv/bin:$PATH
RUN pip install --upgrade pip
COPY ./ ./
# Create inline `sh` script
# https://docs.docker.com/engine/reference/builder/#example-creating-inline-files
ENV DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL}
ENV DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
ENV DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME}
COPY <<-"RAILWAY" ./railway.sh
#!/usr/bin/env sh
python manage.py migrate --no-input
# If any of these three environment variables are empty, or not defined, then a superuser is not created
if ! [ -z $DJANGO_SUPERUSER_EMAIL ] && ! [ -z $DJANGO_SUPERUSER_PASSWORD ] && ! [ -z $DJANGO_SUPERUSER_USERNAME ]
then
python manage.py createsuperuser --no-input
fi
RAILWAY
RUN chmod +x ./railway.sh
# Development
FROM base as development
ENV DJANGO_SETTINGS_MODULE=project.settings.development
RUN pip install -r requirements/development.txt
RUN <<CAT cat >> ./railway.sh
python manage.py runserver_plus --nostatic 0.0.0.0:8000
CAT
CMD ./railway.sh
# Production
FROM base as production
ENV DJANGO_SETTINGS_MODULE=project.settings.production
RUN pip install -r requirements/production.txt
RUN <<CAT cat >> ./railway.sh
python manage.py collectstatic --no-input
python manage.py check --deploy
gunicorn project.wsgi
CAT
CMD ./railway.sh