-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
49 lines (36 loc) · 1.15 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
# set args
ARG PYTHON_VERSION=3.10
ARG PYTHON_VERSION_SUFFIX=slim-buster
# pull python image from docker hub
FROM python:${PYTHON_VERSION}-${PYTHON_VERSION_SUFFIX} AS builder
# set env values
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# update pip and install pipenv
RUN pip install --no-cache-dir --upgrade \
pip \
pipenv
# create tmp folder
WORKDIR /usr/src/tmp
# copy pipenv files to tmp folder
COPY Pipfile.lock /usr/src/tmp/
# convert Pipfile.lock to requirements.txt
# and install all dependencies by pip
RUN pipenv requirements > requirements.txt && \
pip install --no-cache-dir --target=/usr/src/dependencies \
-r requirements.txt
FROM python:${PYTHON_VERSION}-${PYTHON_VERSION_SUFFIX}
# copy all dependencies into container
COPY --from=builder /usr/src/dependencies /usr/src/dependencies
# instal gunicorn for production server
RUN pip install --no-cache-dir gunicorn
# create backend folder
WORKDIR /usr/src/backend
# copy api to container
COPY . /usr/src/backend
# add dependencies path to env
ENV PYTHONPATH=${PYTHONPATH}:"/usr/src/dependencies"
# remove unnecessary files
RUN rm Pipfile
RUN rm Pipfile.lock
RUN rm -d -r nginx/