#!/bin/sh # This script builds various binary artifacts from a checkout of the docker # source code. # # Requirements: # - 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, # with the suffix +CHANGES if the repository isn't clean. # - 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. # set -e set -x # 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 } VERSION=$(cat ./VERSION) GIT_COMMIT=$(git rev-parse --short HEAD) GIT_CHANGES=$(test -n "$(git status --porcelain)" && echo "+CHANGES" || true) PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)" PACKAGE_URL="http://www.docker.io/" PACKAGE_MAINTAINER="docker@dotcloud.com" PACKAGE_DESCRIPTION="lxc-docker is a Linux container runtime Docker complements LXC with a high-level API which operates at the process level. It runs unix processes with strong guarantees of isolation and repeatability across servers. Docker is a great building block for automating distributed systems: large-scale web deployments, database clusters, continuous deployment systems, private PaaS, service-oriented architectures, etc." # Each "bundle" is a different type of build artefact: static binary, Ubuntu # package, etc. # Build Docker as a static binary file bundle_binary() { mkdir -p bundles/$VERSION/binary go build -o bundles/$VERSION/binary/docker-$VERSION \ -ldflags "-X main.GITCOMMIT $GIT_COMMIT$GIT_CHANGES -X main.VERSION $VERSION -d -w" \ ./docker } # Build Docker's test suite as a collection of binary files (one per # sub-package to test) bundle_test() { mkdir -p bundles/$VERSION/test for test_dir in $(find_test_dirs); do test_binary=$( cd $test_dir go test -c -v -ldflags "-X main.GITCOMMIT $GIT_COMMIT$GIT_CHANGES -X main.VERSION $VERSION -d -w" >&2 find . -maxdepth 1 -type f -name '*.test' -executable ) cp $test_dir/$test_binary bundles/$VERSION/test/ done } # Build docker as an ubuntu package using FPM and REPREPRO (sue me). # bundle_binary must be called first. bundle_ubuntu() { mkdir -p bundles/$VERSION/ubuntu DIR=$(pwd)/bundles/$VERSION/ubuntu/build # Generate an upstart config file (ubuntu-specific) mkdir -p $DIR/etc/init cat > $DIR/etc/init/docker.conf <