-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile-django.production
74 lines (57 loc) · 2.54 KB
/
Dockerfile-django.production
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
66
67
68
69
70
71
72
73
74
# Production Dockerfile for Django app
FROM python:3.6.8-alpine3.8
ENV DJANGO_PRODUCTION_MODE 1
# Set the default directory where CMD will execute
WORKDIR /app
# Create a directory for the logs
RUN mkdir -p /var/log/parrot_mania
# Copy wait-for-it.sh script
COPY ./wait-for-it.sh /usr/bin/
# Expose our application port
EXPOSE 80
# Install bash and gettext
# Bash is required to support `wait-for-it.sh` script, should not add too much to docker image
RUN apk add --no-cache bash gettext
# Install build dependencies and mark them as virtual package so they could be removed together
RUN apk add --no-cache --virtual .build-deps \
ca-certificates alpine-sdk postgresql-dev python3-dev linux-headers musl-dev \
libffi-dev jpeg-dev zlib-dev
# Install bash, libpq and gettext
# Bash is required to support `wait-for-it.sh` script, should not add too much to docker image
RUN apk add --no-cache bash gettext libpq
# Install build dependencies and mark them as virtual packages so they could be removed together
RUN apk add --no-cache --virtual .build-deps \
ca-certificates alpine-sdk postgresql-dev python3-dev linux-headers musl-dev \
libffi-dev libxml2-dev libxslt-dev jpeg-dev zlib-dev
# Copy Python requirements dir and Install requirements
RUN pip install -U pipenv==2018.11.26 pip setuptools wheel
COPY Pipfile /
COPY Pipfile.lock /
# Install all dependencies from Pipfile.lock file
RUN pipenv install --system --ignore-pipfile
# Find all file objects containing name `test` or compiled python files and remove them
# Find all runtime dependencies that are marked as needed by scanelf
# scanelf is utility to show ELF data for binary objects
# For more info: https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities#The_scanelf_application
# Finally re-install missing run-dependencies
RUN find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps
# Remove build dependencies
RUN apk del .build-deps
# Copy code
COPY ./parrot_mania /app
# Compile translations to .mo files
# Un-comment this when locale directory has been created
#RUN python manage.py compilemessages
# Run Gunicorn by default
CMD gunicorn parrot_mania.wsgi:application --workers 2 --bind :80