2014-01-22 01:21:56 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-10-17 08:08:14 +00:00
|
|
|
set -e
|
2013-08-07 04:00:50 +00:00
|
|
|
|
2013-08-10 00:38:48 +00:00
|
|
|
# This script builds various binary artifacts from a checkout of the docker
|
|
|
|
# source code.
|
2013-08-07 04:00:50 +00:00
|
|
|
#
|
|
|
|
# Requirements:
|
2013-08-10 00:38:48 +00:00
|
|
|
# - The current directory should be a checkout of the docker source code
|
2014-07-24 22:19:50 +00:00
|
|
|
# (http://github.com/docker/docker). Whatever version is checked out
|
2013-08-10 00:38:48 +00:00
|
|
|
# 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 22:30:50 +00:00
|
|
|
# with the suffix -dirty if the repository isn't clean.
|
2013-09-10 18:33:26 +00:00
|
|
|
# - The script is intented to be run inside the docker container specified
|
2013-08-10 00:38:48 +00:00
|
|
|
# in the Dockerfile at the root of the source. In other words:
|
|
|
|
# DO NOT CALL THIS SCRIPT DIRECTLY.
|
2013-12-02 07:59:45 +00:00
|
|
|
# - The right way to call this script is to invoke "make" from
|
2014-02-10 23:21:20 +00:00
|
|
|
# your checkout of the Docker repository.
|
2014-01-05 04:15:15 +00:00
|
|
|
# the Makefile will do a "docker build -t docker ." and then
|
2014-05-08 13:11:17 +00:00
|
|
|
# "docker run hack/make.sh" in the resulting image.
|
2013-09-23 18:19:28 +00:00
|
|
|
#
|
2013-08-07 04:00:50 +00:00
|
|
|
|
2013-10-17 08:08:14 +00:00
|
|
|
set -o pipefail
|
2013-08-07 04:00:50 +00:00
|
|
|
|
2014-07-30 23:02:04 +00:00
|
|
|
export DOCKER_PKG='github.com/docker/docker'
|
|
|
|
|
2013-08-10 00:43:02 +00: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-07-30 23:02:04 +00:00
|
|
|
if [ "$(pwd)" != "/go/src/$DOCKER_PKG" ] || [ -z "$DOCKER_CROSSPLATFORMS" ]; then
|
2014-01-25 06:01:12 +00:00
|
|
|
{
|
|
|
|
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-10 00:43:02 +00:00
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
# List of bundles to create when no argument is passed
|
|
|
|
DEFAULT_BUNDLES=(
|
2014-04-04 06:37:50 +00:00
|
|
|
validate-dco
|
|
|
|
validate-gofmt
|
2015-01-30 19:45:02 +00:00
|
|
|
validate-toml
|
2014-07-03 18:29:07 +00:00
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
binary
|
2014-07-03 18:29:07 +00:00
|
|
|
|
2014-04-29 22:49:03 +00:00
|
|
|
test-unit
|
2014-03-31 17:55:55 +00:00
|
|
|
test-integration-cli
|
2014-12-19 07:20:59 +00:00
|
|
|
test-docker-py
|
2014-07-03 18:29:07 +00:00
|
|
|
|
2013-10-18 05:40:41 +00:00
|
|
|
dynbinary
|
2015-01-17 05:00:44 +00:00
|
|
|
test-integration
|
2014-07-03 18:29:07 +00:00
|
|
|
|
2013-12-09 03:20:55 +00:00
|
|
|
cover
|
2013-12-19 06:06:14 +00:00
|
|
|
cross
|
2013-11-18 03:25:08 +00:00
|
|
|
tgz
|
2013-09-10 01:45:40 +00:00
|
|
|
ubuntu
|
|
|
|
)
|
|
|
|
|
2013-08-10 00:38:48 +00:00
|
|
|
VERSION=$(cat ./VERSION)
|
2014-02-10 20:44:34 +00:00
|
|
|
if command -v git &> /dev/null && git rev-parse &> /dev/null; then
|
2013-11-21 22:11:17 +00:00
|
|
|
GITCOMMIT=$(git rev-parse --short HEAD)
|
2014-02-10 20:44:34 +00:00
|
|
|
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
2013-11-21 22:11:17 +00: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-15 01:01:13 +00:00
|
|
|
fi
|
2013-08-07 04:00:50 +00:00
|
|
|
|
2014-02-10 01:21:01 +00:00
|
|
|
if [ "$AUTO_GOPATH" ]; then
|
|
|
|
rm -rf .gopath
|
2014-07-30 23:02:04 +00:00
|
|
|
mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")"
|
|
|
|
ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}"
|
2014-02-10 01:21:01 +00:00
|
|
|
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
|
|
|
|
|
2014-08-01 17:34:06 +00:00
|
|
|
if [ -z "$DOCKER_CLIENTONLY" ]; then
|
|
|
|
DOCKER_BUILDTAGS+=" daemon"
|
|
|
|
fi
|
|
|
|
|
2014-12-30 23:24:53 +00:00
|
|
|
if [ "$DOCKER_EXECDRIVER" = 'lxc' ]; then
|
|
|
|
DOCKER_BUILDTAGS+=' test_no_exec'
|
|
|
|
fi
|
|
|
|
|
2013-09-09 23:20:30 +00:00
|
|
|
# Use these flags when compiling the tests and final binary
|
2014-10-28 23:27:23 +00:00
|
|
|
LDFLAGS='
|
|
|
|
-X '$DOCKER_PKG'/dockerversion.GITCOMMIT "'$GITCOMMIT'"
|
|
|
|
-X '$DOCKER_PKG'/dockerversion.VERSION "'$VERSION'"
|
|
|
|
'
|
2014-11-20 17:56:54 +00:00
|
|
|
|
|
|
|
if [ -z "$DEBUG" ]; then
|
2014-12-29 19:02:12 +00:00
|
|
|
LDFLAGS="-w $LDFLAGS"
|
2014-11-20 17:56:54 +00:00
|
|
|
fi
|
|
|
|
|
2014-03-07 02:55:22 +00:00
|
|
|
LDFLAGS_STATIC='-linkmode external'
|
2014-11-18 22:44:05 +00:00
|
|
|
# Cgo -H windows is incompatible with -linkmode external.
|
|
|
|
if [ "$(go env GOOS)" == 'windows' ]; then
|
|
|
|
LDFLAGS_STATIC=''
|
|
|
|
fi
|
2014-03-07 02:55:22 +00:00
|
|
|
EXTLDFLAGS_STATIC='-static'
|
2014-09-25 18:22:24 +00:00
|
|
|
# ORIG_BUILDFLAGS is necessary for the cross target which cannot always build
|
|
|
|
# with options like -race.
|
2015-01-17 05:00:44 +00:00
|
|
|
ORIG_BUILDFLAGS=( -a -tags "netgo static_build $DOCKER_BUILDTAGS" -installsuffix netgo )
|
|
|
|
# see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here
|
2014-09-25 18:22:24 +00:00
|
|
|
BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" )
|
|
|
|
# Test timeout.
|
|
|
|
: ${TIMEOUT:=30m}
|
|
|
|
TESTFLAGS+=" -test.timeout=${TIMEOUT}"
|
2013-09-09 23:20:30 +00:00
|
|
|
|
2014-03-07 02:55:22 +00:00
|
|
|
# A few more flags that are specific just to building a completely-static binary (see hack/make/binary)
|
|
|
|
# PLEASE do not use these anywhere else.
|
|
|
|
EXTLDFLAGS_STATIC_DOCKER="$EXTLDFLAGS_STATIC -lpthread -Wl,--unresolved-symbols=ignore-in-object-files"
|
|
|
|
LDFLAGS_STATIC_DOCKER="
|
|
|
|
$LDFLAGS_STATIC
|
2014-10-28 23:25:50 +00:00
|
|
|
-X $DOCKER_PKG/dockerversion.IAMSTATIC true
|
2014-03-07 02:55:22 +00:00
|
|
|
-extldflags \"$EXTLDFLAGS_STATIC_DOCKER\"
|
|
|
|
"
|
|
|
|
|
2014-02-28 22:45:56 +00:00
|
|
|
if [ "$(uname -s)" = 'FreeBSD' ]; then
|
|
|
|
# Tell cgo the compiler is Clang, not GCC
|
|
|
|
# https://code.google.com/p/go/source/browse/src/cmd/cgo/gcc.go?spec=svne77e74371f2340ee08622ce602e9f7b15f29d8d3&r=e6794866ebeba2bf8818b9261b54e2eef1c9e588#752
|
|
|
|
export CC=clang
|
|
|
|
|
|
|
|
# "-extld clang" is a workaround for
|
|
|
|
# https://code.google.com/p/go/issues/detail?id=6845
|
|
|
|
LDFLAGS="$LDFLAGS -extld clang"
|
|
|
|
fi
|
|
|
|
|
2014-04-16 15:41:19 +00:00
|
|
|
# If sqlite3.h doesn't exist under /usr/include,
|
|
|
|
# check /usr/local/include also just in case
|
|
|
|
# (e.g. FreeBSD Ports installs it under the directory)
|
|
|
|
if [ ! -e /usr/include/sqlite3.h ] && [ -e /usr/local/include/sqlite3.h ]; then
|
|
|
|
export CGO_CFLAGS='-I/usr/local/include'
|
|
|
|
export CGO_LDFLAGS='-L/usr/local/lib'
|
|
|
|
fi
|
|
|
|
|
2013-12-09 03:20:55 +00:00
|
|
|
HAVE_GO_TEST_COVER=
|
2013-12-17 05:54:06 +00:00
|
|
|
if \
|
2013-12-31 01:58:25 +00:00
|
|
|
go help testflag | grep -- -cover > /dev/null \
|
2013-12-17 05:54:06 +00:00
|
|
|
&& go tool -n cover > /dev/null 2>&1 \
|
|
|
|
; then
|
2013-12-09 03:20:55 +00:00
|
|
|
HAVE_GO_TEST_COVER=1
|
|
|
|
fi
|
|
|
|
|
2013-12-08 20:49:57 +00: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 23:21:20 +00:00
|
|
|
coverpkg=$2
|
2013-12-09 03:20:55 +00: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 23:21:20 +00:00
|
|
|
testcover=( -cover -coverprofile "$coverprofile" $coverpkg )
|
2013-12-09 03:20:55 +00:00
|
|
|
fi
|
2013-12-08 20:49:57 +00:00
|
|
|
(
|
2014-07-23 18:12:42 +00:00
|
|
|
export DEST
|
2014-07-30 23:02:04 +00:00
|
|
|
echo '+ go test' $TESTFLAGS "${DOCKER_PKG}${dir#.}"
|
2013-12-08 20:49:57 +00:00
|
|
|
cd "$dir"
|
2015-02-14 10:27:31 +00:00
|
|
|
test_env go test ${testcover[@]} -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS
|
2013-12-08 20:49:57 +00:00
|
|
|
)
|
|
|
|
}
|
2015-02-14 10:27:31 +00:00
|
|
|
test_env() {
|
|
|
|
# use "env -i" to tightly control the environment variables that bleed into the tests
|
|
|
|
env -i \
|
|
|
|
DEST="$DEST" \
|
|
|
|
DOCKER_EXECDRIVER="$DOCKER_EXECDRIVER" \
|
|
|
|
DOCKER_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \
|
|
|
|
DOCKER_HOST="$DOCKER_HOST" \
|
|
|
|
GOPATH="$GOPATH" \
|
|
|
|
HOME="$DEST/fake-HOME" \
|
|
|
|
PATH="$PATH" \
|
|
|
|
TEST_DOCKERINIT_PATH="$TEST_DOCKERINIT_PATH" \
|
|
|
|
"$@"
|
|
|
|
}
|
2013-12-08 20:49:57 +00:00
|
|
|
|
2015-01-10 00:28:40 +00:00
|
|
|
# a helper to provide ".exe" when it's appropriate
|
|
|
|
binary_extension() {
|
|
|
|
if [ "$(go env GOOS)" = 'windows' ]; then
|
|
|
|
echo -n '.exe'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-02-10 23:21:20 +00: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() {
|
2014-03-21 05:31:39 +00:00
|
|
|
find . -not \( \
|
2014-03-12 07:18:12 +00:00
|
|
|
\( \
|
2015-01-10 00:28:40 +00:00
|
|
|
-path './vendor/*' \
|
|
|
|
-o -path './integration/*' \
|
|
|
|
-o -path './integration-cli/*' \
|
|
|
|
-o -path './contrib/*' \
|
|
|
|
-o -path './pkg/mflag/example/*' \
|
|
|
|
-o -path './.git/*' \
|
|
|
|
-o -path './bundles/*' \
|
|
|
|
-o -path './docs/*' \
|
|
|
|
-o -path './pkg/libcontainer/nsinit/*' \
|
2014-03-12 07:18:12 +00:00
|
|
|
\) \
|
2014-02-10 23:21:20 +00:00
|
|
|
-prune \
|
|
|
|
\) -name "$1" -print0 | xargs -0n1 dirname | sort -u
|
|
|
|
}
|
|
|
|
|
2014-03-20 01:58:39 +00:00
|
|
|
hash_files() {
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
f="$1"
|
|
|
|
shift
|
|
|
|
dir="$(dirname "$f")"
|
|
|
|
base="$(basename "$f")"
|
|
|
|
for hashAlgo in md5 sha256; do
|
|
|
|
if command -v "${hashAlgo}sum" &> /dev/null; then
|
|
|
|
(
|
|
|
|
# subshell and cd so that we get output files like:
|
|
|
|
# $HASH docker-$VERSION
|
|
|
|
# instead of:
|
|
|
|
# $HASH /go/src/github.com/.../$VERSION/binary/docker-$VERSION
|
|
|
|
cd "$dir"
|
|
|
|
"${hashAlgo}sum" "$base" > "$base.$hashAlgo"
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
bundle() {
|
|
|
|
bundlescript=$1
|
|
|
|
bundle=$(basename $bundlescript)
|
2013-09-23 18:19:28 +00:00
|
|
|
echo "---> Making bundle: $bundle (in bundles/$VERSION/$bundle)"
|
2013-09-10 01:45:40 +00:00
|
|
|
mkdir -p bundles/$VERSION/$bundle
|
2014-11-18 22:44:05 +00:00
|
|
|
source "$bundlescript" "$(pwd)/bundles/$VERSION/$bundle"
|
2013-08-07 04:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2013-09-23 18:19:28 +00:00
|
|
|
# We want this to fail if the bundles already exist and cannot be removed.
|
2013-09-10 01:45:40 +00: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 18:19:28 +00:00
|
|
|
echo
|
2013-09-10 01:45:40 +00:00
|
|
|
fi
|
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
if [ $# -lt 1 ]; then
|
2013-10-18 03:33:34 +00:00
|
|
|
bundles=(${DEFAULT_BUNDLES[@]})
|
2013-09-10 01:45:40 +00:00
|
|
|
else
|
|
|
|
bundles=($@)
|
|
|
|
fi
|
|
|
|
for bundle in ${bundles[@]}; do
|
|
|
|
bundle $SCRIPTDIR/make/$bundle
|
2013-09-23 18:19:28 +00:00
|
|
|
echo
|
2013-09-10 01:45:40 +00:00
|
|
|
done
|
2013-08-07 04:00:50 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
main "$@"
|