2013-08-07 00:00:50 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
# This script builds various binary artifacts from a checkout of the docker
|
|
|
|
# source code.
|
2013-08-07 00:00:50 -04:00
|
|
|
#
|
|
|
|
# Requirements:
|
2013-08-09 20:38:48 -04:00
|
|
|
# - The current directory should be a checkout of the docker source code
|
|
|
|
# (http://github.com/dotcloud/docker). Whatever version is checked out
|
|
|
|
# will be built.
|
|
|
|
# - The VERSION file, at the root of the repository, should exist, and
|
|
|
|
# will be used as Docker binary version and package version.
|
|
|
|
# - The hash of the git commit will also be included in the Docker binary,
|
|
|
|
# with the suffix +CHANGES if the repository isn't clean.
|
|
|
|
# - The script is intented to be run as part of a docker build, as defined
|
|
|
|
# in the Dockerfile at the root of the source. In other words:
|
|
|
|
# DO NOT CALL THIS SCRIPT DIRECTLY.
|
|
|
|
# - The right way to call this script is to invoke "docker build ." from
|
|
|
|
# your checkout of the Docker repository.
|
2013-08-07 00:00:50 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
2013-08-09 20:43:02 -04:00
|
|
|
# We're a nice, sexy, little shell script, and people might try to run us;
|
|
|
|
# but really, they shouldn't. We want to be in a container!
|
|
|
|
RESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
|
|
|
|
grep -q "$RESOLVCONF" /proc/mounts || {
|
|
|
|
echo "# I will only run within a container."
|
|
|
|
echo "# Try this instead:"
|
|
|
|
echo "docker build ."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
VERSION=$(cat ./VERSION)
|
2013-08-07 00:00:50 -04:00
|
|
|
GIT_COMMIT=$(git rev-parse --short HEAD)
|
2013-08-09 20:38:48 -04:00
|
|
|
GIT_CHANGES=$(test -n "$(git status --porcelain)" && echo "+CHANGES" || true)
|
2013-08-07 00:00:50 -04:00
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
# Each "bundle" is a different type of build artefact: static binary, Ubuntu
|
|
|
|
# package, etc.
|
2013-08-07 00:00:50 -04:00
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
# Build Docker as a static binary file
|
2013-08-07 00:00:50 -04:00
|
|
|
bundle_binary() {
|
|
|
|
mkdir -p bundles/$VERSION/binary
|
2013-08-09 20:38:48 -04:00
|
|
|
go build -o bundles/$VERSION/binary/docker-$VERSION \
|
|
|
|
-ldflags "-X main.GITCOMMIT $GIT_COMMIT$GIT_CHANGES -X main.VERSION $VERSION -d -w" \
|
|
|
|
./docker
|
2013-08-07 00:00:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
# Build Docker's test suite as a collection of binary files (one per
|
|
|
|
# sub-package to test)
|
2013-08-07 00:00:50 -04:00
|
|
|
bundle_test() {
|
|
|
|
mkdir -p bundles/$VERSION/test
|
2013-08-09 20:38:48 -04:00
|
|
|
for test_dir in $(find_test_dirs); do
|
|
|
|
test_binary=$(
|
2013-08-07 00:00:50 -04:00
|
|
|
cd $test_dir
|
|
|
|
go test -c -v -ldflags "-X main.GITCOMMIT $GIT_COMMIT$GIT_CHANGES -X main.VERSION $VERSION -d -w" >&2
|
|
|
|
find . -maxdepth 1 -type f -name '*.test' -executable
|
2013-08-09 20:38:48 -04:00
|
|
|
)
|
2013-08-07 00:00:50 -04:00
|
|
|
cp $test_dir/$test_binary bundles/$VERSION/test/
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build docker as an ubuntu package using FPM and REPREPRO (sue me).
|
|
|
|
# bundle_binary must be called first.
|
|
|
|
bundle_ubuntu() {
|
|
|
|
mkdir -p bundles/$VERSION/ubuntu
|
|
|
|
|
|
|
|
DIR=$(mktemp -d)
|
|
|
|
|
|
|
|
# Generate an upstart config file (ubuntu-specific)
|
|
|
|
mkdir -p $DIR/etc/init
|
|
|
|
cat > $DIR/etc/init/docker.conf <<EOF
|
|
|
|
description "Run docker"
|
|
|
|
|
|
|
|
start on filesystem or runlevel [2345]
|
|
|
|
stop on runlevel [!2345]
|
|
|
|
|
|
|
|
respawn
|
|
|
|
|
|
|
|
exec docker -d
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Copy the binary
|
|
|
|
mkdir -p $DIR/usr/bin
|
|
|
|
cp bundles/$VERSION/binary/docker-$VERSION $DIR/usr/bin/docker
|
|
|
|
|
|
|
|
(
|
|
|
|
cd bundles/$VERSION/ubuntu
|
|
|
|
fpm -s dir -t deb -n lxc-docker -v $VERSION -a all --prefix / -C $DIR .
|
|
|
|
)
|
|
|
|
rm -fr $DIR
|
|
|
|
|
|
|
|
|
|
|
|
# Setup the APT repo
|
|
|
|
APTDIR=bundles/$VERSION/ubuntu/apt
|
|
|
|
mkdir -p $APTDIR/conf
|
|
|
|
cat > $APTDIR/conf/distributions <<EOF
|
|
|
|
Codename: docker
|
|
|
|
Components: main
|
|
|
|
Architectures: amd64
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Add the DEB package to the APT repo
|
|
|
|
DEBFILE=bundles/$VERSION/ubuntu/lxc-docker*.deb
|
|
|
|
reprepro -b $APTDIR includedeb docker $DEBFILE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
# This helper function walks the current directory looking for directories
|
|
|
|
# holding Go test files, and prints their paths on standard output, one per
|
|
|
|
# line.
|
2013-08-07 00:00:50 -04:00
|
|
|
find_test_dirs() {
|
2013-08-09 20:38:48 -04:00
|
|
|
find . -name '*_test.go' |
|
|
|
|
{ while read f; do dirname $f; done; } |
|
|
|
|
sort -u
|
2013-08-07 00:00:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
bundle_binary
|
|
|
|
bundle_ubuntu
|
|
|
|
#bundle_test
|
|
|
|
}
|
|
|
|
|
|
|
|
main
|