2013-09-09 21:45:40 -04:00
|
|
|
#!/bin/bash
|
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-08-09 20:38:48 -04:00
|
|
|
# - The script is intented to be run as part of a docker build, as defined
|
|
|
|
# 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
|
|
|
|
# your checkout of the Docker repository.
|
2013-08-07 00:00:50 -04:00
|
|
|
#
|
|
|
|
|
2013-09-09 19:20:30 -04:00
|
|
|
# FIXME: break down bundles into sub-scripts
|
|
|
|
# FIXME: create all bundles in a single run for consistency.
|
|
|
|
# If the bundles directory already exists, fail or erase it.
|
|
|
|
|
2013-08-07 00:00:50 -04:00
|
|
|
set -e
|
|
|
|
|
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!
|
|
|
|
RESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
|
|
|
|
grep -q "$RESOLVCONF" /proc/mounts || {
|
|
|
|
echo "# I will only run within a container."
|
|
|
|
echo "# Try this instead:"
|
|
|
|
echo "docker build ."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-09-09 21:45:40 -04:00
|
|
|
# List of bundles to create when no argument is passed
|
|
|
|
DEFAULT_BUNDLES=(
|
|
|
|
test
|
|
|
|
binary
|
|
|
|
ubuntu
|
|
|
|
)
|
|
|
|
|
2013-08-09 20:38:48 -04:00
|
|
|
VERSION=$(cat ./VERSION)
|
2013-08-14 21:01:13 -04:00
|
|
|
GITCOMMIT=$(git rev-parse --short HEAD)
|
|
|
|
if test -n "$(git status --porcelain)"
|
|
|
|
then
|
2013-08-16 18:30:50 -04:00
|
|
|
GITCOMMIT="$GITCOMMIT-dirty"
|
2013-08-14 21:01:13 -04:00
|
|
|
fi
|
2013-08-07 00:00:50 -04:00
|
|
|
|
2013-09-09 19:20:30 -04:00
|
|
|
# Use these flags when compiling the tests and final binary
|
|
|
|
LDFLAGS="-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w"
|
|
|
|
|
2013-08-07 00:00:50 -04:00
|
|
|
|
2013-09-09 21:45:40 -04:00
|
|
|
bundle() {
|
|
|
|
bundlescript=$1
|
|
|
|
bundle=$(basename $bundlescript)
|
|
|
|
echo "---> Making bundle: $bundle"
|
|
|
|
mkdir -p bundles/$VERSION/$bundle
|
|
|
|
source $bundlescript $(pwd)/bundles/$VERSION/$bundle
|
2013-08-07 00:00:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2013-09-09 21:45:40 -04:00
|
|
|
|
|
|
|
# We want this to fail if the bundles already exist.
|
|
|
|
# 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
|
|
|
|
fi
|
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
bundles=($DEFAULT_BUNDLES)
|
|
|
|
else
|
|
|
|
bundles=($@)
|
|
|
|
fi
|
|
|
|
for bundle in ${bundles[@]}; do
|
|
|
|
bundle $SCRIPTDIR/make/$bundle
|
|
|
|
done
|
2013-08-09 21:23:48 -04:00
|
|
|
cat <<EOF
|
|
|
|
###############################################################################
|
|
|
|
Now run the resulting image, making sure that you set AWS_S3_BUCKET,
|
|
|
|
AWS_ACCESS_KEY, and AWS_SECRET_KEY environment variables:
|
|
|
|
|
|
|
|
docker run -e AWS_S3_BUCKET=get-staging.docker.io \\
|
|
|
|
AWS_ACCESS_KEY=AKI1234... \\
|
|
|
|
AWS_SECRET_KEY=sEs3mE... \\
|
2013-08-14 20:02:55 -04:00
|
|
|
GPG_PASSPHRASE=sesame... \\
|
2013-08-09 21:23:48 -04:00
|
|
|
image_id_or_name
|
|
|
|
###############################################################################
|
|
|
|
EOF
|
2013-08-07 00:00:50 -04:00
|
|
|
}
|
|
|
|
|
2013-09-09 21:45:40 -04:00
|
|
|
main "$@"
|