Skip to content

Commit

Permalink
Prepare docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
pchlap committed Sep 27, 2022
1 parent f5d5004 commit b59d16e
Show file tree
Hide file tree
Showing 36 changed files with 1,081 additions and 862 deletions.
42 changes: 31 additions & 11 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Package

on:
on:
repository_dispatch:
types: [docker]
workflow_dispatch:
Expand All @@ -16,18 +16,18 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Base
- name: Build and Push Base Image
uses: docker/build-push-action@v2
with:
context: .
Expand All @@ -36,7 +36,27 @@ jobs:
tags: |
platipy/platipy:latest
ghcr.io/pyplati/platipy:latest
- name: Build and Push Cardiac Docker Image
- name: Build and Push Service Image
uses: docker/build-push-action@v2
with:
context: .
file: service.Dockerfile
platforms: linux/amd64
push: true
tags: |
platipy/platipy:service
ghcr.io/pyplati/platipy:service
- name: Build and Push Dev Image
uses: docker/build-push-action@v2
with:
context: .
file: service.Dockerfile
platforms: linux/amd64
push: true
tags: |
platipy/platipy:dev
ghcr.io/pyplati/platipy:dev
- name: Build and Push Cardiac Image
uses: docker/build-push-action@v2
with:
context: services/cardiac
Expand All @@ -45,7 +65,7 @@ jobs:
tags: |
platipy/platipy:cardiac
ghcr.io/pyplati/platipy:cardiac
- name: Build and Push Bronchus Docker Image
- name: Build and Push Bronchus Image
uses: docker/build-push-action@v2
with:
context: services/bronchus
Expand All @@ -54,8 +74,8 @@ jobs:
tags: |
platipy/platipy:bronchus
ghcr.io/pyplati/platipy:bronchus
- name: Build and Push Pinnacle Docker Image
- name: Build and Push Pinnacle Image
uses: docker/build-push-action@v2
with:
context: services/pinnacle
Expand All @@ -65,7 +85,7 @@ jobs:
platipy/platipy:pinnacle
ghcr.io/pyplati/platipy:pinnacle
- name: Build and Push MRI Dixon Docker Image
- name: Build and Push MRI Dixon Image
uses: docker/build-push-action@v2
with:
context: services/mridixon
Expand All @@ -75,7 +95,7 @@ jobs:
platipy/platipy:mridixon
ghcr.io/pyplati/platipy:mridixon
- name: Build and Push Radiomics Docker Image
- name: Build and Push Radiomics Image
uses: docker/build-push-action@v2
with:
context: services/radiomics
Expand All @@ -95,7 +115,7 @@ jobs:
platipy/platipy:dirqa
ghcr.io/pyplati/platipy:dirqa
- name: Build and Push nnUNet Docker Image
- name: Build and Push nnUNet Image
uses: docker/build-push-action@v2
with:
context: services/nnunet
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM ubuntu:20.04

RUN apt-get update; DEBIAN_FRONTEND="noninteractive" apt-get install -y redis-server git python3-pip libgl1-mesa-glx libsm6 libxext6 libxrender-dev libglib2.0-0 pandoc curl
RUN apt-get update; DEBIAN_FRONTEND="noninteractive" apt-get install -y python3-pip libgl1-mesa-glx libsm6 libxext6 libxrender-dev libglib2.0-0 curl

RUN ln -s /usr/bin/python3 /usr/bin/python
RUN pip install --upgrade pip
# RUN pip install --upgrade pip

COPY poetry.lock /platipy/poetry.lock
COPY pyproject.toml /platipy/pyproject.toml

RUN curl -sSL https://install.python-poetry.org | python - --version 1.2.0rc1
RUN echo 'export PATH="/root/.local/bin:$PATH"' >> ~/.bashrc
RUN echo 'export PATH="/root/.local/bin:$PATH"' >> ~/.bashrc
RUN echo "/usr/lib/python3.8/site-packages" >> /usr/local/lib/python3.8/dist-packages/site-packages.pth

RUN /root/.local/bin/poetry config virtualenvs.create false
RUN env -C /platipy /root/.local/bin/poetry install --without dev,docs
3 changes: 0 additions & 3 deletions Dockerfile-dev

This file was deleted.

5 changes: 5 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM platipy/platipy

RUN apt-get update; DEBIAN_FRONTEND="noninteractive" apt-get install -y redis-server git libgl1-mesa-glx libsm6 libxext6 libxrender-dev libglib2.0-0 pandoc curl

RUN env -C /platipy /root/.local/bin/poetry install --with dev,docs --all-extras
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
platipy:
image: platipy/platipy
image: platipy/platipy:dev
ports:
- "8001:8000"
- "7777:7777"
Expand All @@ -14,6 +14,8 @@ services:
entrypoint: /bin/sh -c "while sleep 1000; do :; done"
environment:
PYTHONPATH: "/platipy"
REDIS_HOST: redis
REDIS_PORT: 6379
deploy:
resources:
limits:
Expand Down
7 changes: 2 additions & 5 deletions platipy/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api
from celery import Celery
from loguru import logger

from platipy.backend.application import FlaskApp

import logging
logger = logging.getLogger(__name__)

env_work = os.getcwd()
if "WORK" in os.environ:
Expand All @@ -38,9 +37,7 @@
app.config["SECRET_KEY"] = uuid.uuid4().hex

# Configure SQL Alchemy
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///{0}/{1}.db".format(
env_work, os.path.basename(os.getcwd())
)
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{env_work}/{os.path.basename(os.getcwd())}.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)

Expand Down
2 changes: 1 addition & 1 deletion platipy/backend/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def clean_up_task(task):
)

logger.info(
"Clean Up Task Complete: Removed {0} DataObjects", num_data_objs_removed
"Clean Up Task Complete: Removed %s DataObjects", num_data_objs_removed
)


Expand Down
2 changes: 1 addition & 1 deletion platipy/dicom/io/rtstruct_to_nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def transform_point_set_from_dicom_struct(dicom_image, dicom_struct, spacing_ove

for struct_index, struct_name in enumerate(struct_name_sequence):
image_blank = np.zeros(dicom_image.GetSize()[::-1], dtype=np.uint8)
logger.debug("Converting structure {0} with name: {1}".format(struct_index, struct_name))
logger.debug("Converting structure %d with name: %s", struct_index, struct_name)

if not hasattr(struct_point_sequence[struct_index], "ContourSequence"):
logger.debug("No contour sequence found for this structure, skipping.")
Expand Down
38 changes: 19 additions & 19 deletions platipy/imaging/label/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def run_iar(
g_val_list = []
logger.info(" Calculating surface distance maps: ")
for test_id in remaining_id_list:
logger.info(" {0}".format(test_id))
logger.info(" %s", test_id)
# 2. Calculate the distance from the surface to the consensus surface

test_volume = atlas_set[test_id][label][reference_structure]
Expand Down Expand Up @@ -174,7 +174,7 @@ def run_iar(
g_val_std = np.std(g_val_list_test, axis=0)

if np.any(g_val_std == 0):
logger.info(" Std Dev zero count: {0}".format(np.sum(g_val_std == 0)))
logger.info(" Std Dev zero count: %d", np.sum(g_val_std == 0))
g_val_std[g_val_std == 0] = g_val_std.mean()

z_score_vals_array = (g_vals - g_val_mean) / g_val_std
Expand All @@ -188,25 +188,25 @@ def run_iar(
logger.info(g_val_mad)

if np.any(g_val_mad == 0):
logger.info(" MAD zero count: {0}".format(np.sum(g_val_mad == 0)))
logger.info(" MAD zero count: %d", np.sum(g_val_mad == 0))
g_val_mad[g_val_mad == 0] = np.median(g_val_mad)

z_score_vals_array = (g_vals - g_val_median) / g_val_mad

else:
logger.error(" Error!")
logger.error(" z_score must be one of: MAD, STD")
sys.exit()
raise ValueError("z_score must be one of: MAD, STD")

z_score_vals = np.ravel(z_score_vals_array)

logger.debug(" [{0}] Statistics of mZ-scores".format(test_id))
logger.debug(" Min(Z) = {0:.2f}".format(z_score_vals.min()))
logger.debug(" Q1(Z) = {0:.2f}".format(np.percentile(z_score_vals, 25)))
logger.debug(" Mean(Z) = {0:.2f}".format(z_score_vals.mean()))
logger.debug(" Median(Z) = {0:.2f}".format(np.percentile(z_score_vals, 50)))
logger.debug(" Q3(Z) = {0:.2f}".format(np.percentile(z_score_vals, 75)))
logger.debug(" Max(Z) = {0:.2f}\n".format(z_score_vals.max()))
logger.debug(" [%s] Statistics of mZ-scores", test_id)
logger.debug(" Min(Z) = %.2f", z_score_vals.min())
logger.debug(" Q1(Z) = %.2f", np.percentile(z_score_vals, 25))
logger.debug(" Mean(Z) = %.2f", z_score_vals.mean())
logger.debug(" Median(Z) = %.2f", np.percentile(z_score_vals, 50))
logger.debug(" Q3(Z) = %.2f", np.percentile(z_score_vals, 75))
logger.debug(" Max(Z) = %.2f\n", z_score_vals.max())

# Calculate excess area from Gaussian: the Q-metric
bins = np.linspace(-15, 15, 501)
Expand Down Expand Up @@ -249,34 +249,34 @@ def run_iar(
sys.exit()

logger.info(" Analysing results")
logger.info(" Outlier limit: {0:06.3f}".format(outlier_limit))
logger.info(" Outlier limit: %6.3f}", outlier_limit)
keep_id_list = []

logger.info(
"{0},{1},{2},{3:.4g}\n".format(
"%s,%s,%s,%.4g}\n",
iteration,
" ".join(remaining_id_list),
" ".join(["{0:.4g}".format(i) for i in list(q_results.values())]),
outlier_limit,
)

)

for idx, result in q_results.items():

accept = result <= outlier_limit

logger.info(
" {0}: Q = {1:06.3f} [{2}]".format(
" %s: Q = %6.3f [%s]",
idx, result, {True: "KEEP", False: "REMOVE"}[accept]
)

)

if accept:
keep_id_list.append(idx)

if len(keep_id_list) < len(remaining_id_list):
logger.info("\n Step {0} Complete".format(iteration))
logger.info(" Num. Removed = {0} --\n".format(len(remaining_id_list) - len(keep_id_list)))
logger.info("\n Step %d Complete", iteration)
logger.info(" Num. Removed = %d --\n", len(remaining_id_list) - len(keep_id_list))

iteration += 1
atlas_set_new = {i: atlas_set[i] for i in keep_id_list}
Expand All @@ -298,6 +298,6 @@ def run_iar(
label=label,
)

logger.info(" End point reached. Keeping:\n {0}".format(keep_id_list))
logger.info(" End point reached. Keeping:\n %s", keep_id_list)

return atlas_set
Loading

0 comments on commit b59d16e

Please sign in to comment.