added docker files to allow testing with different cmake versions for #8

This commit is contained in:
ttroy50
2016-04-15 00:01:59 +01:00
parent 1208416848
commit 4e0dbb6bbf
7 changed files with 203 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
#!/bin/bash
ROOT_DIR=`pwd`
dir="01-basic/I-compiling-with-clang"
if [ -d "$ROOT_DIR/$dir/build.clang" ]; then
echo "deleting $dir/build.clang"
rm -r $dir/build.clang
fi

View File

@@ -0,0 +1,9 @@
#!/bin/bash
ROOT_DIR=`pwd`
dir="01-basic/J-building-with-ninja"
if [ -d "$ROOT_DIR/$dir/build.ninja" ]; then
echo "deleting $dir/build.ninja"
rm -r $dir/build.ninja
fi

80
dockerfiles/README.adoc Normal file
View File

@@ -0,0 +1,80 @@
= CMake Examples with Docker
:toc:
:toc-placement!:
toc::[]
# Docker
https://www.docker.com/[Docker] allows you to package software in a container which contains a filesystem with all dependencies. This allows having containers which include everything needed to run and test our examples. And as a result of packaging all dependencies we can create containers to include different versions of cmake so that it is possible to easily make sure our examples work for many cmake versions.
# Building
To build a container from the this directory run the following:
[source,bash]
----
$ docker build --rm -f <dockerfile> -t <container tag> .
----
For example:
[source,bash]
----
$ docker build --rm -f ubuntu14.04-cmake-3.4.3 t matrim/cmake-examples:3.4.3 .
----
In this example the tag is created as follows
<docker user>/<repository>:<cmake version>
This will tag the container as belong to my repositry with the label of the container being the version of cmake installed.
## Pre-build Images
I have pre-build images and pushed them to the https://hub.docker.com[docker hub] in the repository https://hub.docker.com/r/matrim/cmake-examples/[matrim/cmake-examples].
The images available include the following versions of cmake:
* Ubuntu 14.04 with CMake 2.8.12.2
$ docker pull docker pull matrim/cmake-examples:2.8.12.2
* Ubuntu 14.04 with CMake 3.4.3
$ docker pull docker pull matrim/cmake-examples:3.4.3
# Running
When run the images will automatically create a non root user called devuser, with a default command to launch a bash shell in the users home directory.
If you want to set the UID and GID for this user you can pass them in via the environment variables `DEV_UID` and `DEV_GID`
For example
[source,bash]
----
docker run -e DEV_UID=`id -u` -e DEV_GID=`id -u` -it matrim/cmake-examples:3.4.3
----
To build the full set of cmake-examples test cases you can run:
[source,bash]
----
docker run -it matrim/cmake-examples:3.4.3
git clone https://github.com/ttroy50/cmake-examples.git
cd cmake-examples
./test.sh
----
If you already have a checkout of the cmake-examples you can load the directory as a docker volume.
Below is an example of loading a volume and automatically running all cmake-example test cases:
[source,bash]
----
docker run -e DEV_UID=`id -u` -e DEV_GID=`id -u` -v /checkout/directory:/data/code -it matrim/cmake-examples:3.4.3 /data/code/test.sh
----

26
dockerfiles/setup.sh Normal file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
# Setup script for the cmake-examples repository
# Will create a non root user using the UID and GID passed in from environment
# variables and give them sudo access
#
ret=false
output=`getent passwd devuser 2&>1`
result=$?
if [ $result -ne 0 ] ; then
echo "Creating devuser"
if [ -z $DEV_UID ]; then
DEV_UID=1000
fi
if [ -z $DEV_GID ]; then
DEV_GID=1000
fi
groupadd -g $DEV_GID devgroup
useradd -c 'container user' -u $DEV_UID -g $DEV_GID -d /home/devuser -m devuser
echo "devuser:todo_$DEV_UID_$DEV_GID" | chpasswd
sudo adduser devuser sudo
echo "%sudo ALL=NOPASSWD: ALL" >> /etc/sudoers
fi
exec /bin/su - devuser -c "$@"

View File

@@ -0,0 +1,34 @@
# Container for building and testing cmake-examples with cmake v3.4.3
FROM ubuntu:14.04
MAINTAINER Thom Troy
RUN apt-get update && apt-get install -y build-essential \
sudo \
libboost-all-dev \
libprotobuf-dev \
protobuf-compiler \
cppcheck \
clang-3.6 \
ninja-build \
wget \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& apt-get autoremove -y
ADD setup.sh /setup.sh
RUN chmod +x /setup.sh
RUN cd /usr/local/src \
&& wget https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz \
&& tar xvf cmake-3.4.3.tar.gz \
&& cd cmake-3.4.3 \
&& ./bootstrap \
&& make \
&& make install \
&& cd .. \
&& rm -rf cmake*
CMD ["/bin/bash"]
ENTRYPOINT ["/setup.sh"]

View File

@@ -0,0 +1,36 @@
# Container for building and testing cmake-examples with default cmake v2.8.12.2
FROM ubuntu:14.04
MAINTAINER Thom Troy
RUN apt-get update && apt-get install -y build-essential \
sudo \
cmake \
libboost-all-dev \
libprotobuf-dev \
protobuf-compiler \
cppcheck \
clang-3.6 \
ninja-build \
wget \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# tini required to handle issue with building deb packages from cmake v2.8
RUN cd /usr/local/src \
&& wget https://github.com/krallin/tini/archive/v0.9.0.tar.gz \
&& tar xvf v0.9.0.tar.gz \
&& cd tini-0.9.0 \
&& cmake . \
&& make \
&& make install \
&& cd /usr/local/src \
&& rm -rf tini-* \
&& rm -rf v0.9.0.tar.gz
ADD setup.sh /setup.sh
RUN chmod +x /setup.sh
CMD ["/bin/bash"]
ENTRYPOINT ["/usr/local/bin/tini", "--", "/setup.sh"]

View File

@@ -5,6 +5,11 @@
cmake --version cmake --version
cmake --help cmake --help
# Find the directory this test script is in and then run them from there
EXAMPLES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "running examples in $EXAMPLES_DIR"
cd $EXAMPLES_DIR
dirs=( ./01-basic/A-hello-cmake \ dirs=( ./01-basic/A-hello-cmake \
./01-basic/B-hello-headers \ ./01-basic/B-hello-headers \
@@ -70,3 +75,7 @@ do
fi fi
fi fi
done done
echo ""
echo ""
echo "All Tests Completed"