1+ ###########
2+ # BUILDER #
3+ ###########
4+
5+ # pull official base image
6+ FROM python:3.8.3-slim-buster as builder
7+
8+ # install system dependencies
9+ RUN apt-get update \
10+ && apt-get -y install gcc postgresql \
11+ && apt-get clean
12+
13+ # set work directory
14+ WORKDIR /usr/src/app
15+
16+ # set environment varibles
17+ ENV PYTHONDONTWRITEBYTECODE 1
18+ ENV PYTHONUNBUFFERED 1
19+
20+ # install dependencies
21+ RUN pip install --upgrade pip
22+ COPY ./requirements.txt .
23+ RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
24+
25+ # lint
26+ COPY . /usr/src/app/
27+ RUN pip install black flake8 isort
28+ RUN flake8 .
29+ RUN black --exclude=migrations .
30+ RUN isort ./**/*.py
31+
32+
33+ #########
34+ # FINAL #
35+ #########
36+
137# pull official base image
238FROM python:3.8.3-slim-buster
339
@@ -13,7 +49,7 @@ ENV APP_HOME=/home/app/web
1349RUN mkdir $APP_HOME
1450WORKDIR $APP_HOME
1551
16- # set environment varibles
52+ # set environment variables
1753ENV PYTHONDONTWRITEBYTECODE 1
1854ENV PYTHONUNBUFFERED 1
1955ENV ENVIRONMENT prod
@@ -25,15 +61,16 @@ RUN apt-get update \
2561 && apt-get clean
2662
2763# install python dependencies
64+ COPY --from=builder /usr/src/app/wheels /wheels
65+ COPY --from=builder /usr/src/app/requirements.txt .
2866RUN pip install --upgrade pip
29- COPY ./requirements.txt .
30- RUN pip install -r requirements.txt
67+ RUN pip install --no-cache /wheels/*
3168
3269# add app
3370COPY . .
3471
3572# chown all the files to the app user
36- RUN chown -R app:app $APP_HOME
73+ RUN chown -R app:app $HOME
3774
3875# change to the app user
3976USER app
0 commit comments