forked from amerkurev/django-docker-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
65 lines (54 loc) · 1.95 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:3.11-alpine as base
FROM base as builder
RUN apk update && apk --no-cache add python3-dev libpq-dev && mkdir /install
WORKDIR /install
COPY requirements.txt ./
RUN pip install --no-cache-dir --prefix=/install -r ./requirements.txt
FROM base
ARG USER=user
ARG USER_UID=1001
ARG PROJECT_NAME=website
ARG GUNICORN_PORT=8000
ARG GUNICORN_WORKERS=2
# the value is in seconds
ARG GUNICORN_TIMEOUT=60
ARG GUNICORN_LOG_LEVEL=info
ARG DJANGO_BASE_DIR=/usr/src/$PROJECT_NAME
ARG DJANGO_STATIC_ROOT=/var/www/static
ARG DJANGO_MEDIA_ROOT=/var/www/media
ARG DJANGO_SQLITE_DIR=/sqlite
# The superuser with the data below will be created only if there are no users in the database!
ARG DJANGO_SUPERUSER_USERNAME=admin
ARG DJANGO_SUPERUSER_PASSWORD=admin
ARG DJANGO_DEV_SERVER_PORT=8000
ENV \
USER=$USER \
USER_UID=$USER_UID \
PROJECT_NAME=$PROJECT_NAME \
GUNICORN_PORT=$GUNICORN_PORT \
GUNICORN_WORKERS=$GUNICORN_WORKERS \
GUNICORN_TIMEOUT=$GUNICORN_TIMEOUT \
GUNICORN_LOG_LEVEL=$GUNICORN_LOG_LEVEL \
DJANGO_BASE_DIR=$DJANGO_BASE_DIR \
DJANGO_STATIC_ROOT=$DJANGO_STATIC_ROOT \
DJANGO_MEDIA_ROOT=$DJANGO_MEDIA_ROOT \
DJANGO_SQLITE_DIR=$DJANGO_SQLITE_DIR \
DJANGO_SUPERUSER_USERNAME=$DJANGO_SUPERUSER_USERNAME \
DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD \
DJANGO_SUPERUSER_EMAIL=$DJANGO_SUPERUSER_EMAIL \
DJANGO_DEV_SERVER_PORT=$DJANGO_DEV_SERVER_PORT
COPY --from=builder /install /usr/local
COPY docker-entrypoint.sh /
COPY docker-cmd.sh /
COPY $PROJECT_NAME $DJANGO_BASE_DIR
# User
RUN chmod +x /docker-entrypoint.sh /docker-cmd.sh && \
apk --no-cache add su-exec libpq-dev && \
mkdir -p $DJANGO_STATIC_ROOT $DJANGO_MEDIA_ROOT $DJANGO_SQLITE_DIR && \
adduser -s /bin/sh -D -u $USER_UID $USER && \
chown -R $USER:$USER $DJANGO_BASE_DIR $DJANGO_STATIC_ROOT $DJANGO_MEDIA_ROOT $DJANGO_SQLITE_DIR
WORKDIR $DJANGO_BASE_DIR
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/docker-cmd.sh"]
EXPOSE $GUNICORN_PORT