diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..08b2553 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/Dockerfile b/Dockerfile index 01e85b9..2b52dc4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/environment.yml b/environment.yml index c4b155c..77db437 100644 --- a/environment.yml +++ b/environment.yml @@ -10,6 +10,7 @@ dependencies: - python>=3.9 - flask - scipy + - scikit-image - matplotlib<3.5 - opencv - cil @@ -27,3 +28,6 @@ dependencies: - imageio[ffmpeg] - git+https://bitbucket.org/spekpy/spekpy_release.git - xpecgen + + # Docker + - gunicorn diff --git a/webct/components/sim/simulators/GVXRSimulator.py b/webct/components/sim/simulators/GVXRSimulator.py index 5ffe84c..6fe1d50 100644 --- a/webct/components/sim/simulators/GVXRSimulator.py +++ b/webct/components/sim/simulators/GVXRSimulator.py @@ -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 @@ -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)