Skip to content

Commit 4e0dbb6

Browse files
committed
added docker files to allow testing with different cmake versions for #8
1 parent 1208416 commit 4e0dbb6

File tree

7 files changed

+203
-0
lines changed

7 files changed

+203
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
ROOT_DIR=`pwd`
4+
dir="01-basic/I-compiling-with-clang"
5+
6+
if [ -d "$ROOT_DIR/$dir/build.clang" ]; then
7+
echo "deleting $dir/build.clang"
8+
rm -r $dir/build.clang
9+
fi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
ROOT_DIR=`pwd`
4+
dir="01-basic/J-building-with-ninja"
5+
6+
if [ -d "$ROOT_DIR/$dir/build.ninja" ]; then
7+
echo "deleting $dir/build.ninja"
8+
rm -r $dir/build.ninja
9+
fi

dockerfiles/README.adoc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
= CMake Examples with Docker
3+
:toc:
4+
:toc-placement!:
5+
6+
toc::[]
7+
8+
# Docker
9+
10+
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.
11+
12+
# Building
13+
14+
To build a container from the this directory run the following:
15+
16+
[source,bash]
17+
----
18+
$ docker build --rm -f <dockerfile> -t <container tag> .
19+
----
20+
21+
For example:
22+
23+
[source,bash]
24+
----
25+
$ docker build --rm -f ubuntu14.04-cmake-3.4.3 t matrim/cmake-examples:3.4.3 .
26+
----
27+
28+
In this example the tag is created as follows
29+
30+
<docker user>/<repository>:<cmake version>
31+
32+
This will tag the container as belong to my repositry with the label of the container being the version of cmake installed.
33+
34+
## Pre-build Images
35+
36+
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].
37+
38+
The images available include the following versions of cmake:
39+
40+
* Ubuntu 14.04 with CMake 2.8.12.2
41+
42+
$ docker pull docker pull matrim/cmake-examples:2.8.12.2
43+
44+
* Ubuntu 14.04 with CMake 3.4.3
45+
46+
$ docker pull docker pull matrim/cmake-examples:3.4.3
47+
48+
# Running
49+
50+
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.
51+
52+
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`
53+
54+
For example
55+
56+
[source,bash]
57+
----
58+
docker run -e DEV_UID=`id -u` -e DEV_GID=`id -u` -it matrim/cmake-examples:3.4.3
59+
----
60+
61+
62+
To build the full set of cmake-examples test cases you can run:
63+
64+
[source,bash]
65+
----
66+
docker run -it matrim/cmake-examples:3.4.3
67+
git clone https://github.com/ttroy50/cmake-examples.git
68+
cd cmake-examples
69+
./test.sh
70+
----
71+
72+
73+
If you already have a checkout of the cmake-examples you can load the directory as a docker volume.
74+
75+
Below is an example of loading a volume and automatically running all cmake-example test cases:
76+
77+
[source,bash]
78+
----
79+
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
80+
----

dockerfiles/setup.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Setup script for the cmake-examples repository
3+
# Will create a non root user using the UID and GID passed in from environment
4+
# variables and give them sudo access
5+
#
6+
ret=false
7+
output=`getent passwd devuser 2&>1`
8+
result=$?
9+
if [ $result -ne 0 ] ; then
10+
echo "Creating devuser"
11+
if [ -z $DEV_UID ]; then
12+
DEV_UID=1000
13+
fi
14+
15+
if [ -z $DEV_GID ]; then
16+
DEV_GID=1000
17+
fi
18+
19+
groupadd -g $DEV_GID devgroup
20+
useradd -c 'container user' -u $DEV_UID -g $DEV_GID -d /home/devuser -m devuser
21+
echo "devuser:todo_$DEV_UID_$DEV_GID" | chpasswd
22+
sudo adduser devuser sudo
23+
echo "%sudo ALL=NOPASSWD: ALL" >> /etc/sudoers
24+
fi
25+
26+
exec /bin/su - devuser -c "$@"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Container for building and testing cmake-examples with cmake v3.4.3
2+
FROM ubuntu:14.04
3+
MAINTAINER Thom Troy
4+
5+
RUN apt-get update && apt-get install -y build-essential \
6+
sudo \
7+
libboost-all-dev \
8+
libprotobuf-dev \
9+
protobuf-compiler \
10+
cppcheck \
11+
clang-3.6 \
12+
ninja-build \
13+
wget \
14+
git \
15+
&& apt-get clean \
16+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
17+
&& apt-get autoremove -y
18+
19+
ADD setup.sh /setup.sh
20+
RUN chmod +x /setup.sh
21+
22+
RUN cd /usr/local/src \
23+
&& wget https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz \
24+
&& tar xvf cmake-3.4.3.tar.gz \
25+
&& cd cmake-3.4.3 \
26+
&& ./bootstrap \
27+
&& make \
28+
&& make install \
29+
&& cd .. \
30+
&& rm -rf cmake*
31+
32+
CMD ["/bin/bash"]
33+
34+
ENTRYPOINT ["/setup.sh"]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Container for building and testing cmake-examples with default cmake v2.8.12.2
2+
FROM ubuntu:14.04
3+
MAINTAINER Thom Troy
4+
5+
RUN apt-get update && apt-get install -y build-essential \
6+
sudo \
7+
cmake \
8+
libboost-all-dev \
9+
libprotobuf-dev \
10+
protobuf-compiler \
11+
cppcheck \
12+
clang-3.6 \
13+
ninja-build \
14+
wget \
15+
git \
16+
&& apt-get clean \
17+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
18+
19+
# tini required to handle issue with building deb packages from cmake v2.8
20+
RUN cd /usr/local/src \
21+
&& wget https://github.com/krallin/tini/archive/v0.9.0.tar.gz \
22+
&& tar xvf v0.9.0.tar.gz \
23+
&& cd tini-0.9.0 \
24+
&& cmake . \
25+
&& make \
26+
&& make install \
27+
&& cd /usr/local/src \
28+
&& rm -rf tini-* \
29+
&& rm -rf v0.9.0.tar.gz
30+
31+
32+
ADD setup.sh /setup.sh
33+
RUN chmod +x /setup.sh
34+
35+
CMD ["/bin/bash"]
36+
ENTRYPOINT ["/usr/local/bin/tini", "--", "/setup.sh"]

test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
cmake --version
66
cmake --help
77

8+
# Find the directory this test script is in and then run them from there
9+
EXAMPLES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
10+
echo "running examples in $EXAMPLES_DIR"
11+
12+
cd $EXAMPLES_DIR
813

914
dirs=( ./01-basic/A-hello-cmake \
1015
./01-basic/B-hello-headers \
@@ -70,3 +75,7 @@ do
7075
fi
7176
fi
7277
done
78+
79+
echo ""
80+
echo ""
81+
echo "All Tests Completed"

0 commit comments

Comments
 (0)