# Introducing SlicerBuildEnvironment project

**URL:** <https://discourse.slicer.org/t/introducing-slicerbuildenvironment-project/2465>\
**Category:** Development\
**Created:** [March 29, 2018, 5:25am UTC](https://discourse.slicer.org/t/introducing-slicerbuildenvironment-project/2465 "2018-03-29T05:25:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [March 29, 2018, 5:25am UTC](https://discourse.slicer.org/t/introducing-slicerbuildenvironment-project/2465/1 "2018-03-29T05:25:19Z")

</div>

### overview

To streamline the continuous integration and allow anyone to easily reproduce builds, we created a new project. Currently, it contains only a Docker directory that itself contain a sub-directory for each build environment.

> **[GitHub - Slicer/SlicerBuildEnvironment: A repository of scripts to set up a Slicer build...](https://github.com/Slicer/SlicerBuildEnvironment)**
>
> A repository of scripts to set up a Slicer build environment.

### table of contents

- [overview](#heading--overview)
- [docker terminology](#heading--docker-terminology)
- [organization](#heading--organization)
- [dockbuild](#heading--dockbuild)
- [available build environment](#heading--available-build-environment)
- step-by-step
  - [(1) configure, build and package Slicer](#heading--step-by-step-1)
  - [(2) configure, build and package a Slicer extension](#heading--step-by-step-2)

- [summary](#heading--summary)
- [next](#heading--next)

### docker terminology

For the one who are not familiar with [Docker](https://en.wikipedia.org/wiki/Docker_%28software%29), it is somewhat like a light-weight virtual machine that can start very efficiently.

Before diving into the details of this project, some terminology:

- `host`: This is your workstation running your preferred operating system.
- `container`: This is what is created after starting up a docker image.
- `docker image`: It is pre-generated using a recipe (the `Dockerfile`) and can be downloaded on the `host`.
- `docker client`: To keep things simple, this is the tool used to run a `docker image`.

### organization

The SlicerBuildEnvironment project has the following organization:

```plaintext
SlicerBuildEnvironment
  |
  |--- Docker
          |--- qt4-centos5
          | |--- Dockerfile
          |
          |--- qt4-ubuntu1004
          | |--- Dockerfile
          |
          |--- qt5-centos7
          | |--- Dockerfile
          |
          |--- Makefile

```

Each sub-directory (e.g `qt5-centos7`) contains a `Dockerfile` allowing to generate a **reusable** build environment (or docker image). That build environment includes a version of qt (e.g `qt5`) and is based on a given operating system (e.g `centos5`).

### dockbuild

The interesting part is that the recipe associated with each SlicerBuildEnvironment image is only responsible to install (or build) Qt, the remaining of the tools forming the complete compiling environment are provided by some other base images provided by the **dockbuild** project.

[dockbuild](https://github.com/dockbuild/dockbuild#readme) is a project responsible to create base docker image that includes a **tested** compiling environment, latest git version, cmake, ninja, python 3 and openssh-client. And also a convenience entrypoint allowing to automatically mount the current working directory into the image.

dockbuild was inspired by [dockcross](https://github.com/dockcross/dockcross), a collection of docker image providing cross-compiling enviroment. It even re-use the same tests and entrypoint script.

### available build environment

```auto
slicer/buildenv-qt4-ubuntu1004:latest
slicer/buildenv-qt4-centos5:latest
slicer/buildenv-qt5-centos7:latest

```

### step-by-step: (1) configure, build and package Slicer

The following steps will:

- download Slicer 4.8.1 source code
- download the associated build environment
- configure, build and package Slicer

```auto
ROOT_DIR=/tmp/Slicer481
mkdir -p $ROOT_DIR

cd ${ROOT_DIR}

# Download sources
svn co http://svn.slicer.org/Slicer4/branches/Slicer-4-8 Slicer -r 26813

# Download corresponding build environment and generate convenience script
docker run --rm slicer/buildenv-qt4-ubuntu1004 > ~/bin/slicer-buildenv-qt4-ubuntu1004
chmod u+x ~/bin/slicer-buildenv-qt4-ubuntu1004

# Configure Slicer
slicer-buildenv-qt4-ubuntu1004 cmake \
  -BSlicer-build -HSlicer \
  -GNinja \
  -DCMAKE_BUILD_TYPE:STRING=Release \
  -DSlicer_USE_PYTHONQT_WITH_TCL:BOOL=OFF \
  -DSlicer_BUILD_CLI:BOOL=OFF \
  -DSlicer_USE_SimpleITK:BOOL=OFF \
  -DBUILD_TESTING:BOOL=OFF

# Build Slicer
slicer-buildenv-qt4-ubuntu1004 cmake --build Slicer-build

# Package Slicer
slicer-buildenv-qt4-ubuntu1004 cmake --build Slicer-build\Slicer-build --target package

```

### step-by-step: (2) configure, build and package a Slicer extension

The following steps will:

- download an extension source code
- configure, build and package the extension using the build generated above

```auto
ROOT_DIR=/tmp/Slicer481

cd ${ROOT_DIR}

EXTENSION_NAME=ImageMaker

# Download extension source
git clone git://github.com/finetjul/ImageMaker ${EXTENSION_NAME}

# Configure the extension
slicer-buildenv-qt4-ubuntu1004 cmake \
  -B${EXTENSION_NAME}-build -H${EXTENSION_NAME} \
  -GNinja \
  -DCMAKE_BUILD_TYPE:STRING=Release \
  -DSlicer_DIR:PATH=/work/Slicer-build/Slicer-build

# Hint: /work is the working directory in the image, it corresponds to 
# the directory from which the script `slicer-buildenv-qt4-ubuntu1004` is called.

# Build the extension
slicer-buildenv-qt4-ubuntu1004 cmake --build ${EXTENSION_NAME}-build

# Package the extension
slicer-buildenv-qt4-ubuntu1004 cmake --build ${EXTENSION_NAME}-build --target package

```

### summary

We presented a collection of Linux based build environment allowing to reproduce build of Slicer, Slicer extension or literally any other project with similar requirements.

This build environment requires to have docker installed and can be used on Linux, macOS or Windows host.

### next

In follow-up posts, we will:

- explain how to run the tests
- describe the `slicer/slicer-base` docker images used for continous integration
- introduce the `slicer/slicer` image (it will be available shortly, and will be a light weight images including Slicer binaries)

In the future, we also plan to add windows docker images, and/or vagrant cookbook to create Windows virtual machines.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 29, 2018, 1:11pm UTC](https://discourse.slicer.org/t/introducing-slicerbuildenvironment-project/2465/2 "2018-03-29T13:11:15Z")

</div>

Thank you @jcfr, this is great! It could be useful to have this nice overview in the SlicerBuildEnvironment documentation pages, too.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [March 30, 2018, 3:56am UTC](https://discourse.slicer.org/t/introducing-slicerbuildenvironment-project/2465/3 "2018-03-30T03:56:01Z")

</div>

Thanks for the feedback.

The project README has been updated.
