2014-01-21 20:21:56 -05:00
|
|
|
#!/usr/bin/env bash
|
2013-10-17 04:08:14 -04:00
|
|
|
set -e
|
2013-08-07 00:00:50 -04:00
|
|
|
|
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,
|
2013-08-16 18:30:50 -04:00
|
|
|
# with the suffix -dirty if the repository isn't clean.
|
2013-09-10 14:33:26 -04:00
|
|
|
# - The script is intented to be run inside the docker container specified
|
2013-08-09 20:38:48 -04:00
|
|
|
# in the Dockerfile at the root of the source. In other words:
|
|
|
|
# DO NOT CALL THIS SCRIPT DIRECTLY.
|
2013-12-02 02:59:45 -05:00
|
|
|
# - The right way to call this script is to invoke "make" from
|
2014-02-10 18:21:20 -05:00
|
|
|
# your checkout of the Docker repository.
|
2014-01-04 23:15:15 -05:00
|
|
|
# the Makefile will do a "docker build -t docker ." and then
|
2013-09-23 14:19:28 -04:00
|
|
|
# "docker run hack/make.sh" in the resulting container image.
|
|
|
|
#
|
2013-08-07 00:00:50 -04:00
|
|
|
|
2013-10-17 04:08:14 -04:00
|
|
|
set -o pipefail
|
2013-08-07 00:00:50 -04:00
|
|
|
|
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!
|
2014-01-25 01:01:12 -05:00
|
|
|
if [ "$(pwd)" != '/go/src/github.com/dotcloud/docker' ] || [ -z "$DOCKER_CROSSPLATFORMS" ]; then
|
|
|
|
{
|
|
|
|
echo "# WARNING! I don't seem to be running in the Docker container."
|
|
|
|
echo "# The result of this command might be an incorrect build, and will not be"
|
|
|
|
echo "# officially supported."
|
|
|
|
echo "#"
|
|
|
|
echo "# Try this instead: make all"
|
|
|
|
echo "#"
|
|
|
|
} >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
2013-08-09 20:43:02 -04:00
|
|
|
|
2013-09-09 21:45:40 -04:00
|
|
|
# List of bundles to create when no argument is passed
|
|
|
|
DEFAULT_BUNDLES=(
|
|
|
|
binary
|
2013-10-17 23:33:34 -04:00
|
|
|
test
|
2013-12-08 20:41:50 -05:00
|
|
|
test-integration
|
2013-10-18 01:40:41 -04:00
|
|
|
dynbinary
|
|
|
|
dyntest
|
2013-12-08 20:41:50 -05:00
|
|
|
dyntest-integration
|
2013-12-08 22:20:55 -05:00
|
|
|
cover
|
2013-12-19 01:06:14 -05:00
|
|
|
cross
|
2013-11-17 22:25:08 -05:00
|
|
|
tgz
|
2013-09-09 21:45:40 -04:00
|
|
|
ubuntu
|
|
|
|
)
|
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
VERSION=$(cat ./VERSION)
|
2014-02-10 15:44:34 -05:00
|
|
|
if command -v git &> /dev/null && git rev-parse &> /dev/null; then
|
2013-11-21 17:11:17 -05:00
|
|
|
GITCOMMIT=$(git rev-parse --short HEAD)
|
2014-02-10 15:44:34 -05:00
|
|
|
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
2013-11-21 17:11:17 -05:00
|
|
|
GITCOMMIT="$GITCOMMIT-dirty"
|
|
|
|
fi
|
|
|
|
elif [ "$DOCKER_GITCOMMIT" ]; then
|
|
|
|
GITCOMMIT="$DOCKER_GITCOMMIT"
|
|
|
|
else
|
|
|
|
echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified'
|
|
|
|
echo >&2 ' Please either build with the .git directory accessible, or specify the'
|
|
|
|
echo >&2 ' exact (--short) commit hash you are building using DOCKER_GITCOMMIT for'
|
|
|
|
echo >&2 ' future accountability in diagnosing build issues. Thanks!'
|
|
|
|
exit 1
|
2013-08-14 21:01:13 -04:00
|
|
|
fi
|
2013-08-07 00:00:50 -04:00
|
|
|
|
2014-02-09 20:21:01 -05:00
|
|
|
if [ "$AUTO_GOPATH" ]; then
|
|
|
|
rm -rf .gopath
|
|
|
|
mkdir -p .gopath/src/github.com/dotcloud
|
|
|
|
ln -sf ../../../.. .gopath/src/github.com/dotcloud/docker
|
|
|
|
export GOPATH="$(pwd)/.gopath:$(pwd)/vendor"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! "$GOPATH" ]; then
|
|
|
|
echo >&2 'error: missing GOPATH; please see http://golang.org/doc/code.html#GOPATH'
|
|
|
|
echo >&2 ' alternatively, set AUTO_GOPATH=1'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-09-09 19:20:30 -04:00
|
|
|
# Use these flags when compiling the tests and final binary
|
2014-02-11 19:05:45 -05:00
|
|
|
LDFLAGS='-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'" -X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'" -w'
|
2014-02-11 20:23:17 -05:00
|
|
|
LDFLAGS_STATIC='-X github.com/dotcloud/docker/dockerversion.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"'
|
2013-12-18 13:25:08 -05:00
|
|
|
BUILDFLAGS='-tags netgo -a'
|
2013-09-09 19:20:30 -04:00
|
|
|
|
2013-12-08 22:20:55 -05:00
|
|
|
HAVE_GO_TEST_COVER=
|
2013-12-17 00:54:06 -05:00
|
|
|
if \
|
2013-12-30 20:58:25 -05:00
|
|
|
go help testflag | grep -- -cover > /dev/null \
|
2013-12-17 00:54:06 -05:00
|
|
|
&& go tool -n cover > /dev/null 2>&1 \
|
|
|
|
; then
|
2013-12-08 22:20:55 -05:00
|
|
|
HAVE_GO_TEST_COVER=1
|
|
|
|
fi
|
|
|
|
|
2013-12-08 15:49:57 -05:00
|
|
|
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
|
|
|
|
# You can use this to select certain tests to run, eg.
|
|
|
|
#
|
|
|
|
# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test
|
|
|
|
#
|
|
|
|
go_test_dir() {
|
|
|
|
dir=$1
|
2014-02-10 18:21:20 -05:00
|
|
|
coverpkg=$2
|
2013-12-08 22:20:55 -05:00
|
|
|
testcover=()
|
|
|
|
if [ "$HAVE_GO_TEST_COVER" ]; then
|
|
|
|
# if our current go install has -cover, we want to use it :)
|
|
|
|
mkdir -p "$DEST/coverprofiles"
|
|
|
|
coverprofile="docker${dir#.}"
|
|
|
|
coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
|
2014-02-10 18:21:20 -05:00
|
|
|
testcover=( -cover -coverprofile "$coverprofile" $coverpkg )
|
2013-12-08 22:20:55 -05:00
|
|
|
fi
|
2013-12-08 15:49:57 -05:00
|
|
|
(
|
|
|
|
set -x
|
|
|
|
cd "$dir"
|
2013-12-08 22:20:55 -05:00
|
|
|
go test ${testcover[@]} -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS
|
2013-12-08 15:49:57 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2014-02-10 18:21:20 -05:00
|
|
|
# This helper function walks the current directory looking for directories
|
|
|
|
# holding certain files ($1 parameter), and prints their paths on standard
|
|
|
|
# output, one per line.
|
|
|
|
find_dirs() {
|
|
|
|
find -not \( \
|
|
|
|
\( -wholename './vendor' -o -wholename './integration' -o -wholename './contrib' -o -wholename './pkg/mflag/example' \) \
|
|
|
|
-prune \
|
|
|
|
\) -name "$1" -print0 | xargs -0n1 dirname | sort -u
|
|
|
|
}
|
|
|
|
|
2013-09-09 21:45:40 -04:00
|
|
|
bundle() {
|
|
|
|
bundlescript=$1
|
|
|
|
bundle=$(basename $bundlescript)
|
2013-09-23 14:19:28 -04:00
|
|
|
echo "---> Making bundle: $bundle (in bundles/$VERSION/$bundle)"
|
2013-09-09 21:45:40 -04:00
|
|
|
mkdir -p bundles/$VERSION/$bundle
|
|
|
|
source $bundlescript $(pwd)/bundles/$VERSION/$bundle
|
2013-08-07 00:00:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2013-09-23 14:19:28 -04:00
|
|
|
# We want this to fail if the bundles already exist and cannot be removed.
|
2013-09-09 21:45:40 -04:00
|
|
|
# This is to avoid mixing bundles from different versions of the code.
|
|
|
|
mkdir -p bundles
|
|
|
|
if [ -e "bundles/$VERSION" ]; then
|
|
|
|
echo "bundles/$VERSION already exists. Removing."
|
|
|
|
rm -fr bundles/$VERSION && mkdir bundles/$VERSION || exit 1
|
2013-09-23 14:19:28 -04:00
|
|
|
echo
|
2013-09-09 21:45:40 -04:00
|
|
|
fi
|
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
if [ $# -lt 1 ]; then
|
2013-10-17 23:33:34 -04:00
|
|
|
bundles=(${DEFAULT_BUNDLES[@]})
|
2013-09-09 21:45:40 -04:00
|
|
|
else
|
|
|
|
bundles=($@)
|
|
|
|
fi
|
|
|
|
for bundle in ${bundles[@]}; do
|
|
|
|
bundle $SCRIPTDIR/make/$bundle
|
2013-09-23 14:19:28 -04:00
|
|
|
echo
|
2013-09-09 21:45:40 -04:00
|
|
|
done
|
2013-08-07 00:00:50 -04:00
|
|
|
}
|
|
|
|
|
2013-09-09 21:45:40 -04:00
|
|
|
main "$@"
|