-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
58 lines (39 loc) · 1.29 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
50
51
52
53
54
55
56
57
58
FROM python:3.10.7 as base
WORKDIR /usr/src/app
ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1
FROM base as poetry
ENV PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
POETRY_VERSION=1.2.1
RUN --mount=type=cache,target=/root/.cache/pip \
pip install "poetry==$POETRY_VERSION"
FROM poetry as build
COPY poetry.lock ./
COPY pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache/pypoetry/cache \
--mount=type=cache,target=/root/.cache/pypoetry/artifacts \
poetry install --sync --no-root --no-interaction --no-ansi
COPY . ./
RUN make build
FROM poetry as install
RUN python -m venv /opt/venv
COPY poetry.lock ./
COPY pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache/pip \
poetry export -f requirements.txt | /opt/venv/bin/pip install -r /dev/stdin
COPY --from=build /usr/src/app .
RUN /opt/venv/bin/pip install --no-deps dist/*.whl
FROM base as app
RUN addgroup --gid 10000 python \
&& useradd --gid 10000 --uid 10000 python
COPY --from=install /opt/venv /opt/venv
ENV PYAPP_ENV=production \
PYAPP_CONFIG_PATH=/usr/src/app/config \
PORT=8080
EXPOSE 8080
ENTRYPOINT ["/opt/venv/bin/python"]
CMD ["-m", "makenew_python_app"]
USER python
LABEL org.opencontainers.image.source https://github.com/makenew/python-app