-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
84 lines (57 loc) · 1.77 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
FROM python:3.12-slim as python-base
LABEL maintainer="ALERT <alexey.rubasheff@gmail.com>"
ENV \
BASE_DIR=/app \
SOURCE_DIR_NAME=source
WORKDIR $BASE_DIR
ENV \
# Python
PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=utf-8 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
# pip
PIP_DISABLE_PIP_VERSION_CHECK=on \
# poetry
POETRY_HOME="$BASE_DIR/poetry" \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
# venv and requirements path
VIRTUAL_ENV="$BASE_DIR/venv" \
# cache path is HOME/.cache
CACHE_PATH="/root/.cache" \
SOURCE_PATH="$BASE_DIR/$SOURCE_DIR_NAME"
ENV PATH="$POETRY_HOME/bin:$VIRTUAL_ENV/bin:$PATH"
RUN python -m venv $VIRTUAL_ENV
ENV PYTHONPATH="$BASE_DIR:$PYTHONPATH"
FROM python-base as builder-base
RUN \
apt-get update \
&& apt-get install -y curl --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN --mount=type=cache,target=$CACHE_PATH \
curl -sSL https://install.python-poetry.org | python -
WORKDIR $BASE_DIR
COPY poetry.lock pyproject.toml ./
RUN --mount=type=cache,target=$CACHE_PATH \
poetry install --no-root --only main --compile
FROM builder-base as development
WORKDIR $BASE_DIR
RUN --mount=type=cache,target=$CACHE_PATH \
poetry install --no-root --compile
CMD ["bash"]
FROM python-base as production
RUN \
apt-get update \
&& apt-get install -y --no-install-recommends dumb-init \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $VIRTUAL_ENV $VIRTUAL_ENV
WORKDIR $BASE_DIR
COPY poetry.lock pyproject.toml ./
COPY $SOURCE_DIR_NAME ./$SOURCE_DIR_NAME/
VOLUME /data
ENTRYPOINT ["dumb-init", "--"]
CMD ["sh", "-c", "python -m $SOURCE_DIR_NAME"]