Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
248 lines (203 loc) · 8.42 KB
/
Copy pathDockerfile
File metadata and controls
248 lines (203 loc) · 8.42 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
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
#------------------------------------------
# Web UI Build Stage
#------------------------------------------
FROM node:24-alpine3.22@sha256:191c9f0080fcbbc6547a85dc0ff7988072214a355aabdc1d2ec55a7dae5eea8a AS web-ui-base
WORKDIR /home/app/web_ui/
# Install git for degit
RUN apk add --no-cache git
COPY --link application/ui/package.json ./package.json
COPY --link application/ui/package-lock.json ./package-lock.json
RUN npm ci --audit=false
COPY --link application/ui/tsconfig.json ./tsconfig.json
COPY --link application/ui/rsbuild.config.ts ./rsbuild.config.ts
COPY --link application/ui/src ./src
FROM web-ui-base AS web-ui
RUN npm run build
#------------------------------------------
# Anomalib Studio Base with UI built
#------------------------------------------
FROM python:3.13-slim@sha256:7ce4b6dfe35e55397b7cda544f8a13f191b7ae28dc5aad71fe664dbc9bc2623f AS anomalib-studio-base
COPY --from=docker.io/astral/uv:0.9.7@sha256:ba4857bf2a068e9bc0e64eed8563b065908a4cd6bfb66b531a9c424c8e25e142 /uv /uvx /bin/
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
ENV UV_PYTHON_DOWNLOADS=0
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
g++ \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Remove pip because uv is used as the package manager.
# This reduces attack surface and image size (a little bit).
# python:3.13-slim only ships pip (not setuptools/wheel).
ENV PIP_ROOT_USER_ACTION=ignore
RUN python -m pip uninstall -y pip \
&& rm -rf /root/.cache/pip
ENV PATH=/app/.venv/bin:$PATH
WORKDIR /app
ARG STATIC_FILES_DIR="/app/application/ui/"
ENV STATIC_FILES_DIR=${STATIC_FILES_DIR}
ENV DATA_DIR="/app/data"
ENV LOG_DIR="/app/logs"
ENV PYTHONPATH=/app/application/backend
COPY --link --from=web-ui /home/app/web_ui/dist ${STATIC_FILES_DIR}
COPY --link application/backend/run.sh /app/application/backend/run.sh
# Copy anomalib source code (pyproject.toml depends on README and LICENSE as well)
COPY --link src ./src
COPY --link pyproject.toml uv.lock ./
COPY --link LICENSE ./LICENSE
COPY --link README.md ./README.md
# Copy backend application
COPY --link application/backend /app/application/backend
# Create data and logs directories with write permissions for mounted volumes
RUN mkdir -p /app/data /app/logs
#------------------------------------------
# Anomalib Studio CPU version
#------------------------------------------
FROM anomalib-studio-base AS anomalib-studio-cpu
WORKDIR /app/application/backend
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --extra cpu
EXPOSE 8000
# nosemgrep: dockerfile.security.missing-user.missing-user # will fix later
CMD ["sh", "-c", "exec ./run.sh"]
#------------------------------------------
# Anomalib Studio CUDA intermediate stage to install CUDA dependencies
#------------------------------------------
FROM anomalib-studio-base AS anomalib-studio-cuda-base
RUN apt-get update \
&& apt-get install -y --no-install-recommends wget=1.25.0-2 \
&& wget -q https://developer.download.nvidia.com/compute/cuda/repos/debian13/x86_64/cuda-keyring_1.1-1_all.deb \
&& dpkg -i cuda-keyring_1.1-1_all.deb \
&& rm -rf cuda-keyring_1.1-1_all.deb \
&& apt-get remove -y wget \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
RUN apt-get update && apt-get install -y --no-install-recommends \
cuda-cudart-13-1 \
libcublas-13-1 \
libcufft-13-1 \
libcurand-13-1 \
libcusolver-13-1 \
libcusparse-13-1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
WORKDIR /app/application/backend
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --extra cu130
#------------------------------------------
# Anomalib Studio CUDA intermediate stage to cleanup CUDA non-distributable dependencies
#------------------------------------------
FROM anomalib-studio-cuda-base AS anomalib-studio-cuda-cleanup
# CUDA EULA Compliance Cleanup
RUN echo "Removing non-redistributable CUDA components per NVIDIA EULA..." && \
# Define search paths including venv
SEARCH_PATHS="/usr /opt" && \
# Include PYTHONPATH in search paths if it is set
if [ -n "${PYTHONPATH}" ]; then \
SEARCH_PATHS="$SEARCH_PATHS ${PYTHONPATH}"; \
fi && \
# Add any detected venvs from PYTHONPATH (if set)
for venv in $(find ${PYTHONPATH:+${PYTHONPATH}} -name "site-packages" -type d 2>/dev/null | sed 's|/lib/python[0-9.]*/site-packages||' | sort -u); do \
if [ -d "$venv" ]; then \
SEARCH_PATHS="$SEARCH_PATHS $venv"; \
fi; \
done && \
echo "Cleaning CUDA components in: $SEARCH_PATHS" && \
# Remove development tools (non-redistributable)
find $SEARCH_PATHS -type f \( \
-name "nvcc" -o \
-name "cuda-gdb" -o \
-name "nvprof" -o \
-name "nvdisasm" -o \
-name "cuobjdump" -o \
-name "cuda-memcheck" -o \
-name "nsight*" -o \
-name "compute-sanitizer" -o \
-name "ncu" -o \
-name "nv-nsight-cu*" \
\) -delete 2>/dev/null || true && \
# Remove headers and include directories (non-redistributable)
find $SEARCH_PATHS -type d \( \
-name "include" -o \
-name "headers" \
\) -path "*cuda*" -exec rm -rf {} + 2>/dev/null || true && \
# Remove NVIDIA package includes specifically
find $SEARCH_PATHS -type d -path "*/nvidia/*/include" -exec rm -rf {} + 2>/dev/null || true && \
# Remove static libraries (typically non-redistributable)
find $SEARCH_PATHS -name "*.a" -path "*cuda*" -delete 2>/dev/null || true && \
find $SEARCH_PATHS -name "*.a" -path "*nvidia*" -delete 2>/dev/null || true && \
# Remove documentation and samples (non-redistributable)
find $SEARCH_PATHS -type d \( \
-name "doc" -o \
-name "docs" -o \
-name "documentation" -o \
-name "samples" -o \
-name "sample" \
\) -path "*cuda*" -exec rm -rf {} + 2>/dev/null || true && \
# Remove specific non-redistributable CUPTI components
find $SEARCH_PATHS -type f \( \
-name "libcheckpoint.so*" -o \
-name "libnvperf_host.so*" -o \
-name "libnvperf_target.so*" -o \
-name "libpcsamplingutil.so*" \
\) -delete 2>/dev/null || true && \
# Remove cuSolver MG libraries (enterprise feature)
find $SEARCH_PATHS -name "libcusolverMg.so*" -delete 2>/dev/null || true && \
# Remove Triton NVIDIA backends (development components)
find $SEARCH_PATHS -type d -path "*/triton/backends/nvidia" -exec rm -rf {} + 2>/dev/null || true && \
# System package cleanup
apt-get remove -y \
cuda-compiler-* \
cuda-cuobjdump-* \
cuda-gdb-* \
cuda-memcheck-* \
cuda-nvcc-* \
cuda-nvdisasm-* \
cuda-nvprof-* \
cuda-sanitizer-* \
cuda-documentation-* \
cuda-samples-* \
nsight-* \
2>/dev/null || true && \
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*
#------------------------------------------
# Anomalib Studio CUDA version
#------------------------------------------
FROM anomalib-studio-base AS anomalib-studio-cuda
COPY --link --from=anomalib-studio-cuda-cleanup /usr/local /usr/local
COPY --link --from=anomalib-studio-cuda-cleanup ${PYTHONPATH} ${PYTHONPATH}
WORKDIR /app/application/backend
EXPOSE 8000
# nosemgrep: dockerfile.security.missing-user.missing-user # will fix later
CMD ["sh", "-c", "exec ./run.sh"]
#------------------------------------------
# Anomalib Studio XPU version
#------------------------------------------
FROM anomalib-studio-base AS anomalib-studio-xpu
RUN apt-get update \
&& apt-get install -y --no-install-recommends wget gpg \
&& wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
gpg --yes --dearmor --output /usr/share/keyrings/intel-graphics.gpg \
&& echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu jammy unified" | \
tee /etc/apt/sources.list.d/intel-gpu-jammy.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libze-intel-gpu1 \
libze1 \
intel-opencl-icd \
clinfo \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get remove -y wget gpg \
&& apt-get clean
WORKDIR /app/application/backend
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --extra xpu
# CUDA EULA Compliance Cleanup
RUN find /app/application/backend/.venv -type d -path "*/triton/backends/nvidia" -exec rm -rf {} + 2>/dev/null || true
EXPOSE 8000
# nosemgrep: dockerfile.security.missing-user.missing-user # will fix later
CMD ["sh", "-c", "exec ./run.sh"]