From f3416785ca4a4f73d35b20407378f42ff268fc44 Mon Sep 17 00:00:00 2001 From: WYVERN <35181365+WYVERN2742@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:55:55 +0100 Subject: [PATCH 1/2] feat: :construction: WIP - setup docker environment for building Setup docker environment to build webCT using the environment.yml and npm package.json files. Currently there's an issue with conda envionments not linking into the shell, more investigation is needed but iterating with docker is v. painful --- .dockerignore | 1 + Dockerfile | 108 ++++++++------------------------------------------ 2 files changed, 18 insertions(+), 91 deletions(-) create mode 100644 .dockerignore 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..c61875f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,98 +1,24 @@ -# 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 - - -RUN make gVirtualXRay -j16 -RUN make SimpleGVXR -j16 - - -RUN make gvxrPython3 -j16 - - -RUN make -j16 +# Install system dependencies, npm and micromamba +RUN apt-get update +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 -# Install -RUN make install +# Copy files for dependencies, these are done explicitly to allow for docker buildstage caching +COPY ./environment.yml . +COPY ./package*.json . -RUN make test +# Install project dependencies +RUN ./bin/micromamba install -y -n base -f ./environment.yml +RUN ./bin/micromamba clean --all --yes +RUN npm install -WORKDIR /usr/local/gvxrWrapper-1.0.6/python3/ -CMD xterm +# Copy and build project files +COPY . . +RUN npm run build From 0b561c7d1ead04d1a35d9f09b75c45a47ff5b02d Mon Sep 17 00:00:00 2001 From: WYVERN <35181365+WYVERN2742@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:17:34 +0100 Subject: [PATCH 2/2] feat: :construction: WIP - Webserver and nvidia libraries Added gunicorn for the webserver, along with libraries to run nvidia gpus headlessly. At the moment, still unable to get EGL or OPENGL working on windows docker --- Dockerfile | 12 ++++++++++++ environment.yml | 4 ++++ webct/components/sim/simulators/GVXRSimulator.py | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c61875f..2b52dc4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,10 @@ RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONT # Install system dependencies, npm and micromamba RUN apt-get update + +# 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 @@ -22,3 +26,11 @@ RUN npm install # Copy and build project files COPY . . RUN npm run build + +# 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 + +ENV NVIDIA_DRIVER_CAPABILITIES compute,graphics,utility,video + +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)