-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·328 lines (283 loc) · 9.78 KB
/
Copy pathDockerfile
File metadata and controls
executable file
·328 lines (283 loc) · 9.78 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# Dockerfile for rtpipeline - Radiotherapy DICOM Processing Pipeline
# Compatible with Docker and Singularity
# Supports both CPU and GPU execution
#
# Reviewer-package note: this is the full production/offline image definition.
# It expects optional build-context directories such as envs/, third_party/,
# totalseg_weights/, and custom_models/ that are intentionally not bundled in
# the blinded reviewer archive. Use Dockerfile.reviewer_minimal from the
# reviewer code/config bundle for a buildable source-tree smoke-test container.
# Stage 1: Builder
FROM condaforge/mambaforge:24.3.0-0 AS builder
ENV PIP_NO_CACHE_DIR=1
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
wget \
unzip \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# NOTE: Pin dcm2niix version and verify checksum for supply-chain integrity
RUN wget -q https://github.com/rordenlab/dcm2niix/releases/download/v1.0.20230411/dcm2niix_lnx.zip \
&& unzip dcm2niix_lnx.zip -d /usr/local/bin/ \
&& chmod +x /usr/local/bin/dcm2niix \
&& dcm2niix -v 2>&1 | grep -q "v1.0.20230411" \
&& rm dcm2niix_lnx.zip
# Create app directory
WORKDIR /app
# Copy environment files first for better layer caching
COPY envs/ /app/envs/
COPY third_party/ /app/third_party/
# Provide stable absolute path expected by conda env specs
RUN mkdir -p /projekty && ln -s /app /projekty/rtpipeline
# Create conda environments with cleanup between solves. GitHub-hosted runners
# otherwise retain multiple package caches at once and can exhaust the build
# volume before the third environment is complete.
RUN mamba env create -f /app/envs/rtpipeline.yaml && \
mamba clean -afy && rm -rf /root/.cache/pip /opt/conda/pkgs/* && \
mamba env create -f /app/envs/rtpipeline-radiomics.yaml && \
mamba clean -afy && rm -rf /root/.cache/pip /opt/conda/pkgs/* && \
mamba env create -f /app/envs/rtpipeline-custom-models.yaml && \
mamba clean -afy && \
find /opt/conda -follow -type f -name '*.a' -delete && \
find /opt/conda -follow -type f -name '*.pyc' -delete && \
find /opt/conda -follow -type f -name '*.js.map' -delete && \
rm -rf /opt/conda/pkgs/*
# Stage 2: Runtime
FROM condaforge/mambaforge:24.3.0-0
LABEL maintainer="kstawiski"
LABEL description="DICOM-RT pipeline with TotalSegmentator, nnUNet, and Snakemake"
LABEL version="2.2.2"
ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
CONDA_DIR=/opt/conda \
PATH=/opt/conda/bin:$PATH \
LD_LIBRARY_PATH=/opt/conda/lib
# Install runtime dependencies, create user, and setup directories in one layer
RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
libgomp1 \
libglu1-mesa \
pigz \
curl \
procps \
&& rm -rf /var/lib/apt/lists/* && \
groupadd -r rtpipeline && \
useradd -r -g rtpipeline -u 1000 -m rtpipeline && \
mkdir -p \
/data/input \
/data/output \
/data/logs \
/data/models \
/data/uploads \
/tmp/cache \
/app && \
mkdir -p /projekty && \
ln -s /app /projekty/rtpipeline && \
chown -R rtpipeline:rtpipeline /data /tmp/cache /app
# Use tini as init system
ENTRYPOINT ["/usr/bin/tini", "--"]
# Copy dcm2niix from builder
COPY --from=builder /usr/local/bin/dcm2niix /usr/local/bin/dcm2niix
# Configure conda
RUN conda config --set channel_priority strict && \
conda config --add channels conda-forge && \
conda config --add channels bioconda && \
conda config --add channels defaults
# Install Snakemake and Web UI dependencies in base environment
# We install these via mamba to ensure GLIBCXX compatibility (pandas/cpp issues with pip wheels)
# pulp + coin-or-cbc enable Snakemake's ILP scheduler for optimal job ordering
RUN mamba install -y -c conda-forge -c bioconda \
python=3.11 \
'snakemake>=8.4' \
pandas \
flask \
psutil \
'pydicom>=3.0.2,<4' \
pyyaml \
werkzeug \
openpyxl \
pynetdicom \
libstdcxx-ng \
pulp \
coin-or-cbc \
&& mamba clean -afy && \
find /opt/conda -follow -type f -name '*.a' -delete && \
find /opt/conda -follow -type f -name '*.pyc' -delete && \
find /opt/conda -follow -type f -name '*.js.map' -delete && \
rm -rf /opt/conda/pkgs/*
# Copy conda environments from builder
COPY --from=builder /opt/conda/envs /opt/conda/envs
# Copy TotalSegmentator weights for offline support
# The repository tracks an empty placeholder so clean public builds remain valid.
# For offline execution, populate this directory with nnunet/results/Dataset*/...
COPY --chown=rtpipeline:rtpipeline totalseg_weights/ /home/rtpipeline/.totalsegmentator/
# Copy custom models into the image
# This ensures the image is self-contained
COPY --chown=rtpipeline:rtpipeline custom_models /data/models/
WORKDIR /app
# Copy project files
COPY --chown=rtpipeline:rtpipeline . /app/
# Install only the local project into the already-solved environments. All
# runtime dependencies are provided above or by envs/rtpipeline.yaml; allowing
# pip to resolve them again would download a second Torch/CUDA stack.
RUN pip install --no-deps -e . && \
/opt/conda/envs/rtpipeline/bin/pip install --no-deps -e . && \
/opt/conda/envs/rtpipeline/bin/pip install --no-cache-dir psutil
# Create container-specific config
RUN cat > /app/config.container.yaml << 'EOF'
# Container-optimized configuration for rtpipeline
# This config uses professional container paths
# Input/Output directories (container paths)
dicom_root: "/data/input"
output_dir: "/data/output"
logs_dir: "/data/logs"
# Processing parameters
max_workers: null
scheduler:
reserved_cores: 1
dvh_threads_per_job: 4
radiomics_threads_per_job: 6
qc_threads_per_job: 2
prioritize_short_courses: true
segmentation:
device: "gpu"
fast: false
max_workers: null
force: false
roi_subset: null
extra_models: []
force_split: true
nr_threads_resample: 1
nr_threads_save: 1
num_proc_preprocessing: 1
num_proc_export: 1
custom_models:
enabled: true
root: "/data/models"
models: []
max_workers: 1
force: false
nnunet_predict: "nnUNet_predict"
retain_weights: true
conda_activate: null
radiomics:
sequential: false
params_file: "rtpipeline/radiomics_params.yaml"
mr_params_file: "rtpipeline/radiomics_params_mr.yaml"
thread_limit: 4
skip_rois:
- body
- couchsurface
- couchinterior
- couchexterior
- bones
- m1
- m2
max_voxels: 1500000000
min_voxels: 10
# Radiomics robustness analysis
radiomics_robustness:
enabled: true
modes:
- segmentation_perturbation
segmentation_perturbation:
apply_to_structures:
- "GTV*"
- "CTV*"
- "PTV*"
- "pelvic_bones*"
- "iliac_*"
- "bowel_bag"
- "urinary_bladder"
- "colon"
- "prostate"
- "rectum"
small_volume_changes: [-0.15, 0.0, 0.15]
large_volume_changes: [-0.30, 0.0, 0.30]
max_translation_mm: 4.0
n_random_contour_realizations: 2
noise_levels: [0.0, 10.0, 20.0]
intensity: "standard"
metrics:
icc:
implementation: "pingouin"
icc_type: "ICC3"
ci: true
cov:
enabled: true
qcd:
enabled: true
thresholds:
icc:
robust: 0.90
acceptable: 0.75
cov:
robust_pct: 10.0
acceptable_pct: 20.0
aggregation:
threads: auto
environments:
main: "rtpipeline"
radiomics: "rtpipeline-radiomics"
custom_structures: "custom_structures_pelvic.yaml"
ct_cropping:
enabled: true
region: "pelvis"
superior_margin_cm: 2.0
inferior_margin_cm: 10.0
use_cropped_for_dvh: true
use_cropped_for_radiomics: true
keep_original: true
EOF
RUN chown rtpipeline:rtpipeline /app/config.container.yaml
# Environment variables for runtime
ENV SNAKEMAKE_OUTPUT_CACHE="" \
TMPDIR=/tmp/cache \
HOME=/home/rtpipeline \
NUMBA_CACHE_DIR=/tmp/cache \
MPLCONFIGDIR=/tmp/cache \
TOTALSEG_WEIGHTS_PATH=/home/rtpipeline/.totalsegmentator \
nnUNet_results=/home/rtpipeline/.totalsegmentator/nnunet/results \
nnUNet_raw=/home/rtpipeline/.totalsegmentator/nnunet/raw \
nnUNet_preprocessed=/home/rtpipeline/.totalsegmentator/nnunet/preprocessed \
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
TOTALSEG_TIMEOUT=3600 \
DCM2NIIX_TIMEOUT=300 \
RTPIPELINE_RADIOMICS_TASK_TIMEOUT=600 \
SNAKEMAKE_CONDA_PREFIX=/home/rtpipeline/.snakemake/conda
# Pre-create TotalSegmentator weights and nnUNet directories
RUN mkdir -p /home/rtpipeline/.totalsegmentator/nnunet/results \
/home/rtpipeline/.totalsegmentator/nnunet/raw \
/home/rtpipeline/.totalsegmentator/nnunet/preprocessed \
$SNAKEMAKE_CONDA_PREFIX && \
chown -R rtpipeline:rtpipeline /home/rtpipeline/.totalsegmentator /home/rtpipeline/.snakemake
# Switch to non-root user
USER rtpipeline
# Expose ports
EXPOSE 8888 8080
# Default command - interactive bash
CMD ["/bin/bash"]
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Singularity-specific labels
ARG BUILD_DATE=unknown
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="rtpipeline" \
org.label-schema.description="Radiotherapy DICOM processing pipeline" \
org.label-schema.url="https://github.com/kstawiski/rtpipeline" \
org.label-schema.vcs-url="https://github.com/kstawiski/rtpipeline" \
org.label-schema.schema-version="1.0"
# Add help for Singularity users
LABEL org.label-schema.usage.singularity.run.command="singularity run rtpipeline.sif snakemake --cores all --configfile /app/config.container.yaml" \
org.label-schema.usage.singularity.exec.command="singularity exec rtpipeline.sif snakemake --help"