-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
82 lines (59 loc) · 1.93 KB
/
dockerfile
File metadata and controls
82 lines (59 loc) · 1.93 KB
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
###########################################
# base
###########################################
ARG BASE_IMAGE=python:3.9.17-slim-buster
FROM "${BASE_IMAGE}" as base
ENV PYTHONUNBUFFERED=True
ENV PIP_NO_CACHE_DIR=True
# Install the python package managers.
RUN pip install -U \
pip==23.0.1 \
setuptools==58.1.0 \
wheel==0.43.0 \
poetry==1.6.1
# Set this folder at the system root and then cd into it.
ENV HOME=/usr/src/app
RUN mkdir -p $HOME
WORKDIR $HOME
ENV POETRY_VIRTUALENVS_IN_PROJECT=True
# Copy poetry's package list
COPY poetry.lock pyproject.toml ./
RUN poetry install --no-root --without=dev
# Override the CMD because we don't really need to run anything here
CMD ["python3"]
###########################################
# dev
###########################################
FROM base as dev
WORKDIR /usr/src/app
COPY my_app ./my_app
# Install everything including dev dependencies because this is dev
RUN poetry install --extras=type_tests
ENV FLASK_APP=my_app.app
ENV FLASK_ENV=development
EXPOSE 5000
CMD poetry run flask run
###########################################
# build
###########################################
FROM base as build
WORKDIR /usr/src/app
# Copy the contents of the project root directory to the app directory in the container
COPY . .
RUN poetry build --format wheel | grep "Built" | sed 's/^.*\s\(.*\.whl\)/\1/' > package_name
# Override the CMD because we don't really need to run anything here
CMD ["python3"]
###########################################
# production
###########################################
FROM base
# ==> Add user code layer
ENV HOME=/usr/src/app
RUN mkdir -p $HOME
WORKDIR $HOME
# Copy our python package (wheel file, output of `poetry build`) and install it
COPY --from=build /usr/src/app/dist repo_package
COPY --from=build /usr/src/app/package_name package_name
RUN pip install --no-cache-dir repo_package/$(cat package_name)
# docker-compose will override the CMD
CMD ["python3"]