Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker Build to overcome Github Runner space issues #1778

Merged
merged 15 commits into from
Nov 7, 2024
19 changes: 1 addition & 18 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
__pycache__
.idea
.vscode

Dockerfile
.webpack
node_modules/

# Environments
.env
Expand All @@ -31,21 +30,5 @@ ubuntu_venv/
sample-apps/*/logs
sample-apps/*/train
sample-apps/*/model

# docs build
docs/build
docs/source/apidocs

# MONAI-label
*.nii.gz
.DS_Store
*.DS_Store
bin
junit
test-output.xml
studies
tests/data

# Packages
node_modules
yarn.lock
16 changes: 13 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ jobs:
MONAI_ZOO_AUTH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Build
- name: Cleanup
run: |
echo Before Cleanup...
df -h
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
rm -rf /opt/hostedtoolcache
docker system prune -f
DOCKER_BUILDKIT=1 docker build -t projectmonai/monailabel:${{ github.event.inputs.tag || 'latest' }} -f Dockerfile .
rm -rf /usr/share/dotnet/
cd /opt
find . -maxdepth 1 -mindepth 1 '!' -path ./containerd '!' -path ./actionarchivecache '!' -path ./runner '!' -path ./runner-cache -exec rm -rf '{}' ';'
cd -
echo After Cleanup...
df -h
- name: Build
run: |
DOCKER_BUILDKIT=0 docker build -t projectmonai/monailabel:${{ github.event.inputs.tag || 'latest' }} -f Dockerfile .
- name: Verify
run: |
docker run --rm -i --ipc=host --net=host -v $(pwd):/workspace projectmonai/monailabel:${{ github.event.inputs.tag || 'latest' }} /workspace/runtests.sh --net
Expand Down
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,32 @@

# To build with a different base image
# please run `./runtests.sh --clean && DOCKER_BUILDKIT=1 docker build -t projectmonai/monailabel:latest .`
# to use different version of MONAI pass `--build-arg MONAI_IMAGE=...`
# to use different version of MONAI pass `--build-arg FINAL_IMAGE=...`

ARG MONAI_IMAGE=projectmonai/monai:1.4.0
#ARG FINAL_IMAGE=pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
ARG FINAL_IMAGE=ubuntu:22.04
ARG BUILD_IMAGE=python:3.10
ARG NODE_IMAGE=node:slim

# Phase1: Build OHIF Viewer
FROM ${NODE_IMAGE} AS ohifbuild
ADD ./plugins/ohifv3 /opt/ohifv3
COPY plugins/ohifv3 /opt/ohifv3
RUN apt update -y && apt install -y git
RUN cd /opt/ohifv3 && ./build.sh /opt/ohifv3/release

FROM ${MONAI_IMAGE} AS build
LABEL maintainer="[email protected]"

# Phase2: Build MONAI Label Package
FROM ${BUILD_IMAGE} AS build
WORKDIR /opt/monailabel
RUN python -m pip install pip setuptools wheel twine
ADD . /opt/monailabel/
COPY --from=ohifbuild /opt/ohifv3/release /opt/monailabel/monailabel/endpoints/static/ohif
RUN python -m pip install --upgrade --no-cache-dir pip setuptools wheel twine \
&& cd /opt/monailabel \
&& BUILD_OHIF=false python setup.py sdist bdist_wheel --build-number $(date +'%Y%m%d%H%M')
RUN BUILD_OHIF=false python setup.py bdist_wheel --build-number $(date +'%Y%m%d%H%M')

FROM ${MONAI_IMAGE}
# Phase3: Build Final Docker
FROM ${FINAL_IMAGE}
LABEL maintainer="[email protected]"

WORKDIR /opt/monailabel
RUN apt update -y && apt install -y git curl openslide-tools python3 python-is-python3 python3-pip
RUN python -m pip install --no-cache-dir pytest torch torchvision torchaudio
COPY --from=build /opt/monailabel/dist/monailabel* /opt/monailabel/dist/
RUN python -m pip install --upgrade --no-cache-dir pip \
&& python -m pip install /opt/monailabel/dist/monailabel*.whl
RUN python -m pip install --no-cache-dir /opt/monailabel/dist/monailabel*.whl
Binary file modified docs/images/dsa.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/quickstart/monai-label-plugin-favorite-modules-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/qupath.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/sample-apps/deepedit_brain_tumor.png
Binary file not shown.
Binary file removed docs/images/sample-apps/deepedit_left_atrium.png
Binary file not shown.
Binary file removed docs/images/sample-apps/deepedit_left_ventricle.png
Binary file not shown.
Binary file removed docs/images/sample-apps/deepedit_lungs.png
Binary file not shown.
Binary file removed docs/images/sample-apps/deepedit_spleen.png
Binary file not shown.
Binary file removed docs/images/sample-apps/deepedit_vertebra.png
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ function clean_py() {
rm -rf tests/data/*
rm -rf build
rm -rf dist
rm -rf monailabel.egg-info
rm -rf .eggs
rm -rf .mypy_cache

find sample-apps -type d -name "__pycache__" -exec rm -rf "{}" +
find monailabel -type d -name "__pycache__" -exec rm -rf "{}" +
find . -type d -name "__pycache__" -exec rm -rf "{}" +
find plugins -type d -name "node_modules" -exec rm -rf "{}" +
}

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def recursive_files(directory, prefix):
filenames = [f for f in filenames if f != ".gitignore"]
for filename in filenames:
paths.append(os.path.join(path, filename))
print(f"Total Items in path: {directory} are {len(paths)}")
return [(os.path.dirname(prefix + os.path.sep + p), [p]) for p in paths]


data_files = [("logconfig", ["monailabel/logging.json"])]
data_files.extend(recursive_files("sample-apps", "monailabel"))
data_files.extend(recursive_files("plugins", "monailabel"))
print(f"Total Data Files: {len(data_files)}")

# Build OHIF Plugin
build_ohif_s = os.environ.get("BUILD_OHIF", "false")
Expand Down
Loading