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'
|
2020-03-03 03:27:49 +00:00
|
|
|
export SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2015-04-14 16:43:33 +00:00
|
|
|
export MAKEDIR="$SCRIPTDIR/make"
|
2016-06-02 19:09:09 +00:00
|
|
|
export PKG_CONFIG=${PKG_CONFIG:-pkg-config}
|
2014-07-30 23:02:04 +00:00
|
|
|
|
2014-01-25 06:01:12 +00:00
|
|
|
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=(
|
2016-02-19 22:42:51 +00:00
|
|
|
binary-daemon
|
2015-11-06 07:35:47 +00:00
|
|
|
dynbinary
|
2017-05-23 20:32:34 +00:00
|
|
|
test-integration
|
2014-12-19 07:20:59 +00:00
|
|
|
test-docker-py
|
2013-09-10 01:45:40 +00:00
|
|
|
)
|
|
|
|
|
2017-11-01 19:46:46 +00:00
|
|
|
VERSION=${VERSION:-dev}
|
2022-12-26 17:46:26 +00:00
|
|
|
if [[ $VERSION == refs/tags/* ]]; then
|
|
|
|
VERSION=${VERSION#refs/tags/}
|
|
|
|
elif [[ $VERSION == refs/heads/* ]]; then
|
|
|
|
VERSION=$(sed <<< "${VERSION#refs/heads/}" -r 's#/+#-#g')
|
|
|
|
elif [[ $VERSION == refs/pull/* ]]; then
|
|
|
|
VERSION=pr-$(grep <<< "$VERSION" -o '[0-9]\+')
|
|
|
|
fi
|
|
|
|
|
2017-07-19 04:17:19 +00:00
|
|
|
! BUILDTIME=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ "$DOCKER_GITCOMMIT" ]; then
|
2016-11-16 10:49:32 +00:00
|
|
|
GITCOMMIT="$DOCKER_GITCOMMIT"
|
2017-08-01 15:51:24 +00:00
|
|
|
elif command -v git &> /dev/null && [ -e .git ] && git rev-parse &> /dev/null; then
|
2013-11-21 22:11:17 +00:00
|
|
|
GITCOMMIT=$(git rev-parse --short HEAD)
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
2015-12-24 17:11:49 +00:00
|
|
|
GITCOMMIT="$GITCOMMIT-unsupported"
|
2016-03-25 14:09:03 +00:00
|
|
|
echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
|
|
|
echo "# GITCOMMIT = $GITCOMMIT"
|
|
|
|
echo "# The version you are building is listed as unsupported because"
|
2016-10-29 07:03:26 +00:00
|
|
|
echo "# there are some files in the git repository that are in an uncommitted state."
|
2016-03-25 14:09:03 +00:00
|
|
|
echo "# Commit these changes, or add to .gitignore to remove the -unsupported from the version."
|
|
|
|
echo "# Here is the current list:"
|
|
|
|
git status --porcelain --untracked-files=no
|
|
|
|
echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
2013-11-21 22:11:17 +00:00
|
|
|
fi
|
|
|
|
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
|
|
|
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ "$AUTO_GOPATH" ]; then
|
2014-02-10 01:21:01 +00:00
|
|
|
rm -rf .gopath
|
2014-07-30 23:02:04 +00:00
|
|
|
mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")"
|
|
|
|
ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}"
|
2016-10-31 18:22:28 +00:00
|
|
|
export GOPATH="${PWD}/.gopath"
|
2014-02-10 01:21:01 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-10 01:23:38 +00:00
|
|
|
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
|
|
|
|
|
2017-11-16 06:09:16 +00:00
|
|
|
# Adds $1_$2 to DOCKER_BUILDTAGS unless it already
|
|
|
|
# contains a word starting from $1_
|
|
|
|
add_buildtag() {
|
|
|
|
[[ " $DOCKER_BUILDTAGS" == *" $1_"* ]] || DOCKER_BUILDTAGS+=" $1_$2"
|
|
|
|
}
|
|
|
|
|
2022-07-20 11:24:28 +00:00
|
|
|
if ${PKG_CONFIG} 'libsystemd' 2> /dev/null; then
|
2016-02-19 22:42:51 +00:00
|
|
|
DOCKER_BUILDTAGS+=" journald"
|
2014-08-01 17:34:06 +00:00
|
|
|
fi
|
|
|
|
|
2015-04-21 22:14:59 +00:00
|
|
|
# test whether "libdevmapper.h" is new enough to support deferred remove
|
2017-11-16 06:09:16 +00:00
|
|
|
# functionality. We favour libdm_dlsym_deferred_remove over
|
|
|
|
# libdm_no_deferred_remove in dynamic cases because the binary could be shipped
|
2018-08-08 15:45:00 +00:00
|
|
|
# with a newer libdevmapper than the one it was built with.
|
2022-12-27 00:51:08 +00:00
|
|
|
if command -v gcc &> /dev/null && ! (echo -e '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }' | gcc -xc - -o /dev/null $(${PKG_CONFIG} --libs devmapper 2> /dev/null) &> /dev/null); then
|
2017-11-16 06:09:16 +00:00
|
|
|
add_buildtag libdm dlsym_deferred_remove
|
2015-04-21 22:14:59 +00:00
|
|
|
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
|
|
|
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ -z "$DOCKER_DEBUG" ]; then
|
2015-05-07 12:22:44 +00:00
|
|
|
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'
|
2023-01-18 19:14:52 +00:00
|
|
|
BUILDFLAGS=(${BUILDFLAGS} -tags "netgo osusergo static_build $DOCKER_BUILDTAGS")
|
2016-01-20 06:30:54 +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
|
|
|
"
|
|
|
|
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ "$(uname -s)" = 'FreeBSD' ]; then
|
2014-02-28 22:45:56 +00:00
|
|
|
# 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
|
|
|
|
|
2013-09-10 01:45:40 +00:00
|
|
|
bundle() {
|
2020-03-03 03:27:49 +00:00
|
|
|
local bundle="$1"
|
|
|
|
shift
|
2015-05-29 20:07:16 +00:00
|
|
|
echo "---> Making bundle: $(basename "$bundle") (in $DEST)"
|
|
|
|
source "$SCRIPTDIR/make/$bundle" "$@"
|
2013-08-07 04:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2019-11-05 21:07:47 +00:00
|
|
|
bundle_dir="bundles"
|
|
|
|
if [ -n "${PREFIX}" ]; then
|
|
|
|
bundle_dir="${PREFIX}/${bundle_dir}"
|
|
|
|
fi
|
|
|
|
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ -z "${KEEPBUNDLE-}" ]; then
|
2019-11-05 21:07:47 +00:00
|
|
|
echo "Removing ${bundle_dir}/"
|
|
|
|
rm -rf "${bundle_dir}"/*
|
2013-09-23 18:19:28 +00:00
|
|
|
echo
|
2013-09-10 01:45:40 +00:00
|
|
|
fi
|
2019-11-05 21:07:47 +00:00
|
|
|
mkdir -p "${bundle_dir}"
|
2015-04-03 08:07:57 +00:00
|
|
|
|
2019-01-10 01:23:38 +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
|
2019-11-05 21:07:47 +00:00
|
|
|
export DEST="${bundle_dir}/$(basename "$bundle")"
|
2015-05-29 20:07:16 +00:00
|
|
|
# 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 "$@"
|