forked from NannyML/nannyml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
108 lines (87 loc) · 2.39 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Author: Niels Nuyttens <niels@nannyml.com>
#
# License: Apache Software License 2.0
## Thank you Michael Oliver
## https://github.com/michaeloliverx/python-poetry-docker-example/blob/master/docker/Dockerfile
## Thank you Baptiste Maingret
## https://github.com/bmaingret/coach-planner/blob/main/docker/Dockerfile
ARG APP_NAME=nannyml
ARG APP_PATH=/opt/$APP_NAME
ARG PYTHON_VERSION=3.10.0-slim-bullseye
ARG POETRY_VERSION=1.3.2
#
# Stage: staging
#
FROM python:$PYTHON_VERSION as staging
ARG APP_NAME
ARG APP_PATH
ARG POETRY_VERSION
ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1
ENV \
POETRY_VERSION=$POETRY_VERSION \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1
RUN apt-get update && \
apt-get install --no-install-recommends -y \
curl \
build-essential
# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION
ENV PATH="$POETRY_HOME/bin:$PATH"
# Import our project files
WORKDIR $APP_PATH
COPY ./poetry.lock ./pyproject.toml ./
COPY . .
#
# Stage: development
#
FROM staging as development
ARG APP_NAME
ARG APP_PATH
ENV POETRY_INSTALLER_MAX_WORKERS=10
# Install project in editable mode and with development dependencies
WORKDIR $APP_PATH
RUN poetry install
ENTRYPOINT ["poetry", "run"]
CMD ["nml"]
#
# Stage: build
#
FROM staging as build
ARG APP_PATH
WORKDIR $APP_PATH
RUN poetry build --format wheel
RUN poetry export --format requirements.txt --output constraints.txt --without-hashes
#
# Stage: production
#
FROM python:$PYTHON_VERSION as production
ARG APP_NAME
ARG APP_PATH
ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1
ENV \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100
# LightGBM dependency
RUN apt-get update && \
apt-get install --no-install-recommends -y \
libgomp1
# Get build artifact wheel and install it respecting dependency versions
WORKDIR $APP_PATH
COPY --from=build $APP_PATH/dist/*.whl ./
COPY --from=build $APP_PATH/constraints.txt ./
RUN pip install ./$APP_NAME*.whl --constraint constraints.txt
RUN useradd --create-home --shell /bin/bash $APP_NAME
WORKDIR /home/$APP_NAME
USER $APP_NAME
# export APP_NAME as environment variable for the CMD
ENV APP_NAME=$APP_NAME
CMD ["sh", "-c", "$APP_NAME"]