-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
94 lines (78 loc) · 2.13 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
##
# base
##
FROM python:3.12-slim AS base
LABEL maintainer="[email protected]"
# set up user
ARG USER=user
ARG UID=1000
RUN useradd --no-create-home --shell /bin/false --uid ${UID} ${USER}
# set up environment
ARG VIRTUAL_ENV=/work/venv
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=${VIRTUAL_ENV} \
PATH=${VIRTUAL_ENV}/bin:${PATH}
ARG APP_HOME=/work/app
WORKDIR ${APP_HOME}
##
# dev
##
FROM base AS dev
ARG DEBIAN_FRONTEND=noninteractive
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update && \
apt-get install --no-install-recommends -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_COMPILE=0 \
PIP_NO_INPUT=1 \
POETRY_NO_INTERACTION=1
# set up python
RUN --mount=type=cache,target=/root/.cache/pip \
pip install poetry && \
python -m venv --upgrade-deps ${VIRTUAL_ENV} && \
chown -R ${USER}:${USER} ${VIRTUAL_ENV} && \
chown -R ${USER}:${USER} ${APP_HOME}
COPY --chown=${USER}:${USER} pyproject.toml poetry.lock ./
RUN --mount=type=cache,target=/root/.cache/pypoetry \
poetry install --only main --no-root && \
python --version && \
pip list
# set up project
USER ${USER}
COPY --chown=${USER}:${USER} src src
RUN --mount=type=cache,target=/root/.cache/pypoetry \
poetry install --only-root
EXPOSE 8000
ARG ENVIRONMENT=dev
ENV ENVIRONMENT ${ENVIRONMENT}
CMD ["gunicorn", "-c", "python:example_app.gunicorn_conf", "--reload"]
##
# ci
##
FROM dev AS ci
USER root
RUN --mount=type=cache,target=/root/.cache/pypoetry \
poetry install && \
pip list
USER ${USER}
COPY --chown=${USER}:${USER} tests tests
COPY --chown=${USER}:${USER} Makefile Makefile
CMD ["make", "lint", "test"]
##
# prod
##
FROM base AS prod
# set up project
USER ${USER}
COPY --from=dev --chown=${USER}:${USER} ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY --from=dev --chown=${USER}:${USER} ${APP_HOME} ${APP_HOME}
EXPOSE 8000
ARG ENVIRONMENT=prod
ENV ENVIRONMENT=${ENVIRONMENT}
CMD ["gunicorn", "-c", "python:example_app.gunicorn_conf"]