Skip to content
This repository was archived by the owner on May 3, 2018. It is now read-only.

Commit c29f735

Browse files
committed
Added isolated Docker builder and runner
Current build setup requires root and installation of a ton of packages from pip on the local machine. With this PR, this can be done in a single-command with a DinD config and isolated builder. Currently only supports Ubuntu 16.04 but can be easily extended to others.
1 parent 9dd5214 commit c29f735

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed

contrib/flocker-builder/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

contrib/flocker-builder/Dockerfile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM ubuntu:16.04
2+
3+
MAINTAINER Srdjan Grubor <[email protected]>
4+
5+
# You can't have aufs on aufs so this is mandatory to have bind-mounted
6+
# on some systems
7+
# VOLUME /var/lib/docker
8+
9+
# Add Docker repo key
10+
# XXX: Done early to reuse cache as much as possible
11+
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
12+
13+
RUN apt-get update && \
14+
apt-get -y dist-upgrade && \
15+
apt-get install -y apt-transport-https
16+
17+
RUN echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" > /etc/apt/sources.list.d/docker.list
18+
19+
RUN apt-get update && \
20+
apt-get install -y docker-engine \
21+
libffi-dev \
22+
libssl-dev \
23+
lsb-release \
24+
python \
25+
python-pip \
26+
sudo \
27+
virtualenv && \
28+
apt-get clean
29+
30+
# Get tini to handle reaping and signal processing
31+
ENV TINI_VERSION v0.14.0
32+
33+
ADD https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini /usr/local/bin/tini
34+
ADD https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini.asc /usr/local/bin/tini.asc
35+
36+
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 6380DC428747F6C393FEACA59A84159D7001A4E5 && \
37+
gpg --verify /usr/local/bin/tini.asc && \
38+
rm -r /usr/local/bin/tini.asc
39+
40+
RUN chmod +x /usr/local/bin/tini
41+
42+
# We want a limited user even though we technically are using a privileged container
43+
RUN groupadd -r -g 910 builder
44+
RUN useradd -m -r -u 910 -g 910 builder
45+
46+
# Builder needs to be in docker group to avoid requirements for sudo
47+
RUN usermod -a -G docker builder
48+
49+
RUN mkdir -p /opt/flocker && \
50+
chown builder:builder /opt/flocker
51+
52+
# Added last to avoid cache busting
53+
COPY build_flocker.sh build.sh dind_wrapper.sh \
54+
/usr/local/bin/
55+
56+
RUN chmod +x /usr/local/bin/build_flocker.sh \
57+
/usr/local/bin/build.sh \
58+
/usr/local/bin/dind_wrapper.sh
59+
60+
ENTRYPOINT ["/usr/local/bin/tini", "-g", "--"]
61+
CMD ["/usr/local/bin/build.sh"]

contrib/flocker-builder/build.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash -e
2+
3+
OUTPUT_DIR=/opt/flocker/output
4+
FLOCKER_SRC_DIR=/opt/flocker/flocker
5+
6+
echo "Starting DinD..."
7+
/usr/local/bin/dind_wrapper.sh &
8+
9+
echo "Invoking build script..."
10+
sudo -i -u builder /usr/local/bin/build_flocker.sh
11+
12+
echo "Exporting the packages..."
13+
if [ ! -d "${OUTPUT_DIR}" ]; then
14+
mkdir -p "${OUTPUT_DIR}"
15+
fi
16+
17+
mv ${FLOCKER_SRC_DIR}/clusterhq-*.deb "${OUTPUT_DIR}"
18+
chmod 666 ${OUTPUT_DIR}/clusterhq-*.deb
19+
20+
echo
21+
echo "Output files:"
22+
ls "${OUTPUT_DIR}"
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash -e
2+
3+
echo "Building as UID/EUID $UID/$EUID"
4+
5+
BUILD_DIR=/opt/flocker
6+
FLOCKER_SRC_DIR=${BUILD_DIR}/flocker
7+
8+
pushd "${BUILD_DIR}" >/dev/null
9+
echo "Cloning..."
10+
git clone https://github.com/scatterhq/flocker
11+
12+
# XXX: netifaces throws an error if it's not installed but adding it to
13+
# admin.txt throws an error in Docker build due to duplication
14+
echo "Installing prerequisites"
15+
pushd "${FLOCKER_SRC_DIR}" >/dev/null
16+
# XXX: Not strictly needed but can help if used locally to build
17+
virtualenv venv
18+
. venv/bin/activate
19+
20+
pip install --requirement requirements/admin.txt && \
21+
pip install netifaces
22+
23+
release_id=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
24+
release_name=$(lsb_release -rs)
25+
26+
echo "Starting Flocker build in ${FLOCKER_SRC_DIR}..."
27+
./admin/build-package --distribution=${release_id}-${release_name} $(pwd)
28+
echo "Finished Flocker build!"
29+
popd >/dev/null
30+
popd >/dev/null
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash -e
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2014 Dan Tehranian
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
# Original from:
26+
# https://github.com/tehranian/dind-jenkins-slave/commit/bdaea009f2ec982f07c89408906a64ce24ab7637
27+
28+
# First, make sure that cgroups are mounted correctly.
29+
CGROUP=/sys/fs/cgroup
30+
: {LOG:=stdio}
31+
32+
[ -d $CGROUP ] ||
33+
mkdir $CGROUP
34+
35+
mountpoint -q $CGROUP ||
36+
mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
37+
echo "Could not make a tmpfs mount. Did you use --privileged?"
38+
exit 1
39+
}
40+
41+
if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security
42+
then
43+
mount -t securityfs none /sys/kernel/security || {
44+
echo "Could not mount /sys/kernel/security."
45+
echo "AppArmor detection and --privileged mode might break."
46+
}
47+
fi
48+
49+
# Mount the cgroup hierarchies exactly as they are in the parent system.
50+
for SUBSYS in $(cut -d: -f2 /proc/1/cgroup)
51+
do
52+
[ -d $CGROUP/$SUBSYS ] || mkdir $CGROUP/$SUBSYS
53+
mountpoint -q $CGROUP/$SUBSYS ||
54+
mount -n -t cgroup -o $SUBSYS cgroup $CGROUP/$SUBSYS
55+
56+
# The two following sections address a bug which manifests itself
57+
# by a cryptic "lxc-start: no ns_cgroup option specified" when
58+
# trying to start containers withina container.
59+
# The bug seems to appear when the cgroup hierarchies are not
60+
# mounted on the exact same directories in the host, and in the
61+
# container.
62+
63+
# Named, control-less cgroups are mounted with "-o name=foo"
64+
# (and appear as such under /proc/<pid>/cgroup) but are usually
65+
# mounted on a directory named "foo" (without the "name=" prefix).
66+
# Systemd and OpenRC (and possibly others) both create such a
67+
# cgroup. To avoid the aforementioned bug, we symlink "foo" to
68+
# "name=foo". This shouldn't have any adverse effect.
69+
echo $SUBSYS | grep -q ^name= && {
70+
NAME=$(echo $SUBSYS | sed s/^name=//)
71+
ln -s $SUBSYS $CGROUP/$NAME || true
72+
}
73+
74+
# Likewise, on at least one system, it has been reported that
75+
# systemd would mount the CPU and CPU accounting controllers
76+
# (respectively "cpu" and "cpuacct") with "-o cpuacct,cpu"
77+
# but on a directory called "cpu,cpuacct" (note the inversion
78+
# in the order of the groups). This tries to work around it.
79+
[ $SUBSYS = cpuacct,cpu ] && ln -s $SUBSYS $CGROUP/cpu,cpuacct
80+
done
81+
82+
# Note: as I write those lines, the LXC userland tools cannot setup
83+
# a "sub-container" properly if the "devices" cgroup is not in its
84+
# own hierarchy. Let's detect this and issue a warning.
85+
grep -q :devices: /proc/1/cgroup ||
86+
echo "WARNING: the 'devices' cgroup should be in its own hierarchy."
87+
grep -qw devices /proc/1/cgroup ||
88+
echo "WARNING: it looks like the 'devices' cgroup is not mounted."
89+
90+
# Now, close extraneous file descriptors.
91+
pushd /proc/self/fd >/dev/null
92+
for FD in *
93+
do
94+
case "$FD" in
95+
# Keep stdin/stdout/stderr
96+
[012])
97+
;;
98+
# Nuke everything else
99+
*)
100+
eval exec "$FD>&-"
101+
;;
102+
esac
103+
done
104+
popd >/dev/null
105+
106+
107+
# If a pidfile is still around (for example after a container restart),
108+
# delete it so that docker can start.
109+
rm -rf /var/run/docker.pid
110+
111+
# Force overlayfs for DinD or it won't work on Debian image (like this one)
112+
# XXX: Disabled for now since this will be run on local machines w/ overlay
113+
# as the default FS so we leave the default in
114+
# DOCKER_DAEMON_ARGS="$DOCKER_DAEMON_ARGS -s overlay"
115+
116+
exec dockerd $DOCKER_DAEMON_ARGS >/var/log/docker.log

contrib/flocker-builder/run.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash -e
2+
3+
CURRENT_DIR=$(readlink -f $(dirname $0))
4+
OUTPUT_DIR="${CURRENT_DIR}/dist"
5+
6+
if [ ! -d "${OUTPUT_DIR}" ]; then
7+
mkdir -p "${OUTPUT_DIR}"
8+
fi
9+
10+
pushd "${CURRENT_DIR}" >/dev/null
11+
docker build --tag flocker_builder .
12+
docker run -v ${OUTPUT_DIR}:/opt/flocker/output --rm --privileged flocker_builder
13+
popd >/dev/null
14+
15+
echo "Built files are in ${OUTPUT_DIR}"

0 commit comments

Comments
 (0)