Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
255 lines (213 loc) · 9.89 KB
/
Copy pathDockerfile
File metadata and controls
255 lines (213 loc) · 9.89 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# syntax=docker/dockerfile:1
ARG BASE_IMAGE=ubuntu:24.04
FROM ${BASE_IMAGE} AS build-image-base
RUN apt-get -o Acquire::Retries=5 update && \
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -yq \
cargo-1.85 \
curl \
g++ \
gcc \
git \
libhdf5-dev \
libldap2-dev \
libmp3lame-dev \
libsasl2-dev \
make \
nasm \
pkg-config \
python3-dev \
python3-pip \
&& update-alternatives \
--install /usr/bin/rustc rustc /usr/bin/rustc-1.85 185 \
--slave /usr/bin/cargo cargo /usr/bin/cargo-1.85 \
&& rm -rf /var/lib/apt/lists/*
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
# We build OpenH264, FFmpeg and PyAV in a separate build stage,
# because this way Docker can do it in parallel to all the other packages.
FROM build-image-base AS build-image-av
# Compile Openh264 and FFmpeg
ARG PREFIX=/opt/ffmpeg
ARG PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
ENV FFMPEG_VERSION=8.0 \
OPENH264_VERSION=2.6.0
WORKDIR /tmp/openh264
RUN curl -sL https://github.com/cisco/openh264/archive/v${OPENH264_VERSION}.tar.gz --output - | \
tar -zx --strip-components=1 && \
make -j5 && make install-shared PREFIX=${PREFIX} && make clean
WORKDIR /tmp/ffmpeg
RUN curl -sL https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz --output - | \
tar -zx --strip-components=1 && \
./configure --disable-nonfree --disable-gpl --enable-libopenh264 --enable-libmp3lame \
--enable-shared --disable-static --disable-doc --disable-programs --prefix="${PREFIX}" && \
make -j5 && make install && make clean
COPY utils/dataset_manifest/requirements.txt /tmp/utils/dataset_manifest/requirements.txt
# Since we're using pip-compile-multi, each dependency can only be listed in
# one requirements file. In the case of PyAV, that should be
# `dataset_manifest/requirements.txt`. Make sure it's actually there,
# and then remove everything else.
RUN grep -q '^av==' /tmp/utils/dataset_manifest/requirements.txt
RUN sed -i '/^av==/!d' /tmp/utils/dataset_manifest/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip/http-v2 \
python3 -m pip wheel --no-binary=av \
-r /tmp/utils/dataset_manifest/requirements.txt \
-w /tmp/wheelhouse
# This stage builds wheels for all dependencies (except PyAV)
FROM build-image-base AS build-image
COPY cvat/requirements/ /tmp/cvat/requirements/
COPY utils/dataset_manifest/requirements.txt /tmp/utils/dataset_manifest/requirements.txt
# Exclude av from the requirements file
RUN sed -i '/^av==/d' /tmp/utils/dataset_manifest/requirements.txt
ARG CVAT_CONFIGURATION="production"
# The lxml and xmlsec wheels must bundle compatible libxml2 versions.
RUN --mount=type=cache,target=/root/.cache/pip/http-v2 \
DATUMARO_HEADLESS=1 python3 -m pip wheel --no-deps --only-binary lxml,xmlsec \
-r /tmp/cvat/requirements/${CVAT_CONFIGURATION}.txt \
-w /tmp/wheelhouse
# Go 1.27.3 fixes the stdlib findings (CVE-2026-111943). Stripe's 68e7b8218e
# (2026-10-22) still requires golang.org/x/net v0.59.0, so the build raises it to
# v0.62.0 (CVE-2026-78663 and four other advisories fixed in v0.60.0;
# CVE-2026-78661 and CVE-2026-97045 in v0.62.0), re-vendors (smokescreen builds
# from vendor/), and fails if the binary records any other x/net version.
# supervisord starts the binary on 127.0.0.1:4750 with --allow-self-connections.
# Transfer deadlines are set in supervisord/reusable/smokescreen.yaml.
FROM golang:1.27.3 AS build-smokescreen
RUN git clone --filter=blob:none --no-checkout https://github.com/stripe/smokescreen.git
RUN cd smokescreen && git checkout 68e7b8218e226bc47d09ce705fdb8fed82145ceb \
&& go get golang.org/x/net@v0.62.0 && go mod tidy && go mod vendor \
&& go build -o /tmp/smokescreen \
&& go version -m /tmp/smokescreen | grep -E '^\s+dep\s+golang.org/x/net\s+v0.62.0(\s|$)'
FROM ${BASE_IMAGE}
ARG http_proxy
ARG https_proxy
ARG no_proxy
ARG socks_proxy
ARG TZ="Etc/UTC"
ENV TERM=xterm \
http_proxy=${http_proxy} \
https_proxy=${https_proxy} \
no_proxy=${no_proxy} \
socks_proxy=${socks_proxy} \
LANG='C.UTF-8' \
LC_ALL='C.UTF-8' \
TZ=${TZ}
ARG USER="django"
ARG CVAT_CONFIGURATION="production"
ENV DJANGO_SETTINGS_MODULE="cvat.settings.${CVAT_CONFIGURATION}"
# Install necessary apt packages.
# USN-8950-1 ships the fix as libpoppler134 24.02.0-1ubuntu9.11.
# The upstream version stays 24.02.0, so the Debian revision is the check.
# USN-8954-1 ships zlib1g 1:1.3.dfsg-3.1ubuntu2.3. The package is named here
# so apt upgrades the copy inherited from the Ubuntu base image.
# apt-get upgrade takes every other security revision the base image is behind on,
# such as libpcre2-8-0 10.42-4ubuntu2.2; the checks below fail the build if a
# stale mirror or cache still serves an older one.
# 7zip is not installed: Ubuntu 24.04's 7zip 23.01 fixes CVE-2023-52168 and
# CVE-2023-52169 only in Ubuntu Pro. patool still extracts zip and tar archives
# with Python's own modules and rar archives with unrar; .7z uploads are refused.
RUN apt-get -o Acquire::Retries=5 update && \
DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=5 -yq upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -yq \
adduser \
bzip2 \
ca-certificates \
curl \
git \
libgl1 \
libgomp1 \
libldap2 \
libmp3lame0 \
libpython3.12t64 \
libsasl2-2 \
nginx \
poppler-utils \
python3 \
python3-venv \
supervisor \
tzdata \
unrar \
wait-for-it \
zlib1g \
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' libpoppler134)" ge "24.02.0-1ubuntu9.11" \
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' zlib1g)" ge "1:1.3.dfsg-3.1ubuntu2.3" \
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' libpcre2-8-0)" ge "10.42-4ubuntu2.2" \
&& if dpkg-query -W -f='${db:Status-Abbrev}\n' 7zip p7zip-full 2>/dev/null | grep -q '^ii'; then \
echo "7zip must not be installed" >&2; exit 1; \
fi \
&& ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
rm -rf /var/lib/apt/lists/*
# Install smokescreen
COPY --from=build-smokescreen /tmp/smokescreen /usr/local/bin/smokescreen
# Add a non-root user
ENV USER=${USER}
RUN deluser --remove-home ubuntu && \
adduser --uid=1000 --shell /bin/bash --disabled-password --gecos "" ${USER}
ENV CVAT_BASE_DIR=/home/${USER}
ARG CLAM_AV="no"
RUN if [ "$CLAM_AV" = "yes" ]; then \
apt-get -o Acquire::Retries=5 update && \
apt-get --no-install-recommends install -yq \
clamav \
libclamunrar && \
sed -i 's/ReceiveTimeout 30/ReceiveTimeout 300/g' /etc/clamav/freshclam.conf && \
freshclam && \
chown -R ${USER}:${USER} /var/lib/clamav && \
rm -rf /var/lib/apt/lists/*; \
fi
# Install wheels from the build image
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:${PATH}"
ARG PIP_DISABLE_PIP_VERSION_CHECK=1
RUN --mount=type=bind,from=build-image,source=/tmp/wheelhouse,target=/mnt/wheelhouse \
--mount=type=bind,from=build-image-av,source=/tmp/wheelhouse,target=/mnt/wheelhouse-av \
python -m pip install --no-index /mnt/wheelhouse/*.whl /mnt/wheelhouse-av/*.whl
ENV NUMPROCS=1
COPY --from=build-image-av /opt/ffmpeg/lib /usr/lib
# These variables are required for supervisord substitutions in files
# This library allows remote python debugging with VS Code
ARG CVAT_DEBUG_ENABLED
RUN if [ "${CVAT_DEBUG_ENABLED}" = 'yes' ]; then \
python3 -m pip install --no-cache-dir debugpy; \
fi
# Removing pip due to security reasons. See: https://scout.docker.com/vulnerabilities/id/CVE-2018-20225
# The vulnerability is dubious and we don't use pip at runtime, but some vulnerability scanners mark it as a high vulnerability,
# and it was decided to remove pip from the final image
RUN python -m pip uninstall -y pip
# python3-venv only builds /opt/venv. It pulls in Ubuntu's pip and setuptools
# wheels, whose fixes for the vendored urllib3 and requests (CVE-2024-35195,
# CVE-2025-66418, CVE-2025-66471) ship only in Ubuntu Pro. Nothing creates a
# virtualenv at runtime, so those packages leave the final image too.
RUN apt-get purge -y python3-venv python3.12-venv python3-pip-whl python3-setuptools-whl \
&& if dpkg-query -W -f='${db:Status-Abbrev}\n' python3-venv python3.12-venv python3-pip-whl python3-setuptools-whl 2>/dev/null | grep -q '^ii'; then \
echo "Ubuntu's venv or pip wheel packages are still installed" >&2; exit 1; \
fi
# Install and initialize CVAT, copy all necessary files
COPY cvat/nginx.conf /etc/nginx/nginx.conf
COPY --parents \
backend_entrypoint.d cvat supervisord utils \
backend_entrypoint.sh \
components/analytics/clickhouse/init.py \
manage.py \
rqscheduler.py \
wait_for_deps.sh \
/opt/cvat/
# The pip-compile-multi sources and locks are build inputs, already installed into
# /opt/venv above. Left in the image, scanners read testing.txt as installed
# packages (lupa, CVE-2026-34444, which has no fix) although only the production
# set is installed.
RUN rm -rf /opt/cvat/cvat/requirements
RUN python -m compileall -q /opt/cvat
# Link manage.py to the home directory for backwards compatibility.
RUN ln -s /opt/cvat/manage.py ${CVAT_BASE_DIR}/manage.py
RUN echo "/opt/cvat" > /opt/venv/lib/python3.12/site-packages/cvat.pth
ARG COVERAGE_PROCESS_START
RUN if [ "${COVERAGE_PROCESS_START}" ]; then \
echo "import coverage; coverage.process_startup()" > /opt/venv/lib/python3.12/site-packages/coverage_subprocess.pth; \
fi
# RUN all commands below as 'django' user.
# Use numeric UID/GID so that the image is compatible with the Kubernetes runAsNonRoot setting.
USER 1000:1000
WORKDIR ${CVAT_BASE_DIR}
RUN mkdir -p data share keys logs /tmp/supervisord /tmp/cvat static
EXPOSE 8080
ENTRYPOINT ["/opt/cvat/backend_entrypoint.sh"]