Merge pull request #387 from dpw/build_in_container
Containerized weave build
This commit is contained in:
commit
d9cdfff35d
6 files changed
+170
-24
No files matched your search
@@ -31,4 +31,8 @@ _testmain.go
|
|||||||
weaver/weaver
|
weaver/weaver
|
||||||
weavedns/weavedns
|
weavedns/weavedns
|
||||||
tools/bin
|
tools/bin
|
||||||
|
tools/build
|
||||||
releases
|
releases
|
||||||
|
weave.tar
|
||||||
|
weavedns.tar
|
||||||
|
weavetools.tar
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
PUBLISH=publish_weave publish_weavedns publish_weavetools
|
PUBLISH=publish_weave publish_weavedns publish_weavetools
|
||||||
|
|
||||||
.DEFAULT: all
|
.DEFAULT: all
|
||||||
.PHONY: all update tests publish $(PUBLISH) clean
|
.PHONY: all update tests publish $(PUBLISH) clean prerequisites build
|
||||||
|
|
||||||
# If you can use docker without being root, you can do "make SUDO="
|
# If you can use docker without being root, you can do "make SUDO="
|
||||||
SUDO=sudo
|
SUDO=sudo
|
||||||
@@ -14,9 +14,9 @@ WEAVETOOLS_EXES=tools/bin
|
|||||||
WEAVER_IMAGE=$(DOCKERHUB_USER)/weave
|
WEAVER_IMAGE=$(DOCKERHUB_USER)/weave
|
||||||
WEAVEDNS_IMAGE=$(DOCKERHUB_USER)/weavedns
|
WEAVEDNS_IMAGE=$(DOCKERHUB_USER)/weavedns
|
||||||
WEAVETOOLS_IMAGE=$(DOCKERHUB_USER)/weavetools
|
WEAVETOOLS_IMAGE=$(DOCKERHUB_USER)/weavetools
|
||||||
WEAVER_EXPORT=/var/tmp/weave.tar
|
WEAVER_EXPORT=weave.tar
|
||||||
WEAVEDNS_EXPORT=/var/tmp/weavedns.tar
|
WEAVEDNS_EXPORT=weavedns.tar
|
||||||
WEAVETOOLS_EXPORT=/var/tmp/weavetools.tar
|
WEAVETOOLS_EXPORT=weavetools.tar
|
||||||
|
|
||||||
all: $(WEAVER_EXPORT) $(WEAVEDNS_EXPORT) $(WEAVETOOLS_EXPORT)
|
all: $(WEAVER_EXPORT) $(WEAVEDNS_EXPORT) $(WEAVETOOLS_EXPORT)
|
||||||
|
|
||||||
@@ -38,8 +38,17 @@ $(WEAVER_EXE) $(WEAVEDNS_EXE): common/*.go
|
|||||||
$(WEAVER_EXE): router/*.go weaver/main.go
|
$(WEAVER_EXE): router/*.go weaver/main.go
|
||||||
$(WEAVEDNS_EXE): nameserver/*.go weavedns/main.go
|
$(WEAVEDNS_EXE): nameserver/*.go weavedns/main.go
|
||||||
|
|
||||||
|
build_weavetools_exes_in_container=yes
|
||||||
|
|
||||||
$(WEAVETOOLS_EXES): tools/build.sh
|
$(WEAVETOOLS_EXES): tools/build.sh
|
||||||
|
ifdef build_weavetools_exes_in_container
|
||||||
$(SUDO) docker run --rm -v $(realpath $(<D)):/home/weave ubuntu sh /home/weave/build.sh
|
$(SUDO) docker run --rm -v $(realpath $(<D)):/home/weave ubuntu sh /home/weave/build.sh
|
||||||
|
else
|
||||||
|
rm -rf tools/build
|
||||||
|
mkdir tools/build
|
||||||
|
cd tools/build && sh ../../$<
|
||||||
|
rm -rf tools/build
|
||||||
|
endif
|
||||||
|
|
||||||
$(WEAVER_EXPORT): weaver/Dockerfile $(WEAVER_EXE)
|
$(WEAVER_EXPORT): weaver/Dockerfile $(WEAVER_EXE)
|
||||||
$(SUDO) docker build -t $(WEAVER_IMAGE) weaver
|
$(SUDO) docker build -t $(WEAVER_IMAGE) weaver
|
||||||
@@ -69,3 +78,8 @@ clean:
|
|||||||
-$(SUDO) docker rmi $(WEAVER_IMAGE) $(WEAVEDNS_IMAGE) $(WEAVETOOLS_IMAGE)
|
-$(SUDO) docker rmi $(WEAVER_IMAGE) $(WEAVEDNS_IMAGE) $(WEAVETOOLS_IMAGE)
|
||||||
rm -f $(WEAVER_EXE) $(WEAVEDNS_EXE) $(WEAVER_EXPORT) $(WEAVEDNS_EXPORT) $(WEAVETOOLS_EXPORT)
|
rm -f $(WEAVER_EXE) $(WEAVEDNS_EXE) $(WEAVER_EXPORT) $(WEAVEDNS_EXPORT) $(WEAVETOOLS_EXPORT)
|
||||||
$(SUDO) rm -rf $(WEAVETOOLS_EXES)
|
$(SUDO) rm -rf $(WEAVETOOLS_EXES)
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(SUDO) go clean -i net
|
||||||
|
$(SUDO) go install -tags netgo std
|
||||||
|
$(MAKE) build_weavetools_exes_in_container=
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM ubuntu
|
||||||
|
|
||||||
|
# When doing a build in a container, "apt-get update" happens twice,
|
||||||
|
# which can be a very significant overhead for incremental builds.
|
||||||
|
# And it's unnecessary, because if any of the prerequisites do change,
|
||||||
|
# the right thing to do is to rebuild the container image. Rather
|
||||||
|
# than suppressing the "apt-get update" commands explicitly, we clear
|
||||||
|
# out sources.list so that 'apt-get update' doesn't do anything.
|
||||||
|
|
||||||
|
RUN sh -c 'apt-get -y update && apt-get -y install --no-install-recommends build-essential git ca-certificates golang docker.io mercurial libpcap-dev curl make pkg-config gcc bison flex && echo >/etc/apt/sources.list'
|
||||||
|
COPY build.sh /
|
||||||
|
ENTRYPOINT ["sh", "/build.sh"]
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
GOPATH=/home/go
|
||||||
|
export GOPATH
|
||||||
|
|
||||||
|
WEAVE_SRC=$GOPATH/src/github.com/zettio/weave
|
||||||
|
|
||||||
|
if [ $# -eq 0 ] ; then
|
||||||
|
# No arguments. Expect that the weave repo will be bind-mounted
|
||||||
|
# into $GOPATH
|
||||||
|
if ! [ -e $WEAVE_SRC ] ; then
|
||||||
|
cat 2>&1 <<EOF
|
||||||
|
No container arguments supplied, and nothing at ${WEAVE_SRC}. Please
|
||||||
|
either bind-mount the golang workspace containing weave with the
|
||||||
|
docker run -v option, e.g.:
|
||||||
|
|
||||||
|
$ docker run -v <host gopath>:${GOPATH} \\
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock zettio/weave-build
|
||||||
|
|
||||||
|
Or supply git clone arguments to retrieve it, e.g.:
|
||||||
|
|
||||||
|
$ docker run -v /var/run/docker.sock:/var/run/docker.sock \\
|
||||||
|
zettio/weave-build https://github.com/zettio/weave.git
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If we run make directly, any files created on the bind mount
|
||||||
|
# will have awkward ownership. So we switch to a user with the
|
||||||
|
# same user and group IDs as source directory. We have to set a
|
||||||
|
# few things up so that sudo works without complaining later on.
|
||||||
|
uid=$(stat --format="%u" $WEAVE_SRC)
|
||||||
|
gid=$(stat --format="%g" $WEAVE_SRC)
|
||||||
|
echo "weave:x:$uid:$gid::$WEAVE_SRC:/bin/sh" >>/etc/passwd
|
||||||
|
echo "weave:*:::::::" >>/etc/shadow
|
||||||
|
echo "weave ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
|
||||||
|
su weave -c "make -C $WEAVE_SRC build"
|
||||||
|
else
|
||||||
|
# There are arguments to pass to git-clone
|
||||||
|
mkdir -p ${WEAVE_SRC%/*}
|
||||||
|
git clone "$@" $WEAVE_SRC
|
||||||
|
make -C $WEAVE_SRC build
|
||||||
|
fi
|
||||||
+86
-16
@@ -3,35 +3,105 @@ title: Building Weave
|
|||||||
layout: default
|
layout: default
|
||||||
---
|
---
|
||||||
|
|
||||||
**NB** This is only necessary if you want to work on the weave code.
|
You only need to build weave if you want to work on the weave codebase
|
||||||
|
(or you just enjoy building software).
|
||||||
|
|
||||||
## Building directly on Linux
|
Apart from the `weave` shell script, weave is delivered as a set of
|
||||||
|
container images. There is no distribution-specific packaging, so in
|
||||||
|
principle it shouldn't matter which Linux distribution you build
|
||||||
|
under. But naturally, Docker is a prerequisite (version 1.3.0 or
|
||||||
|
later). And it is difficult to build under Fedora because [Fedora
|
||||||
|
does not include static
|
||||||
|
libraries](http://fedoraproject.org/wiki/Packaging:Guidelines#Packaging_Static_Libraries).
|
||||||
|
So we recommend building under Ubuntu.
|
||||||
|
|
||||||
You can work on weave without using a VM if you are running the docker
|
You can also build in a container under any system that supports
|
||||||
daemon outside a VM. (These instructions have only been tested on
|
Docker. And you can run Ubuntu in a VM and build there. These
|
||||||
Ubuntu.)
|
options are described below.
|
||||||
|
|
||||||
To build weave you need `libpcap-dev` and `docker` (version 1.3.0 or
|
## Building directly on Ubuntu
|
||||||
later) installed. And `go` (and `git` and `hg` to fetch dependencies).
|
|
||||||
|
|
||||||
The package name is `github.com/zettio/weave`, so assuming `$GOPATH`
|
The weave git repository should be cloned into
|
||||||
is set:
|
`$GOPATH/src/github.com/zettio/weave`, in accordance with [the go
|
||||||
|
workspace conventions](https://golang.org/doc/code.html#Workspaces):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cd $GOPATH
|
|
||||||
$ WEAVE=github.com/zettio/weave
|
$ WEAVE=github.com/zettio/weave
|
||||||
$ git clone https://$WEAVE src/$WEAVE
|
$ git clone https://$WEAVE $GOPATH/src/$WEAVE
|
||||||
$ cd src/$WEAVE
|
$ cd $GOPATH/src/$WEAVE
|
||||||
```
|
```
|
||||||
|
|
||||||
Then simply run
|
Some prerequisites are needed to build weave. First, install Docker
|
||||||
|
if you haven't already, by following the instructions [on the Docker
|
||||||
|
site](https://docs.docker.com/installation/ubuntulinux/). Note that
|
||||||
|
we recommend using the Docker-maintained `lxc-docker` package, rather
|
||||||
|
than the `docker.io` package which contains a very old version. Then
|
||||||
|
install the other prerequisites for building with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo apt-get install build-essential git golang mercurial libpcap-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Then to actually build, simply do:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ make
|
$ make
|
||||||
```
|
```
|
||||||
|
|
||||||
This will build the weave router, produce a docker image
|
This will build the weave components and package them into three
|
||||||
`zettio/weave` and export that image to `/var/tmp/weave.tar`.
|
Docker images (`zettio/weave`, `zettio/weavedns`, and
|
||||||
|
`zettio/weavetools`). These are then exported (as
|
||||||
|
`weave.tar`, `weavends.tar` and `weavetools.tar`).
|
||||||
|
|
||||||
|
## Building in a Docker container
|
||||||
|
|
||||||
|
As a preliminary step, we create a container image based on Ubuntu
|
||||||
|
that has all the prerequisites. This avoids the need to download and
|
||||||
|
install them for each build. In the `weave` directory, do:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo docker build -t zettio/weave-build build
|
||||||
|
```
|
||||||
|
|
||||||
|
Next we run a container based on that image. That container requires
|
||||||
|
access to the Docker daemon on the host, via
|
||||||
|
`/var/run/docker.sock`. If you are building under a Fedora or RHEL
|
||||||
|
Docker host (or another distribution that uses SELinux), and you have
|
||||||
|
SELinux set to enforcing mode, it will block attempts to access
|
||||||
|
`/var/run/docker.sock` inside the container. See
|
||||||
|
[dpw/selinux-dockersock](https://github.com/dpw/selinux-dockersock)
|
||||||
|
for a way to work around this problem.
|
||||||
|
|
||||||
|
To perform a build, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo docker run -v /var/run/docker.sock:/var/run/docker.sock zettio/weave-build https://github.com/zettio/weave.git
|
||||||
|
```
|
||||||
|
|
||||||
|
This will clone the weave git repository, then do the build.
|
||||||
|
|
||||||
|
When the build completes, the resulting images are stored in docker on
|
||||||
|
the host, as when building directly under Ubuntu.
|
||||||
|
|
||||||
|
The container arguments are passed to `git clone`, so for example, you
|
||||||
|
can build from a forked repository and a specific branch with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo docker run -v /var/run/docker.sock:/var/run/docker.sock zettio/weave-build -b <branch name> <repo URI>
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, you might want to build from a weave source tree
|
||||||
|
already present on the host. You can do this by using the `-v` option
|
||||||
|
to bind the bind your go workspace containing the weave repository to
|
||||||
|
`/home/go` inside the container. No container arguments should be
|
||||||
|
passed in this case:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo docker run -v /var/run/docker.sock:/var/run/docker.sock -v <host gopath>:/home/go zettio/weave-build
|
||||||
|
```
|
||||||
|
|
||||||
|
This will leave the intermediate build artifacts on the host, so that
|
||||||
|
you can modify the weave source code and rebuild quickly.
|
||||||
|
|
||||||
## Building using Vagrant
|
## Building using Vagrant
|
||||||
|
|
||||||
@@ -82,7 +152,7 @@ The docker daemon is also running in this VM, so you can then do
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
vm$ sudo ./weave launch
|
vm$ sudo ./weave launch
|
||||||
vm$ docker ps
|
vm$ sudo docker ps
|
||||||
```
|
```
|
||||||
|
|
||||||
and so on.
|
and so on.
|
||||||
|
|||||||
+6
-4
@@ -1,8 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
|
||||||
|
|
||||||
apt-get -y update
|
# Show the progress of this script, in case it fails.
|
||||||
apt-get -y install curl make pkg-config gcc bison flex
|
set -x -e
|
||||||
|
|
||||||
|
sudo apt-get -y update
|
||||||
|
sudo apt-get -y install curl make pkg-config gcc bison flex
|
||||||
|
|
||||||
BASEDIR=$(dirname $0)
|
BASEDIR=$(dirname $0)
|
||||||
mkdir -p "$BASEDIR"/bin
|
mkdir -p "$BASEDIR"/bin
|
||||||
@@ -38,7 +40,7 @@ fetch() {
|
|||||||
|
|
||||||
for PACKAGE in $PACKAGES; do
|
for PACKAGE in $PACKAGES; do
|
||||||
fetch $PACKAGE
|
fetch $PACKAGE
|
||||||
(cd $PACKAGE; ./configure --disable-shared && make install)
|
(cd $PACKAGE; ./configure --disable-shared && make && sudo make install)
|
||||||
done
|
done
|
||||||
|
|
||||||
fetch $CONNTRACK
|
fetch $CONNTRACK
|
||||||
|
|||||||
Reference in new issue
Block a user