Commit 64502c49 authored by Scott Wittenburg's avatar Scott Wittenburg
Browse files

Split Docker images into development and runtime builds

The development images leave everything in place, useful for building
plugins against a specific version of ParaView.  These also split the
build up into more RUN commands, so that if one step fails, any issues
can be more easily investigated.

The runtime images are multi-stage builds, starting from the development
images, and then taking a clean base image and only installing a subset
of the system packages used in the development build, then copying the
ParaView install tree into the final image.

The runtime images, as a result, are now smaller than previous Docker
images generated from the Scripts/docker/ubuntu/Dockerfile.
parent fe82123e
# Introduction
The goal of this document is to describe the `Dockerfile` in this directory and how to use it to build, deploy, and run a variety of ParaView Docker images.
The goal of this document is to describe the various Docker images that can be built using the files within this directory and how to build, deploy, and run them.
There are two different `Dockerfiles` included here, one for building development images, the other for building runtime images on top of the development images.
The basic idea of the `Dockerfile` is that it will first install some packages needed for running the ParaView Superbuild, then clone the superbuild and use the `CMake` initial cache located in `cmake/sites/Docker-Ubuntu-18_04.cmake` to provide the build options.
Images built from the development `Dockerfile` are useful for building custom plugins against a target version of ParaView, as well as for debugging broken builds. In the development images, cmake is left in place, as well as the entire filesystem used during the superbuild (including build tree, downloads, etc.). Additionally, the `Dockerfile` is split into many run commands, so that if part of the build fails, you can get into the container resulting from the previous step and investigate.
Images built from the runtime `Dockerfile` are multi-stage builds that rely both on the base container of the development images, as well as the development images themselves. These images only take the paraview install tree from the development image, resulting the smallest possible runtime container.
## Building images
This section describes building the ParaView `Docker` images using the `Dockerfile` in this directory.
This section describes building the ParaView `Docker` images using the `Dockerfiles` in this directory. The basic idea is to first build the development image, experiment with it until you are convinced you have a working build, then build the runtime image on top of it. Here is a simple example of building both images:
```
cd Scripts/docker/ubuntu/development
docker build -t pv-release-egl-py2-devel .
cd ../runtime
docker build --build-arg PV_DEV_BASE_IMAGE=pv-release-egl-py2-devel -t pv-release-egl-py2-runtime
```
### Description of build arguments
### Description of development build arguments
The `Dockerfile` accepts several build arguments (provided in the form `--build-arg OPTION=VALUE`) allowing the user to specify the following build options:
The development `Dockerfile` accepts several build arguments (provided in the form `--build-arg OPTION=VALUE`) allowing the user to specify the following build options:
#### `BASE_IMAGE`
......@@ -52,6 +65,22 @@ where `${PYTHON_VERSION}` is interpreted from the user-supplied python version.
PIP_CMD="${!SYSTEM_PYTHON_PIP}"
```
### Description of runtime build arguments
The runtime `Dockerfile` accepts only three arguments, and this section describes the constraints on those options. The runtime build uses the development image built previously as the first stage in the build, so that we can later take the build tree from that image. The second stage starts from a clean base image, and applies a subset of the packages and steps used to build the development image, so that the libraries needed by ParaView will be found in the expected locations.
#### `BASE_IMAGE`
This argument must be the same as was used for the `BASE_IMAGE` for the development build.
#### 'PV_DEV_BASE_IMAGE'
This argument should be the tag used when creating the development image previously.
#### 'PYTHON_VERSION'
This argument must be the same as the one used to create the development image previously.
### Build command-line examples
The simplest build just accepts all the defaults:
......
......@@ -38,13 +38,6 @@
#
# "master", "v5.6.0", <branch-name>, etc...
#
# DEV_BUILD
#
# false
# true
#
# (default is "false" -> build tree and cmake are removed)
#
# PYTHON_VERSION
#
# 2
......@@ -52,6 +45,10 @@
#
# (default is "2")
#
# BUILD_TYPE
#
# "Release", or "Debug" (Default: "Release")
#
ARG BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
FROM ${BASE_IMAGE}
......@@ -60,8 +57,8 @@ ARG RENDERING=egl
ARG PARAVIEW_TAG=v5.7.0
ARG SUPERBUILD_TAG=v5.7.0
ARG SUPERBUILD_REPO=https://gitlab.kitware.com/paraview/paraview-superbuild.git
ARG DEV_BUILD=false
ARG PYTHON_VERSION=2
ARG BUILD_TYPE=Release
# The following environment variables help with the Python 2 vs 3 option while
# we still support both of them. In order for this approach to work, we need
......@@ -98,15 +95,24 @@ RUN groupadd pv-user && \
USER pv-user
# Get CMake, then clone the ParaView superbuild project
# Get CMake
RUN mkdir -p /home/pv-user/cmake/3.13.4 && cd /home/pv-user/cmake/3.13.4 && \
curl -L https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.tar.gz | tar --strip-components=1 -xzv && \
mkdir -p /home/pv-user/pvsb && cd /home/pv-user/pvsb && \
curl -L https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.tar.gz | tar --strip-components=1 -xzv
# Clone the superbuild
RUN mkdir -p /home/pv-user/pvsb/build && cd /home/pv-user/pvsb && \
git clone --recursive ${SUPERBUILD_REPO} src && \
cd src && git checkout ${SUPERBUILD_TAG} && git submodule update && cd .. && \
mkdir build && cd build && \
/home/pv-user/cmake/3.13.4/bin/cmake -C /home/pv-user/pvsb/src/cmake/sites/Docker-Ubuntu-18_04.cmake "-GUnix Makefiles" ../src && \
make -j"$(nproc)" install && \
if [ "${DEV_BUILD}" != "true" ] ; then rm -rf /home/pv-user/pvsb && rm -rf /home/pv-user/cmake ; fi
cd src && git checkout ${SUPERBUILD_TAG} && git submodule update
WORKDIR /home/pv-user/pvsb/build
# Configure
RUN /home/pv-user/cmake/3.13.4/bin/cmake -C /home/pv-user/pvsb/src/cmake/sites/Docker-Ubuntu-18_04.cmake "-GUnix Makefiles" ../src
# Build
RUN make -j"$(nproc)"
# Install
RUN make -j"$(nproc)" install
WORKDIR /opt/paraview
#
# This Dockerfile allows copying only the ParaView install tree from the
# development image. To be sure the resulting paraview binaries work, you
# must still use, as the second-stage base image, the same base image used
# to build the development image.
#
# To build this image:
#
# $ docker build \
# --build-arg PV_DEV_BASE_IMAGE=pv-v5.7.1-egl-py3-dev \
# -t pv-v5.7.1-egl-py3-rel \
# .
#
# To customize the image used as the second-stage base, use the `BASE_IMAGE`
# build argument:
#
# $ docker build \
# --build-arg PV_DEV_BASE_IMAGE=pv-v5.7.1-egl-py3-dev \
# --build-arg BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04 \
# -t pv-v5.7.1-egl-py3-rel \
# .
#
ARG BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
ARG PV_DEV_BASE_IMAGE=pv-dev-image
# Start with the pv development image so we can copy from it
FROM ${PV_DEV_BASE_IMAGE} AS devimage
# Now pick the base of that image as our new base
FROM ${BASE_IMAGE} AS baseimage
# Now install python the same same way we did in the base
ARG PYTHON_VERSION=2
# The following environment variables help with the Python 2 vs 3 option while
# we still support both of them. In order for this approach to work, we need
# the RUN command to use bash instead of sh for variable indirection.
SHELL ["/bin/bash", "-c"]
ENV SYSTEM_PYTHON_2_PIP pip
ENV SYSTEM_PYTHON_3_PIP pip3
ENV SYSTEM_PYTHON_PIP "SYSTEM_PYTHON_${PYTHON_VERSION}_PIP"
RUN apt-get update && \
if [ "${PYTHON_VERSION}" = "2" ]; then apt-get install -y --no-install-recommends python2.7-dev python-pip python-setuptools; fi && \
if [ "${PYTHON_VERSION}" = "3" ]; then apt-get install -y --no-install-recommends python3-dev python3-pip python3-setuptools; fi && \
if [ "${PYTHON_VERSION}" = "3" ]; then update-alternatives --install /usr/bin/python python /usr/bin/python3 1; fi && \
rm -rf /var/lib/apt/lists/*
# Re-create the non-root user we had in development image
RUN groupadd pv-user && \
useradd -g pv-user -d /home/pv-user pv-user && \
mkdir /home/pv-user && chown -R pv-user:pv-user /home/pv-user
# Now copy the installed paraview from the development image, using
# the non-root user as the owner.
COPY --from=devimage --chown=pv-user:pv-user /opt/paraview /opt/paraview
USER pv-user
WORKDIR /opt/paraview
......@@ -21,6 +21,7 @@ From: nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
SUPERBUILD_REPO=https://gitlab.kitware.com/paraview/paraview-superbuild.git
DEV_BUILD=false
PYTHON_VERSION=2
BUILD_TYPE=Release
# First install some packages we need
apt-get -y update
......@@ -54,6 +55,7 @@ From: nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
export PARAVIEW_TAG=${PARAVIEW_TAG}
export RENDERING=${RENDERING}
export PYTHON_VERSION=${PYTHON_VERSION}
export BUILD_TYPE=${BUILD_TYPE}
# Configure/build/install ParaView
/home/pv-user/cmake/3.13.4/bin/cmake -C /home/pv-user/pvsb/src/cmake/sites/Docker-Ubuntu-18_04.cmake "-GUnix Makefiles" ../src
......
......@@ -19,6 +19,7 @@ From: ubuntu:18.04
SUPERBUILD_REPO=https://gitlab.kitware.com/paraview/paraview-superbuild.git
DEV_BUILD=false
PYTHON_VERSION=2
BUILD_TYPE=Release
# First install some packages we need
echo "\ndeb http://us.archive.ubuntu.com/ubuntu/ bionic universe\n" >> /etc/apt/sources.list
......@@ -54,6 +55,7 @@ From: ubuntu:18.04
export PARAVIEW_TAG=${PARAVIEW_TAG}
export RENDERING=${RENDERING}
export PYTHON_VERSION=${PYTHON_VERSION}
export BUILD_TYPE=${BUILD_TYPE}
# Configure/build/install ParaView
/home/pv-user/cmake/3.13.4/bin/cmake -C /home/pv-user/pvsb/src/cmake/sites/Docker-Ubuntu-18_04.cmake "-GUnix Makefiles" ../src
......
......@@ -39,7 +39,7 @@ set(PARAVIEW_DEFAULT_SYSTEM_GL OFF CACHE BOOL "")
# Some general options
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
set(CMAKE_BUILD_TYPE $ENV{BUILD_TYPE} CACHE STRING "")
set(BUILD_TESTING ON CACHE BOOL "")
# ParaView related
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment