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

Toplevel Docker build #70

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
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
77 changes: 77 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Dockerfile for openmoonray base build image
FROM nvidia/cuda:11.4.0-base-centos7 as build
ARG BUILD_JOBS=64

RUN yum install -y epel-release centos-release-scl.noarch
RUN yum install -y devtoolset-9 devtoolset-9-gcc \
devtoolset-9-gcc-c++ devtoolset-9-libatomic-devel
RUN yum install -y bison flex wget git python3 python3-devel \
patch giflib-devel libmng libtiff-devel libjpeg-devel \
libatomic libcgroup-devel libuuid-devel \
openssl-devel curl-devel

# Not required when using cuda:11.4.0-base-centos7
# RUN yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
RUN yum install -y mesa-libGL
RUN yum install -y cuda-toolkit-11-4

# Not needed if you skip building the GUI apps (CMake -DBUILD_QT_APPS=NO)
RUN yum install -y qt5-qtbase-devel qt5-qtscript-devel


# when changing the shell using podman, the --format docker flag must be used
shell ["/usr/bin/scl", "enable", "devtoolset-9"]
RUN echo "source scl_source enable devtoolset-9" >> /etc/profile.d/moonray-development.sh
RUN mkdir -p /usr/local/

# install everything in /usr/local, optix install script is @ /root/optix.sh
RUN mkdir -p /root/build/dependancies
WORKDIR /root/build
RUN git clone --branch v3.23.1 --depth 1 https://github.com/Kitware/CMake.git
RUN cd CMake && ./bootstrap -- -DCMAKE_BUILD_TYPE:STRING=Release && make -j ${BUILD_JOBS} && make install

COPY . /root/build/openmoonray
RUN mkdir -p /usr/local
RUN if [[ -e /root/build/openmoonray/optix.sh ]]; then chmod 755 /root/build/openmoonray/optix.sh && /root/build/openmoonray/optix.sh --prefix=/usr/local --exclude-subdir --skip-license; else echo "please copy the correct version of optix into openmoonray/optix.sh"; false; fi

WORKDIR /root/build/dependancies
RUN cmake -D installDir:PATH=/usr/local ../openmoonray/building
RUN make -j ${BUILD_JOBS}

WORKDIR /root/build/openmoonray
# hack a bit because the container-release has hard-coded paths.
RUN ln -s /usr/local /installs
RUN cmake --preset container-release
RUN cmake --build --preset container-release -- -j ${BUILD_JOBS}
RUN cmake --install /build --prefix /usr/local

WORKDIR /root
run rm -rf /build /root/build


FROM nvidia/cuda:11.4.0-base-centos7

RUN yum install -y epel-release centos-release-scl.noarch
RUN yum install -y python3 giflib libmng libtiff libjpeg \
libatomic libcgroup libuuid \
openssl curl

# Not required when using cuda:11.4.0-base-centos7
# RUN yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
RUN yum install -y mesa-libGL
RUN yum install -y cuda-toolkit-11-4

RUN yum install -y qt5-qtbase-gui

COPY --from=build /usr/local /usr/local
# setup the environment for Moonray
ENV REZ_MOONRAY_ROOT=/usr/local/bin
ENV RDL2_DSO_PATH=/usr/local/rdl2dso:/usr/local/rdl2dso.proxy
ENV MOONRAY_CLASS_PATH=/usr/local/shader_json
ENV PXR_PLUGINPATH_NAME=/usr/local/plugin/usd
ENV ARRAS_SESSION_PATH=/usr/local/sessions
ENV PXR_PLUGIN_PATH=/usr/local/plugin/usd

RUN mkdir -p /project
WORKDIR /project
ENTRYPOINT ["/usr/local/bin/moonray"]
44 changes: 23 additions & 21 deletions building/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ project(openmoonray_third_party)

include(ExternalProject)

set(installDir /installs)
set(installDir /installs CACHE PATH "install directory")

ExternalProject_Add(Blosc
GIT_REPOSITORY https://github.com/Blosc/c-blosc
GIT_TAG a44e961498cdca2eb893fa897cd15dd007fad496 # 1.20.1
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
)

set(PYTHON_VER 3.6)
Expand All @@ -27,7 +27,7 @@ ExternalProject_Add(Boost
URL https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz
UPDATE_COMMAND ./bootstrap.sh --prefix=${installDir}
CONFIGURE_COMMAND ""
BUILD_COMMAND ./b2 install -j64 --user-config=/building/python-config.jam --with_python variant=release toolset=gcc link=shared threading=multi
BUILD_COMMAND ./b2 install -j 4 --user-config=${CMAKE_HOME_DIRECTORY}/python-config.jam variant=release link=shared threading=multi
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
DEPENDS Blosc
Expand All @@ -39,8 +39,9 @@ ExternalProject_Add(JsonCpp
GIT_TAG 15949af09856076b584c7b432f065386ccd267a9 # 0.7.0
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DJSONCPP_LIB_BUILD_SHARED:BOOL=ON
-DJSONCPP_WITH_TESTS:BOOL=OFF
DEPENDS Boost
)

Expand Down Expand Up @@ -71,7 +72,7 @@ ExternalProject_Add(OpenSubdiv
GIT_TAG 82ab1b9f54c87fdd7e989a3470d53e137b8ca270 # v3_4_3
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DCMAKE_BUILD_TYPE=Release
-DNO_PTEX=1 -DNO_OMP=1 -DNO_TBB=1 -DNO_CUDA=1 -DNO_GLFW_X11=1
-DNO_OPENCL=1 -DNO_CLEW=1 -DNO_REGRESSION=1 -DNO_EXAMPLES=1 -DNO_TUTORIALS=1
Expand All @@ -83,7 +84,7 @@ ExternalProject_Add(OpenEXR
GIT_TAG 8bc3741131db146ad08a5b83af9e6e48f0e94a03 # v2.5.7
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DBUILD_SHARED_LIBS=OFF
DEPENDS OpenSubdiv
)
Expand All @@ -102,9 +103,10 @@ ExternalProject_Add(OpenVDB
GIT_REPOSITORY https://github.com/AcademySoftwareFoundation/openvdb
GIT_TAG 88ae51a34ca70a23442dc60bba83894f35f7f728 # v8.2.0
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBLOSC_ROOT=/usr
CMAKE_ARGS
-DTBB_ROOT:PATH=${installDir}
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DBLOSC_ROOT:PATH=${installDir}
DEPENDS TBB
)

Expand All @@ -113,7 +115,7 @@ ExternalProject_Add(Log4CPlus
GIT_TAG bd2dfe9ef0817277a7d41fadecd84addaf943fe3 # REL_1_1_2
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
DEPENDS OpenVDB
)

Expand Down Expand Up @@ -148,12 +150,12 @@ ExternalProject_Add(ISPC
ExternalProject_Add(embree
GIT_REPOSITORY https://github.com/embree/embree
GIT_TAG 69bd4c272f1ed608494f233ecfff3feec516880b # v3.12.1
PATCH_COMMAND patch -p1 < /building/embree_missing_type.patch
PATCH_COMMAND patch -N -p1 < ${CMAKE_HOME_DIRECTORY}/embree_missing_type.patch
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DEMBREE_ISPC_EXECUTABLE=<INSTALL_DIR>/bin/ispc
-DEMBREE_TBB_ROOT=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DEMBREE_ISPC_EXECUTABLE=${installDir}/bin/ispc
-DEMBREE_TBB_ROOT=${installDir}
-DEMBREE_IGNORE_INVALID_RAYS=ON
-DEMBREE_RAY_MASK=ON
-DEMBREE_MAX_ISA=AVX
Expand All @@ -167,7 +169,7 @@ ExternalProject_Add(OpenColorIO
GIT_TAG 056b7b0cb0d087961e9dba75104820e44faf52a1 # v2.0.2
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DBUILD_SHARED_LIBS=ON
-DOCIO_BUILD_STATIC=OFF
-DCMAKE_CXX_STANDARD=17
Expand All @@ -179,8 +181,8 @@ ExternalProject_Add(OpenImageIO
GIT_TAG 55ebad1f77f06527b23b4fe9d0da81fe8d0ecdc8 # 2.2.15.1
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DOpenEXR_ROOT=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DOpenEXR_ROOT=${installDir}
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DUSE_QT=0
-DUSE_PYTHON=0
DEPENDS OpenColorIO
Expand All @@ -192,9 +194,9 @@ ExternalProject_Add(OpenImageDenoise
# GIT_TAG d959bac5b7130b31c41095811ddfbe58c4cf03f4 # 1.4.3
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DISPC_EXECUTABLE=<INSTALL_DIR>/bin/ispc
-DTBB_ROOT=<INSTALL_DIR>
-DCMAKE_INSTALL_PREFIX:PATH=${installDir}
-DISPC_EXECUTABLE=${installDir}/bin/ispc
-DTBB_ROOT=${installDir}
-DOIDN_APPS=OFF
DEPENDS OpenImageIO
)
Expand All @@ -205,7 +207,7 @@ ExternalProject_Add(USD
GIT_TAG 3b097e3ba8fabf1777a1256e241ea15df83f3065 # v22.05
INSTALL_DIR ${installDir}
CMAKE_ARGS
-DCMAKE_PREFIX_PATH=<INSTALL_DIR>
-DCMAKE_PREFIX_PATH=${installDir}
-DPXR_ENABLE_PYTHON_SUPPORT=ON
-DPXR_USE_PYTHON_3=ON
-DTBB_USE_DEBUG_BUILD=OFF
Expand Down
99 changes: 18 additions & 81 deletions building/container_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,115 +3,52 @@
You will need Docker and a copy of the MoonRay source. The instructions assume that the source is in */source/openmoonray*

NVIDIA Optix headers need to be downloaded manually from [here](https://developer.nvidia.com/designworks/optix/downloads/legacy), since they require a EULA.
Be sure to download version 7.3, as MoonRay is not yet compatible with their more recent releases.
The instructions assume that these are in */optix/include*.

Substitute */source/openmoonray* and */optix* for the actual locations wherever they appear in the instructions.

---
## Step 1. Base requirements
---

The base image for building MoonRay in a container is constructed using *Dockerfile* in the *building* directory of the MoonRay source. It contains a number of MoonRay dependencies that are installed using *yum*, the Centos-7 package manager. It also intalls CMake, needed for Step 2.

You can remove the Qt5 packages from the Dockerfile if you do not intend to build the MoonRay GUI programs.

```bash
> cd /source/openmoonray/building
> docker build -t openmoonray_base . --file Dockerfile
```
Be sure to download version 7.3, as MoonRay is not yet compatible with their more recent releases. The Optix installer must be renamed `optix.sh` and placed in the top level of the checkout.

---
## Step 2. Build the remaining dependencies
## Step 1. build docker
---

Apart from Optix, the remaining MoonRay dependencies can be built from source and installed using CMake. *CMakeLists.txt* in the *building* directory contains a series of targets that download the sources and build each dependency.


Start the base container from step 1.
Build using the `Dockerfile` in the top level of the MoonRay source. The build requires `optix.sh` to be present, and the correct version. Download the installer from the link above, and rename it to `optix.sh`. By default, the build uses 64 compile jobs, this may be adjusted using `--build-arg BUILD_JOBS=8`.

```bash
> docker run -v /source/openmoonray/building:/building:shared -v /optix:/optix:shared --network=host --rm -it openmoonray_base
docker build --tag openmoonray/moonray .
# docker build --build-arg BUILD_JOBS=8 --tag openmoonray/moonray .
```

Run the CMake external projects build. The targets are set up to build one at a time. The build takes about 20 minutes on my machine.
If using [podman](https://podman.io/), the `--format docker` flag is required

```bash
> cd /build
> cmake ../building
> cmake --build . -- -j 64
docker build --format docker --tag openmoonray/moonray .
```

Clean up the build residue, and copy the Optix headers into */installs*
To execute `moonray` on an input file, the host filesystem must be mounted in the Docker image using `/project` as the default. `openmoonray` is the entrypoint in the Docker image. To render `testdata/rectangle.rdla`, mount the top level of the MoonRay source to `/project` with relative arguments. The `testdata/rectangle.rdla` will be mapped to `/project/testdata/rectangle.rdla` within the Docker container. Because the working directory is `/project` the same relative paths will be used.

```bash
> rm -rf /build/*
> mkdir /installs/optix
> cp -r /optix/include /installs/optix
docker run --rm -v $(pwd):/project openmoonray/moonray -info -in testdata/rectangle.rdla -out testdata/rectangle.exr
```

The dependencies required to build openmoonray are now installed into the container.

To avoid re-running this step, commit the image as **openmoonray_build**. In another shell:

```bash
> docker ps

CONTAINER ID IMAGE ...
c3a90b08a53a openmoonray_base ...

> docker commit c3a90b08a53a openmoonray_build
```

You can then exit the container.

---
## Step 3. Build MoonRay
## Step 2. build gui docker
---

The entire OpenMoonRay code base is built by running CMake at the top level of the source tree. The locations of dependencies are provided to the build system using a CMake preset defined in *CMakePresets.json*. The source tree already contains a preset for building in a container created following the process described here, called **container-release**.

To continue the container build process, run the **openmoonray_build** container with the OpenMoonRay source mounted.
The `gui` directory contains a `Dockerfile` for building on the `openmoonray/moonray` image in the previous step. It uses [`noVNC`](https://github.com/novnc/noVNC) and [`easy-novnc`](https://github.com/pgaskin/easy-novnc) to host the gui in a web browser. If building under `podman`, the `SHELL` command warning may be ignored, or suppressed using the `--format docker` flag.

```bash
> docker run -v /source/openmoonray:/openmoonray:shared -v /tmp:/tmp:shared --network=host --rm -it openmoonray_build
docker build --tag openmoonray/moonray-gui ./gui
```

cd to the root of the source and build openmoonray:
To run the `moonray_gui` launch the docker, then open `http://localhost:8080` to interact with the desktop. The VNC password is `moonray`.

```bash
> cd /openmoonray
> cmake --preset container-release
> cmake --build --preset container-release -- -j 64
> mkdir /installs/openmoonray
> cmake --install ../build --prefix /installs/openmoonray
docker run -it --rm -v $(pwd):/project -p 8080:8080 openmoonray/moonray-gui
```
The configure step will report failure to find Mkl (unless you happen to have it installed). This does not cause a problem : Mkl is only linked into the commands if it was found.

If you are building without Qt, add the argument ***-DBUILD_QT_APPS=NO*** to the first cmake command.

Set up the install and test moonray
Click "Use default config" when the `xfce` window manager asks for the initial setup, and the "XFCE PolicyKit Agent" error can be ignored. Click the terminal icon in the bottom tray to open a terminal then run the `moonray_gui` application.

```bash
> source /installs/openmoonray/scripts/setup.sh
> moonray -in /openmoonray/testdata/rectangle.rdla -out /tmp/rectangle.exr
# in GUI terminal window
moonray_gui -in testdata/rectangle.rdla
```

To commit **openmoonray_run**, follow the same procedure as step 2.

---

## 4. Running moonray_gui
---

To run **moonray_gui**, you need to set up X in the container. The steps required may vary depending on the host setup, but generally you will need to set the environment variables ***DISPLAY*** and ***XAUTHORITY***, and make sure the directory that *XAUTHORITY* points to is mounted in the container.

You may also need to install additional packages. On my machine, the hotkeys in moonray_gui do not function if package *libxkbcommon-x11* is not installed.

```bash
> docker run -v /source/openmoonray:/openmoonray:shared -v /tmp:/tmp:shared -e DISPLAY=$DISPLAY -e XAUTHORITY=${XAUTHORITY} -v "${XAUTHORITY}:${XAUTHORITY}:z" --network=host --rm -it openmoonray_run

> yum install -y libxkbcommon-x11
> source /installs/openmoonray/scripts/setup.sh
> moonray_gui -in /openmoonray/testdata/rectangle.rdla -out /tmp/rectangle.exr
```
![screenshot](moonray_gui_screenshot.png)
23 changes: 23 additions & 0 deletions gui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM openmoonray/moonray
# docker build --format docker --tag openmoonray/moonray .
# docker build --tag openmoonray/moonray-gui .
# docker run -it --rm --publish 8080:8080 openmoonray/moonray-gui

RUN yum install -y tigervnc-server epel-release go
RUN yum groupinstall -y xfce

RUN go install github.com/geek1011/easy-novnc@v1.1.0

RUN mkdir -p /root/.vnc
RUN echo moonray | vncpasswd -f > /root/.vnc/passwd
run chmod 0600 /root/.vnc/passwd

COPY --chmod=755 xstartup /root/.vnc/
COPY config /root/.vnc/
run touch .Xauthority

COPY --chmod=755 run-vncserver /root/run-vncserver

# expose the noVNC port, run forever
EXPOSE 8080
ENTRYPOINT ["/root/run-vncserver"]
10 changes: 10 additions & 0 deletions gui/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=2000x1200
dpi=96
# localhost
# alwaysshared
Binary file added gui/moonray_gui_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions gui/run-vncserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash

# start vnc viewer
vncserver > /dev/null 2>&1

# start the novnc server
/root/go/bin/easy-novnc --port 5901 --host localhost
Loading