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

Docker ci #245

Merged
merged 12 commits into from
Jan 4, 2022
41 changes: 41 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Byte-compiled / optimized / DLL files
__pycache__/

# Unit test / coverage reports
.pytest_cache/
coverage_report_html/
.coverage

# Sphinx documentation
docs/build/

# data
data/

# files created by matplotlib testing suite
result_images/

# distribution / packaging
*.egg-info
*.egg
build/
dist/

# Jupyter Notebook
.ipynb_checkpoints

# scratch notebook
scratch.ipynb

# Mac files
.DS_Store

# Pycharm
.idea/

# dask
dask-worker-space/

# git
.git
.gitigore
31 changes: 31 additions & 0 deletions .github/workflows/publish-to-docker-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish PathML Docker image on Docker Hub

on:
release:
types: [published]

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set version number variable
run: |
VER=$(cat pathml/_version.py | grep -o '"[^"]\+"' | tr '"' ' ')
echo "VERSION=$VER" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.6.0
- name: Login to DockerHub
uses: docker/login-action@v1.10.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2.7.0
with:
push: true
tags:
pathml/pathml:latest
pathml/pathml:${{ env.VERSION }}
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# syntax=docker/dockerfile:1

FROM ubuntu:20.04
# LABEL about the custom image
LABEL maintainer="PathML@dfci.harvard.edu"
LABEL description="This is custom Docker Image for running PathML"

# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive

#Set miniconda path
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"

ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
ARG JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"

ENV SHELL="/bin/bash"

#install packages on root
USER root

#download and install miniconda and external dependencies
RUN apt-get update && apt-get install -y --no-install-recommends openslide-tools \
g++ \
gcc \
libpixman-1-0 \
libblas-dev \
liblapack-dev \
wget \
openjdk-8-jre \
openjdk-8-jdk \
&& wget \
https://repo.anaconda.com/miniconda/Miniconda3-py38_4.10.3-Linux-x86_64.sh \
&& mkdir /root/.conda \
&& bash Miniconda3-py38_4.10.3-Linux-x86_64.sh -b \
&& rm -f Miniconda3-py38_4.10.3-Linux-x86_64.sh \
&& rm -rf /var/lib/apt/lists/*

# copy pathml files into docker
COPY setup.py README.md /opt/pathml/
COPY pathml/ /opt/pathml/pathml
COPY tests/ /opt/pathml/tests

# install pathml and deepcell
RUN pip3 install --upgrade pip \
&& pip3 install numpy==1.19.5 \
&& pip3 install python-bioformats==4.0.0 deepcell /opt/pathml/ pytest

# run tests to verify container
WORKDIR /opt/pathml
RUN python3 -m pytest /opt/pathml/tests/ -m "not slow"

WORKDIR /home/pathml

# set up jupyter lab
RUN pip3 install jupyter -U && pip3 install jupyterlab
EXPOSE 8888
ENTRYPOINT ["jupyter", "lab", "--ip=0.0.0.0", "--allow-root", "--no-browser"]
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ There are several ways to install `PathML`:

1. pip install (**recommended for users**)
2. clone repo to local machine and install from source (recommended for developers/contributors)
3. Use the PathML Docker container

Options (1) and (2) require that you first install all external dependencies:
* openslide
Expand Down Expand Up @@ -87,6 +88,29 @@ Install `PathML`:
pip install -e .
````

## Installation option 3: docker

Build the PathML docker container:
````
docker build -t pathml-analysis .
````

Connect to the container:
````
docker run -it -p 8888:8888 pathml-analysis
````

The above command runs the container, which is configured to spin up a jupyter lab session and expose it on port 8888.
The terminal should display a URL to the jupyter lab session starting with http://127.0.0.1:8888/lab?token=<...>.
Navigate to that page and you should connect to the jupyter lab session running on the container with the pathml
environment fully configured.

Note that the docker container requires extra configurations to use with GPU.
Note that these instructions assume that there are no other processes using port 8888.

Please refer to the `Docker run` [documentation](https://docs.docker.com/engine/reference/run/) for further instructions
on accessing the container, e.g. for mounting volumes to access files on a local machine from within the container.

## CUDA

To use GPU acceleration for model training or other tasks, you must install CUDA.
Expand Down
2 changes: 1 addition & 1 deletion pathml/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
License: GNU GPL 2.0
"""

__version__ = "2.0.1"
__version__ = "2.0.dev1"
15 changes: 10 additions & 5 deletions pathml/core/slide_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@

from io import BytesIO
from typing import Tuple

import numpy as np
import openslide
import pathml.core
import pathml.core.tile
from pathml.utils import pil_to_rgb
from PIL import Image
from pydicom.dataset import Dataset
from pydicom.encaps import get_frame_offsets
Expand All @@ -19,6 +15,11 @@
from pydicom.tag import SequenceDelimiterTag, TupleTag
from pydicom.uid import UID
from scipy.ndimage import zoom
from javabridge.jutil import JavaException

import pathml.core
import pathml.core.tile
from pathml.utils import pil_to_rgb

try:
import bioformats
Expand Down Expand Up @@ -255,7 +256,11 @@ def __init__(self, filename):
self.filename = filename
# init java virtual machine
javabridge.start_vm(class_path=bioformats.JARS, max_heap_size="50G")
_init_logger()
# disable verbose JVM logging if possible
try:
_init_logger()
except JavaException:
pass
# java maximum array size of 2GB constrains image size
ImageReader = bioformats.formatreader.make_image_reader_class()
reader = ImageReader()
Expand Down