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

feat: ✨ Docker Container (#15) #44

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
110 changes: 24 additions & 86 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,98 +1,36 @@
# set base image (host OS)
#FROM nvidia/cuda:11.0.3-base-ubuntu20.04
FROM nvidia/opengl:1.2-glvnd-devel-ubuntu20.04
WORKDIR /usr/src/


# Set timezone:
# Set timezone to prevent that one random time library from breaking headless installs.
RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone

# Install dependencies:
RUN apt-get update && apt-get install -y tzdata

# Build
RUN apt-get update && apt-get install -y libxi-dev swig libxmu-dev #mesa-utils
#RUN apt-get update && apt-get install -y libglew-dev glew-utils
RUN apt-get update && apt-get install -y libxrandr-dev libxcursor-dev
RUN apt-get update && apt-get install -y libxinerama-dev libxxf86vm-dev
#RUN apt-get update && apt-get install -y libglfw3 libglfw3-dev

RUN apt-get update && apt-get install -y cmake build-essential

RUN apt-get update && apt-get install -y python3 python3-dev subversion

#RUN apt-get update && apt-get install -y libglvnd0 \
# libgl1 \
# libglx0 \
# libegl1 \
# libxext6 \
# libx11-6

RUN apt-get update && apt-get install -y libfreetype6-dev

RUN apt-get update && apt-get install -y libtiff-dev
RUN apt-get update && apt-get install -y libglu1-mesa-dev
RUN apt-get update && apt-get install -y xterm


WORKDIR /usr/local/src

# Get gvxr
RUN svn checkout svn://zedbluffer@svn.code.sf.net/p/gvirtualxray/code/branches/use-xraylib gvirtualxray-code

WORKDIR /usr/local/src/gvirtualxray-code

RUN svn up

RUN mkdir bin

WORKDIR /usr/local/src/gvirtualxray-code/bin

ENV CC=/usr/bin/gcc
ENV CXX=/usr/bin/g++
RUN cmake \
-DCMAKE_C_COMPILER:STRING=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER:STRING=/usr/bin/g++ \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DBUILD_SIMPLEGVXR:BOOL=ON \
-DBUILD_TESTING:BOOL=ON \
-DUSE_LIBTIFF:BOOL=ON \
-DBUILD_TESTING:BOOL=ON \
-DUSE_SYSTEM_GLFW:BOOL=OFF \
-DUSE_SYSTEM_GLEW:BOOL=OFF \
-DBUILD_WRAPPER_PYTHON3:BOOL=ON \
-DGLEW_USE_STATIC_LIBS:BOOL=ON \
-S .. \
-B .

RUN make assimp -j16

RUN make glew -j16
RUN mkdir gvxr/glew-install/lib64
RUN cp gvxr/glew-install/lib/lib*.a gvxr/glew-install/lib64

RUN make glfw -j16
RUN mkdir glfw-install/lib64
RUN cp glfw-install/lib/lib*.a glfw-install/lib64

RUN make googletest -j16

RUN mkdir third_party/lib64
RUN cp third_party/lib/lib*.a third_party/lib64

# Install system dependencies, npm and micromamba
RUN apt-get update

RUN make gVirtualXRay -j16
RUN make SimpleGVXR -j16
# Headless GPU requirements
RUN apt-get install -y nvidia-headless-515 nvidia-cuda-toolkit nvidia-utils-515 libnvidia-gl-515-server libopengl0 libglvnd0 libgl1 libglx0 libegl1 libgles2 xvfb

RUN apt-get install -y curl git wget npm
RUN wget -qO- https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
RUN ./bin/micromamba shell hook -s posix

RUN make gvxrPython3 -j16
# Copy files for dependencies, these are done explicitly to allow for docker buildstage caching
COPY ./environment.yml .
COPY ./package*.json .

# Install project dependencies
RUN ./bin/micromamba install -y -n base -f ./environment.yml
RUN ./bin/micromamba clean --all --yes
RUN npm install

RUN make -j16
# Copy and build project files
COPY . .
RUN npm run build

# Install
RUN make install
# Workaround for https://github.com/NVIDIA/nvidia-docker/issues/1551
RUN rm -rf /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 /usr/lib/x86_64-linux-gnu/libcuda.so.1

RUN make test
ENV NVIDIA_DRIVER_CAPABILITIES compute,graphics,utility,video

WORKDIR /usr/local/gvxrWrapper-1.0.6/python3/
CMD xterm
EXPOSE 80
CMD [ "bin/micromamba", "run", "gunicorn", "-w 2", "-b 0.0.0.0:80", "webct:app" ]
4 changes: 4 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- python>=3.9
- flask
- scipy
- scikit-image
- matplotlib<3.5
- opencv
- cil
Expand All @@ -27,3 +28,6 @@ dependencies:
- imageio[ffmpeg]
- git+https://bitbucket.org/spekpy/spekpy_release.git
- xpecgen

# Docker
- gunicorn
8 changes: 7 additions & 1 deletion webct/components/sim/simulators/GVXRSimulator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import List, Tuple
from gvxrPython3 import gvxr
from gvxrPython3.json2gvxr import initGVXR
import numpy as np
import platform

from webct.components.Beam import PROJECTION, Beam
from webct.components.Capture import CaptureParameters
Expand Down Expand Up @@ -33,7 +35,11 @@ def __init__(self):
self._initRenderer()

def _initRenderer(self):
gvxr.createWindow(-1, 0, "OPENGL")
if platform.system() == "Windows":
# Use OPENGL for windows
gvxr.createWindow(-1, 0, "OPENGL")
else:
gvxr.createWindow(-1, 0, "EGL")
gvxr.removePolygonMeshesFromSceneGraph()
gvxr.disableArtefactFiltering()
gvxr.setDetectorUpVector(0, 0, -1)
Expand Down