-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
116 lines (99 loc) · 4.08 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
109
110
111
112
113
114
115
116
FROM ubuntu:24.04 AS base-all-0
LABEL maintainer Camptocamp "[email protected]"
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]
RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
apt-get update \
&& apt-get upgrade --assume-yes \
&& apt-get install --assume-yes --no-install-recommends python3-pip python3-venv \
&& python3 -m venv /venv
ENV PATH=/venv/bin:$PATH
# Used to convert the locked packages by poetry to pip requirements format
# We don't directly use `poetry install` because it force to use a virtual environment.
FROM base-all-0 AS poetry
# Install Poetry
WORKDIR /tmp
COPY requirements.txt ./
RUN --mount=type=cache,target=/root/.cache \
python3 -m pip install --disable-pip-version-check --requirement=requirements.txt
# Do the conversion
COPY poetry.lock pyproject.toml ./
ENV POETRY_DYNAMIC_VERSIONING_BYPASS=0.0.0
RUN poetry export --extras=all --output=requirements.txt \
&& poetry export --extras=all --with=dev --output=requirements-dev.txt
# Base, the biggest thing is to install the Python packages
FROM base-all-0 AS base-all
# The /poetry/requirements.txt file is build with the command
# poetry export --extras=all --output=requirements.txt, see above
# hadolint ignore=SC2086
RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
--mount=type=cache,target=/root/.cache \
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
apt-get update \
&& DEV_PACKAGES="libpq-dev build-essential python3-dev" \
&& apt-get install --yes --no-install-recommends \
libpq5 curl postgresql-client net-tools iputils-ping gnupg apt-transport-https \
$DEV_PACKAGES \
&& python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements.txt \
&& strip /venv/lib/python3.*/site-packages/*/*.so \
&& apt-get remove --purge --autoremove --yes $DEV_PACKAGES binutils
ENV LOG_TYPE=console \
LOG_HOST=localhost \
LOG_PORT=514 \
SQL_LOG_LEVEL=WARN \
GUNICORN_LOG_LEVEL=WARN \
OTHER_LOG_LEVEL=WARN \
DEVELOPMENT=0 \
PKG_CONFIG_ALLOW_SYSTEM_LIBS=OHYESPLEASE
FROM base-all AS base-lint
# The /poetry/requirements.txt file is build with the command
# poetry export --extras=all --with=dev --output=requirements-dev.txt, see above
RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,from=poetry,source=/tmp,target=/poetry \
python3 -m pip install --disable-pip-version-check --no-deps --requirement=/poetry/requirements-dev.txt
FROM base-all AS base
WORKDIR /opt/c2cwsgiutils
COPY c2cwsgiutils ./c2cwsgiutils
COPY pyproject.toml README.md ./
# The sed is to deactivate the poetry-dynamic-versioning plugin.
ENV POETRY_DYNAMIC_VERSIONING_BYPASS=dev
RUN --mount=type=cache,target=/root/.cache \
python3 -m pip install --disable-pip-version-check --no-deps --editable=. \
&& python3 -m compileall -q \
&& python3 -m compileall /usr/local/lib/python3.* /usr/lib/python3.* . -q \
&& python3 -c 'import c2cwsgiutils' \
&& mkdir -p /prometheus-metrics \
&& chmod a+rwx /prometheus-metrics
ENV C2C_BASE_PATH=/c2c \
C2C_REDIS_URL= \
C2C_REDIS_SENTINELS= \
C2C_REDIS_SERVICENAME=mymaster \
C2C_REDIS_DB=0 \
C2C_REDIS_OPTIONS=socket_timeout=3 \
C2C_BROADCAST_PREFIX=broadcast_api_ \
C2C_REQUEST_ID_HEADER= \
C2C_REQUESTS_DEFAULT_TIMEOUT= \
C2C_SQL_PROFILER_ENABLED=0 \
C2C_PROFILER_PATH= \
C2C_PROFILER_MODULES= \
C2C_DEBUG_VIEW_ENABLED=0 \
C2C_LOG_VIEW_ENABLED=0 \
C2C_DB_MAINTENANCE_VIEW_ENABLED=0 \
C2C_ENABLE_EXCEPTION_HANDLING=0 \
SENTRY_URL= \
SENTRY_CLIENT_ENVIRONMENT=dev \
SENTRY_CLIENT_RELEASE=latest \
SENTRY_TAG_SERVICE=app
CMD ["/venv/bin/gunicorn"]
COPY production.ini /app/
FROM base-lint AS tests
WORKDIR /opt/c2cwsgiutils
COPY c2cwsgiutils ./c2cwsgiutils
COPY pyproject.toml README.md ./
# The sed is to deactivate the poetry-dynamic-versioning plugin.
ARG VERSION=dev
RUN --mount=type=cache,target=/root/.cache \
POETRY_DYNAMIC_VERSIONING_BYPASS=${VERSION} python3 -m pip install --disable-pip-version-check --no-deps --editable=. \
&& python3 -m pip freeze > /requirements.txt
FROM base AS standard