2013-09-10 01:45:40 +00:00
|
|
|
#!/bin/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
|
|
|
|
# (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 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.
|
|
|
|
# - The right way to call this script is to invoke "docker build ." from
|
2013-09-10 18:33:26 +00:00
|
|
|
# your checkout of the Docker repository, and then
|
2013-09-23 18:19:28 +00:00
|
|
|
# "docker run hack/make.sh" in the resulting container image.
|
|
|
|
#
|
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
|
|
|
|
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!
|
|
|
|
RESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
|
|
|
|
grep -q "$RESOLVCONF" /proc/mounts || {
|
2013-09-30 19:57:30 +00:00
|
|
|
echo >&2 "# WARNING! I don't seem to be running in a docker container."
|
|
|
|
echo >&2 "# The result of this command might be an incorrect build, and will not be officially supported."
|
|
|
|
echo >&2 "# Try this: 'docker build -t docker . && docker run docker ./hack/make.sh'"
|
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=(
|
|
|
|
binary
|
2013-10-18 03:33:34 +00:00
|
|
|
test
|
2013-10-18 05:40:41 +00:00
|
|
|
dynbinary
|
|
|
|
dyntest
|
2013-09-10 01:45:40 +00:00
|
|
|
ubuntu
|
|
|
|
)
|
|
|
|
|
2013-08-10 00:38:48 +00:00
|
|
|
VERSION=$(cat ./VERSION)
|
2013-08-15 01:01:13 +00:00
|
|
|
GITCOMMIT=$(git rev-parse --short HEAD)
|
2013-09-23 18:19:28 +00:00
|
|
|
if [ -n "$(git status --porcelain)" ]; then
|
2013-08-16 22:30:50 +00:00
|
|
|
GITCOMMIT="$GITCOMMIT-dirty"
|
2013-08-15 01:01:13 +00:00
|
|
|
fi
|
2013-08-07 04:00:50 +00:00
|
|
|
|
2013-09-09 23:20:30 +00:00
|
|
|
# Use these flags when compiling the tests and final binary
|
2013-10-18 05:38:34 +00:00
|
|
|
LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w'
|
2013-10-18 05:40:41 +00:00
|
|
|
LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"'
|
2013-10-05 02:25:15 +00:00
|
|
|
BUILDFLAGS='-tags netgo'
|
2013-09-09 23:20:30 +00:00
|
|
|
|
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
|
|
|
|
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 "$@"
|