-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.prod
85 lines (64 loc) · 1.72 KB
/
Dockerfile.prod
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
75
76
77
78
79
80
81
82
83
84
85
###########
# BUILDER #
###########
# Pull official base image
FROM python:3.8.2-alpine as builder
# Set work directory
WORKDIR /usr/src/app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev
# Install Pillow dependencies
RUN apk add jpeg-dev zlib-dev
# Install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
# Lint
COPY . .
RUN pip install black flake8 isort
RUN flake8 .
RUN black --exclude=migrations .
RUN isort ./*/*.py
#########
# FINAL #
#########
# Pull official base image
FROM python:3.8.2-alpine
# Set work directory
WORKDIR /usr/src/app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DEBUG 0
ARG SECRET_KEY
ENV SECRET_KEY $SECRET_KEY
ENV DJANGO_ALLOWED_HOSTS .herokuapp.com
ENV EMAIL_HOST_USER apikey
ARG EMAIL_HOST_PASSWORD
ENV EMAIL_HOST_PASSWORD $EMAIL_HOST_PASSWORD
ARG EMAIL_SENDER_EMAIL
ENV EMAIL_SENDER_EMAIL $EMAIL_SENDER_EMAIL
ENV POSTS_PER_PAGE 6
ENV COMMENTS_PER_PAGE 10
ENV SEARCH_RESULTS_PER_PAGE 20
# Install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev
# Install dependencies
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
# Copy project
COPY . .
# Collect static files
RUN python manage.py collectstatic --noinput
# Add and run as non-root user
RUN adduser -D myuser
USER myuser
# Run gunicorn
CMD gunicorn portfolio_project.wsgi:application --bind 0.0.0.0:$PORT