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

adding docker and singularity container recipes and instructions #2906

Merged
merged 2 commits into from Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,6 +7,7 @@
*.xml~
*.yaml~
*.wpu
*.sif
Thumbs.db

# Files generated by setup.py and related tools
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ To get the latest version of the game, you have to build it from source:
* [Instructions for Windows](https://github.com/unknown-horizons/unknown-horizons/wiki/Windows)
* [Instructions for OS X](https://github.com/unknown-horizons/unknown-horizons/wiki/MacOS)

If you want to start hacking on Unknown Horizons, check out [this guide](https://github.com/unknown-horizons/unknown-horizons/wiki/Getting-started) and contact us to help you get started. We have easy tasks for starters [here](https://github.com/unknown-horizons/unknown-horizons/issues?q=is%3Aopen+is%3Aissue+label%3AD-starter).
If you want to start hacking on Unknown Horizons, check out [this guide](https://github.com/unknown-horizons/unknown-horizons/wiki/Getting-started) and contact us to help you get started. A [development workflow](development/docker/) with containers is also available. We have easy tasks for starters [here](https://github.com/unknown-horizons/unknown-horizons/issues?q=is%3Aopen+is%3Aissue+label%3AD-starter).


## Dependencies
Expand Down
66 changes: 66 additions & 0 deletions development/docker/Dockerfile
@@ -0,0 +1,66 @@
FROM ubuntu:18.04

# docker build -f development/docker/Dockerfile -t unknown-horizons .

RUN apt-get update && \
apt-get install -y build-essential \
libalsa-ocaml-dev \
libsdl2-dev \
libboost-dev \
libsdl2-ttf-dev \
libsdl2-image-dev \
libvorbis-dev \
libalut-dev \
python3 \
python3-dev \
libboost-regex-dev \
libboost-filesystem-dev \
libboost-test-dev \
swig \
zlib1g-dev \
libopenal-dev \
git \
python3-yaml \
libxcursor1 \
libxcursor-dev \
cmake \
cmake-data \
libtinyxml-dev \
libpng-dev \
libglew-dev \
python3-enet \
intltool \
python3-pillow \
python3-future

# Install Fifengine and Fifechan
RUN git clone https://github.com/fifengine/fifechan.git && \
cd fifechan && \
mkdir _build && \
cd _build && \
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && \
make && make install

RUN git clone https://github.com/fifengine/fifengine.git && \
cd fifengine && \
mkdir _build && \
cd _build && \
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DPYTHON_EXECUTABLE=/usr/bin/python3 .. && \
make && make install

RUN mkdir -p /code
ADD . /code
WORKDIR /code
RUN python3 setup.py build_i18n && \
adduser --disabled-password --gecos "" horizonuser
RUN usermod -a -G video horizonuser
USER horizonuser
RUN mkdir -p ~/.config/unknown-horizons/ && \
cp content/settings-template.xml ~/.config/unknown-horizons/settings.xml

# Also create config for root user that can leverage video
USER root
RUN mkdir -p ~/.config/unknown-horizons/ && \
cp content/settings-template.xml ~/.config/unknown-horizons/settings.xml

ENTRYPOINT ["python3", "/code/run_uh.py"]
79 changes: 79 additions & 0 deletions development/docker/README.md
@@ -0,0 +1,79 @@
# Running in a Container

This tutorial will cover how to build and run unknown horizons in a container.
Specifically, since we need to access the host video card, we need a container
that is seamless to the host hardware and environment. [Singularity](sylabs.io/guides/3.1/user-guide/)
containers will let us easily do that, and we can build a container
using Docker that will be pulled into a Singularity container.

## Docker + Singularity

The [Dockerfile](Dockerfile) in this folder represents the build recipe for the
container. Here we install all dependencies, and additionally the
Fifengine and Fifechan libraries, and then unknown horizons directly from the
repository. Here is how the build can be done locally, from the root of the
repository:


```bash
$ docker build -f development/docker/Dockerfile -t unknown-horizons .
```

At this point, we need to push to Docker Hub (or other registry) so that we can run
with a Singularity container. Here is how I would tag the container with a different
name, and push:

```bash
$ docker tag unknown-horizons vanessa/unknown-horizons:dev
$ docker push vanessa/unknown-horizons:dev
```

Great! And now that the container is in a registry, we can easily pull it
into a Singularity container. Note that if you haven't installed Singularity,
you can [do that first](https://www.sylabs.io/guides/3.1/user-guide/quick_start.html#quick-installation-steps).

```bash
$ singularity pull docker://vanessa/unknown-horizons:dev
```

This testing container is available for you to [use](https://hub.docker.com/r/vanessa/unknown-horizons/tags). It was created with commit ``.

This command will pull the container into the present working directory. It's a sif file,
which is a compressed (read only) filesystem that is optimized for running on HPC.
The default name it gets pulled to is `unknown-horizons_dev.sif` (and note you
can rename it, or use --name to specify a different name on pulling.)

```bash
$ ls *.sif
unknown-horizons_dev.sif
```

Finally, you can run it! Just run the container. The entrypoint is the run_uh.py script.

```bash
$ singularity run unknown-horizons_dev.sif
```

The game will open in a window for you to play.

![game.png](game.png)

This Docker + Singularity approach is a good production workflow, because it will
allow you to build updated versions on Continuous Integration and release to
Docker Hub, and have users pull the container via Singularity. It doesn't work
well to develop / test since we can't easily use the devices on our machine.
If you need to interactively shell inside:

```bash
$ docker run --entrypoint bash -it unknown-horizons
```

# Singularity

As an alternative, if you don't want to rely on Docker Hub (or Docker at all) you can
just build a Singularity container. The [Singularity](Singularity) recipe in this
folder can build a container on your host directly:

```bash
$ sudo singularity build uh.sif development/docker/Singularity
```
64 changes: 64 additions & 0 deletions development/docker/Singularity
@@ -0,0 +1,64 @@
Bootstrap: docker
From:ubuntu:18.04

# sudo singularity build uh.sif docker/Singularity

%setup
mkdir -p ${SINGULARITY_ROOTFS}/code
cp -R . ${SINGULARITY_ROOTFS}/code

%post
apt-get update && \
apt-get install -y build-essential \
libalsa-ocaml-dev \
libsdl2-dev \
libboost-dev \
libsdl2-ttf-dev \
libsdl2-image-dev \
libvorbis-dev \
libalut-dev \
python3 \
python3-dev \
libboost-regex-dev \
libboost-filesystem-dev \
libboost-test-dev \
swig \
zlib1g-dev \
libopenal-dev \
git \
python3-yaml \
libxcursor1 \
libxcursor-dev \
cmake \
cmake-data \
libtinyxml-dev \
libpng-dev \
libglew-dev \
python3-enet \
intltool \
python3-pillow \
python3-future

# Install Fifengine and Fifechan
git clone https://github.com/fifengine/fifechan.git && \
cd fifechan && \
mkdir _build && \
cd _build && \
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && \
make && make install

git clone https://github.com/fifengine/fifengine.git && \
cd fifengine && \
mkdir _build && \
cd _build && \
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DPYTHON_EXECUTABLE=/usr/bin/python3 .. && \
make && make install

cd /code
python3 setup.py build_i18n && \
adduser --disabled-password --gecos "" horizonuser
su horizonuser -c "mkdir -p /home/horizonuser/.config/unknown-horizons/"
su horizonuser -c "cp /code/content/settings-template.xml /home/horizonuser/.config/unknown-horizons/settings.xml"

%runscript
exec /usr/bin/python3 /code/run_uh.py "$@"
Binary file added development/docker/game.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.