forked from Project-MONAI/MONAILabel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
107 lines (91 loc) · 4.91 KB
/
Copy pathDockerfile
File metadata and controls
107 lines (91 loc) · 4.91 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
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Modifications Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved.
# To build with a different base image
# please run `./runtests.sh --clean && DOCKER_BUILDKIT=1 docker build -t amd-monailabel:latest .`
# to use different version of MONAI pass `--build-arg FINAL_IMAGE=...`
#
# AMD ROCm build (default): torch comes from the ROCm wheel index and MONAI is
# provided by amd-monai (with amd-hipcim) from the AMD ROCm pip index. Override the ROCm base / indices
# with the build-args below, e.g.:
# DOCKER_BUILDKIT=1 docker build \
# --build-arg FINAL_IMAGE=rocm/dev-ubuntu-24.04:7.2-complete \
# --build-arg TORCH_INDEX_URL=https://download.pytorch.org/whl/rocm7.1 \
# --build-arg AMDGPU_TARGETS=gfx942 -t amd-monailabel:latest .
ARG FINAL_IMAGE=rocm/dev-ubuntu-24.04:7.2-complete
ARG BUILD_IMAGE=python:3.10
ARG NODE_IMAGE=node:slim
ARG TORCH_INDEX_URL=https://download.pytorch.org/whl/rocm7.1
ARG AMDGPU_TARGETS=gfx942
# Phase1: Build OHIF Viewer
FROM ${NODE_IMAGE} AS ohifbuild
COPY plugins/ohifv3 /opt/ohifv3
RUN apt update -y && apt install -y --no-install-recommends git curl ca-certificates && \
npm install -g yarn
RUN cd /opt/ohifv3 && ./build.sh /opt/ohifv3/release
RUN test -d /opt/ohifv3/release && [ -n "$(ls -A /opt/ohifv3/release)" ] || \
{ echo "ERROR: OHIF build produced no /opt/ohifv3/release output"; exit 1; }
# Phase2: Build MONAI Label Package
FROM ${BUILD_IMAGE} AS build
ARG TORCH_INDEX_URL
WORKDIR /opt/monailabel
RUN python -m pip install pip setuptools wheel twine
RUN python -m pip install --no-cache-dir ninja && \
python -m pip install --no-cache-dir torch --index-url ${TORCH_INDEX_URL}
ADD . /opt/monailabel/
COPY --from=ohifbuild /opt/ohifv3/release /opt/monailabel/monailabel/endpoints/static/ohif
# Build the wheel. .git is included in the context so versioneer resolves the
# real version (e.g. 0.8.5...). Drop --build-number so no date suffix is added,
# then rename the wheel to a clean, stable name: monailabel-<version>-py3.whl.
RUN BUILD_OHIF=false python setup.py bdist_wheel && \
cd dist && \
orig="$(ls amd_monailabel-*.whl | head -1)" && \
ver="$(echo "${orig}" | sed -E 's/^amd_monailabel-([^+-]+).*/\1/')" && \
mv "${orig}" "amd_monailabel-${ver}-py3-none-any.whl" && \
ls -l
# Phase3: Build Final Docker (AMD ROCm)
FROM ${FINAL_IMAGE}
LABEL maintainer="monai.contact@gmail.com"
WORKDIR /opt/monailabel
ARG TORCH_INDEX_URL
ARG AMDGPU_TARGETS
ENV ROCM_HOME=/opt/rocm \
ROCM_PATH=/opt/rocm \
HIP_PATH=/opt/rocm \
PATH=/opt/rocm/bin:${PATH} \
LD_LIBRARY_PATH=/opt/rocm/lib:${LD_LIBRARY_PATH} \
AMDGPU_TARGETS=${AMDGPU_TARGETS} \
PIP_BREAK_SYSTEM_PACKAGES=1 \
PIP_ROOT_USER_ACTION=ignore
COPY requirements.txt /opt/monailabel/requirements.txt
COPY amd-constraints.txt /opt/monailabel/amd-constraints.txt
RUN apt update -y && apt install -y git curl openslide-tools python3 python-is-python3 python3-pip python3-setuptools python3-wheel
RUN python -m pip install --no-cache-dir --upgrade "setuptools>=61"
# torch from the ROCm wheel index
RUN python -m pip install --no-cache-dir torch torchvision torchaudio --index-url ${TORCH_INDEX_URL}
# amd-hipcim + amd-monai (MONAI's ROCm build) from the AMD ROCm pip index
RUN ROCM_VERSION="$(cat /opt/rocm/.info/version)" && \
AMD_INDEX="https://pypi.amd.com/rocm-${ROCM_VERSION}/simple" && \
python -m pip install --no-cache-dir amd-hipcim --extra-index-url="${AMD_INDEX}/" && \
python -m pip install --no-cache-dir amd-monai --extra-index-url="${AMD_INDEX}"
RUN python -m pip install --no-cache-dir "setuptools-scm<8" "setuptools>=61" wheel && \
python -m pip install --no-cache-dir --no-build-isolation girder-client==3.2.3
RUN SAM2_URL="$(grep -iE 'sam2\.git' requirements.txt | sed -E 's/^[^@]*@ *//; s/ *;.*$//' | head -1)" && \
grep -ivE 'sam2\.git|^girder-client' requirements.txt > /tmp/req_nosam.txt && \
python -m pip install --no-cache-dir -r /tmp/req_nosam.txt -c amd-constraints.txt && \
if [ -n "${SAM2_URL}" ]; then \
echo "Installing SAM-2 with --no-build-isolation: ${SAM2_URL}" && \
python -m pip install --no-cache-dir --no-build-isolation "${SAM2_URL}"; \
fi
# Install the MONAILabel wheel (deps already satisfied above)
COPY --from=build /opt/monailabel/dist/amd_monailabel* /opt/monailabel/dist/
RUN python -m pip install -v --no-cache-dir --no-deps /opt/monailabel/dist/amd_monailabel*.whl