Newer
Older
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
###########
# BUILDER #
###########
# pull official base image
FROM python:3.8.1 as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN apt-get -y update
RUN apt-get install -y python python-pip python-dev python-django-extensions postgresql-client netcat
RUN apt-get -y update && apt-get -y autoremove
# lint
RUN pip install --upgrade pip
RUN pip install flake8
COPY ./src /usr/src/app/
#RUN flake8 --max-line-length=125 --exclude=kszkepzes,migrations .
# install dependencies
COPY ./requirements/production.txt /usr/src/app/requirements.txt
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.8.1
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN groupadd app && useradd -g app app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/kszkepzes-backend
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install dependencies
RUN apt-get -y update && apt-get install netcat -y
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 entrypoint-prod.sh
COPY ./src/entrypoint.prod.sh $APP_HOME
# copy project
COPY ./src $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.sh
ENTRYPOINT ["/home/app/kszkepzes-backend/entrypoint.prod.sh"]