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
|
2015-04-11 17:22:16 +00:00
|
|
|
# (https://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,
|
2015-12-24 17:11:49 +00:00
|
|
|
# with the suffix -unsupported if the repository isn't clean.
|
2015-12-13 16:00:39 +00:00
|
|
|
# - The script is intended 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'
|
2015-04-14 15:38:14 +00:00
|
|
|
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2015-04-14 16:43:33 +00:00
|
|
|
export MAKEDIR="$SCRIPTDIR/make"
|
2014-07-30 23:02:04 +00:00
|
|
|
|
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!
|
2015-04-14 15:21:12 +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-07-22 22:19:32 +00:00
|
|
|
validate-lint
|
2015-06-12 19:19:56 +00:00
|
|
|
validate-pkg
|
2015-04-22 18:20:32 +00:00
|
|
|
validate-test
|
2015-01-30 19:45:02 +00:00
|
|
|
validate-toml
|
2015-04-01 04:48:03 +00:00
|
|
|
validate-vet
|
2014-07-03 18:29:07 +00:00
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
binary
|
2015-11-06 07:35:47 +00:00
|
|
|
dynbinary
|
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-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
|
|
|
)
|
|
|
|
|
2015-04-14 16:31:52 +00:00
|
|
|
VERSION=$(< ./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
|
2015-12-24 17:11:49 +00:00
|
|
|
GITCOMMIT="$GITCOMMIT-unsupported"
|
2013-11-21 22:11:17 +00:00
|
|
|
fi
|
2015-12-03 18:12:11 +00:00
|
|
|
! BUILDTIME=$(date --rfc-3339 ns | sed -e 's/ /T/') &> /dev/null
|
|
|
|
if [ -z $BUILDTIME ]; then
|
|
|
|
# If using bash 3.1 which doesn't support --rfc-3389, eg Windows CI
|
|
|
|
BUILDTIME=$(date -u)
|
|
|
|
fi
|
2013-11-21 22:11:17 +00:00
|
|
|
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}"
|
2015-04-14 15:21:12 +00:00
|
|
|
export GOPATH="${PWD}/.gopath:${PWD}/vendor"
|
2014-02-10 01:21:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! "$GOPATH" ]; then
|
2015-04-11 17:22:16 +00:00
|
|
|
echo >&2 'error: missing GOPATH; please see https://golang.org/doc/code.html#GOPATH'
|
2014-02-10 01:21:01 +00:00
|
|
|
echo >&2 ' alternatively, set AUTO_GOPATH=1'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-09-18 17:41:12 +00:00
|
|
|
if [ "$DOCKER_EXPERIMENTAL" ] || [ "$DOCKER_REMAP_ROOT" ]; then
|
2015-05-19 22:09:58 +00:00
|
|
|
echo >&2 '# WARNING! DOCKER_EXPERIMENTAL is set: building experimental features'
|
|
|
|
echo >&2
|
2015-10-31 01:14:10 +00:00
|
|
|
DOCKER_BUILDTAGS+=" experimental pkcs11"
|
2015-05-19 22:09:58 +00:00
|
|
|
fi
|
|
|
|
|
2014-08-01 17:34:06 +00:00
|
|
|
if [ -z "$DOCKER_CLIENTONLY" ]; then
|
|
|
|
DOCKER_BUILDTAGS+=" daemon"
|
Add log reading to the journald log driver
If a logdriver doesn't register a callback function to validate log
options, it won't be usable. Fix the journald driver by adding a dummy
validator.
Teach the client and the daemon's "logs" logic that the server can also
supply "logs" data via the "journald" driver. Update documentation and
tests that depend on error messages.
Add support for reading log data from the systemd journal to the
journald log driver. The internal logic uses a goroutine to scan the
journal for matching entries after any specified cutoff time, formats
the messages from those entries as JSONLog messages, and stuffs the
results down a pipe whose reading end we hand back to the caller.
If we are missing any of the 'linux', 'cgo', or 'journald' build tags,
however, we don't implement a reader, so the 'logs' endpoint will still
return an error.
Make the necessary changes to the build setup to ensure that support for
reading container logs from the systemd journal is built.
Rename the Jmap member of the journald logdriver's struct to "vars" to
make it non-public, and to make it easier to tell that it's just there
to hold additional variable values that we want journald to record along
with log data that we're sending to it.
In the client, don't assume that we know which logdrivers the server
implements, and remove the check that looks at the server. It's
redundant because the server already knows, and the check also makes
using older clients with newer servers (which may have new logdrivers in
them) unnecessarily hard.
When we try to "logs" and have to report that the container's logdriver
doesn't support reading, send the error message through the
might-be-a-multiplexer so that clients which are expecting multiplexed
data will be able to properly display the error, instead of tripping
over the data and printing a less helpful "Unrecognized input header"
error.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> (github: nalind)
2015-07-23 15:02:56 +00:00
|
|
|
if pkg-config libsystemd-journal 2> /dev/null ; then
|
|
|
|
DOCKER_BUILDTAGS+=" journald"
|
|
|
|
fi
|
2014-08-01 17:34:06 +00:00
|
|
|
fi
|
|
|
|
|
2015-04-03 07:30:12 +00:00
|
|
|
# test whether "btrfs/version.h" exists and apply btrfs_noversion appropriately
|
|
|
|
if \
|
|
|
|
command -v gcc &> /dev/null \
|
2015-11-17 17:44:36 +00:00
|
|
|
&& ! gcc -E - -o /dev/null &> /dev/null <<<'#include <btrfs/version.h>' \
|
2015-04-03 07:30:12 +00:00
|
|
|
; then
|
|
|
|
DOCKER_BUILDTAGS+=' btrfs_noversion'
|
|
|
|
fi
|
|
|
|
|
2015-04-21 22:14:59 +00:00
|
|
|
# test whether "libdevmapper.h" is new enough to support deferred remove
|
|
|
|
# functionality.
|
|
|
|
if \
|
|
|
|
command -v gcc &> /dev/null \
|
2015-11-17 17:44:36 +00:00
|
|
|
&& ! ( echo -e '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }'| gcc -ldevmapper -xc - -o /dev/null &> /dev/null ) \
|
2015-04-21 22:14:59 +00:00
|
|
|
; then
|
|
|
|
DOCKER_BUILDTAGS+=' libdm_no_deferred_remove'
|
|
|
|
fi
|
|
|
|
|
2013-09-09 23:20:30 +00:00
|
|
|
# Use these flags when compiling the tests and final binary
|
2014-11-20 17:56:54 +00:00
|
|
|
|
2015-02-04 21:22:38 +00:00
|
|
|
IAMSTATIC='true'
|
2015-04-14 15:38:14 +00:00
|
|
|
source "$SCRIPTDIR/make/.go-autogen"
|
2015-05-07 12:22:44 +00:00
|
|
|
if [ -z "$DOCKER_DEBUG" ]; then
|
|
|
|
LDFLAGS='-w'
|
|
|
|
fi
|
2014-11-20 17:56:54 +00:00
|
|
|
|
2015-11-15 22:47:48 +00:00
|
|
|
LDFLAGS_STATIC=''
|
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-11-09 18:32:46 +00:00
|
|
|
ORIG_BUILDFLAGS=( -a -tags "autogen netgo static_build sqlite_omit_load_extension $DOCKER_BUILDTAGS" -installsuffix netgo )
|
2015-01-17 05:00:44 +00:00
|
|
|
# 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.
|
2015-02-24 18:33:18 +00:00
|
|
|
: ${TIMEOUT:=120m}
|
2014-09-25 18:22:24 +00:00
|
|
|
TESTFLAGS+=" -test.timeout=${TIMEOUT}"
|
2013-09-09 23:20:30 +00:00
|
|
|
|
2014-03-07 02:55:22 +00:00
|
|
|
LDFLAGS_STATIC_DOCKER="
|
|
|
|
$LDFLAGS_STATIC
|
2015-09-08 18:29:43 +00:00
|
|
|
-extldflags \"$EXTLDFLAGS_STATIC\"
|
2014-03-07 02:55:22 +00:00
|
|
|
"
|
|
|
|
|
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.
|
|
|
|
#
|
2015-04-30 07:40:48 +00:00
|
|
|
# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
|
|
|
|
#
|
|
|
|
# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
|
|
|
|
# to run certain tests on your local host, you should run with command:
|
|
|
|
#
|
|
|
|
# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration-cli
|
2013-12-08 20:49:57 +00:00
|
|
|
#
|
|
|
|
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#.}"
|
2015-05-29 20:07:16 +00:00
|
|
|
coverprofile="$ABS_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-30 23:02:04 +00:00
|
|
|
echo '+ go test' $TESTFLAGS "${DOCKER_PKG}${dir#.}"
|
2013-12-08 20:49:57 +00:00
|
|
|
cd "$dir"
|
2015-05-29 20:07:16 +00:00
|
|
|
export DEST="$ABS_DEST" # we're in a subshell, so this is safe -- our integration-cli tests need DEST, and "cd" screws it up
|
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_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \
|
2015-04-07 23:53:39 +00:00
|
|
|
DOCKER_USERLANDPROXY="$DOCKER_USERLANDPROXY" \
|
2015-02-14 10:27:31 +00:00
|
|
|
DOCKER_HOST="$DOCKER_HOST" \
|
2015-10-10 02:09:02 +00:00
|
|
|
DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \
|
2015-08-05 16:21:45 +00:00
|
|
|
DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \
|
2015-02-14 10:27:31 +00:00
|
|
|
GOPATH="$GOPATH" \
|
2015-05-29 20:07:16 +00:00
|
|
|
HOME="$ABS_DEST/fake-HOME" \
|
2015-02-14 10:27:31 +00:00
|
|
|
PATH="$PATH" \
|
2015-05-22 22:14:22 +00:00
|
|
|
TEMP="$TEMP" \
|
2015-02-14 10:27:31 +00:00
|
|
|
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-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() {
|
2015-05-29 20:07:16 +00:00
|
|
|
local bundle="$1"; shift
|
|
|
|
echo "---> Making bundle: $(basename "$bundle") (in $DEST)"
|
|
|
|
source "$SCRIPTDIR/make/$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
|
2015-11-05 01:17:37 +00:00
|
|
|
if [ -e "bundles/$VERSION" ] && [ -z "$KEEPBUNDLE" ]; then
|
2013-09-10 01:45:40 +00:00
|
|
|
echo "bundles/$VERSION already exists. Removing."
|
2015-04-14 16:08:08 +00:00
|
|
|
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
|
2015-04-03 08:07:57 +00:00
|
|
|
|
|
|
|
if [ "$(go env GOHOSTOS)" != 'windows' ]; then
|
|
|
|
# Windows and symlinks don't get along well
|
2015-05-26 12:54:08 +00:00
|
|
|
|
2015-05-27 07:21:09 +00:00
|
|
|
rm -f bundles/latest
|
|
|
|
ln -s "$VERSION" bundles/latest
|
2015-04-03 08:07:57 +00:00
|
|
|
fi
|
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
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
|
2015-05-29 20:07:16 +00:00
|
|
|
export DEST="bundles/$VERSION/$(basename "$bundle")"
|
|
|
|
# Cygdrive paths don't play well with go build -o.
|
|
|
|
if [[ "$(uname -s)" == CYGWIN* ]]; then
|
|
|
|
export DEST="$(cygpath -mw "$DEST")"
|
|
|
|
fi
|
|
|
|
mkdir -p "$DEST"
|
|
|
|
ABS_DEST="$(cd "$DEST" && pwd -P)"
|
|
|
|
bundle "$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 "$@"
|