| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-#!/bin/sh |
|
| 1 |
+#!/bin/bash |
|
| 2 | 2 |
|
| 3 | 3 |
# This script builds various binary artifacts from a checkout of the docker |
| 4 | 4 |
# source code. |
| ... | ... |
@@ -34,139 +34,50 @@ grep -q "$RESOLVCONF" /proc/mounts || {
|
| 34 | 34 |
exit 1 |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
+# List of bundles to create when no argument is passed |
|
| 38 |
+DEFAULT_BUNDLES=( |
|
| 39 |
+ test |
|
| 40 |
+ binary |
|
| 41 |
+ ubuntu |
|
| 42 |
+) |
|
| 43 |
+ |
|
| 37 | 44 |
VERSION=$(cat ./VERSION) |
| 38 |
-PKGVERSION="$VERSION" |
|
| 39 | 45 |
GITCOMMIT=$(git rev-parse --short HEAD) |
| 40 | 46 |
if test -n "$(git status --porcelain)" |
| 41 | 47 |
then |
| 42 | 48 |
GITCOMMIT="$GITCOMMIT-dirty" |
| 43 |
- PKGVERSION="$PKGVERSION-$(date +%Y%m%d%H%M%S)-$GITCOMMIT" |
|
| 44 | 49 |
fi |
| 45 | 50 |
|
| 46 | 51 |
# Use these flags when compiling the tests and final binary |
| 47 | 52 |
LDFLAGS="-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w" |
| 48 | 53 |
|
| 49 |
-PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)" |
|
| 50 |
-PACKAGE_URL="http://www.docker.io/" |
|
| 51 |
-PACKAGE_MAINTAINER="docker@dotcloud.com" |
|
| 52 |
-PACKAGE_DESCRIPTION="lxc-docker is a Linux container runtime |
|
| 53 |
-Docker complements LXC with a high-level API which operates at the process |
|
| 54 |
-level. It runs unix processes with strong guarantees of isolation and |
|
| 55 |
-repeatability across servers. |
|
| 56 |
-Docker is a great building block for automating distributed systems: |
|
| 57 |
-large-scale web deployments, database clusters, continuous deployment systems, |
|
| 58 |
-private PaaS, service-oriented architectures, etc." |
|
| 59 |
- |
|
| 60 |
-UPSTART_SCRIPT='description "Docker daemon" |
|
| 61 |
- |
|
| 62 |
-start on filesystem and started lxc-net |
|
| 63 |
-stop on runlevel [!2345] |
|
| 64 |
- |
|
| 65 |
-respawn |
|
| 66 |
- |
|
| 67 |
-script |
|
| 68 |
- /usr/bin/docker -d |
|
| 69 |
-end script |
|
| 70 |
-' |
|
| 71 |
- |
|
| 72 |
-# Each "bundle" is a different type of build artefact: static binary, Ubuntu |
|
| 73 |
-# package, etc. |
|
| 74 |
- |
|
| 75 |
-# Run Docker's test suite, including sub-packages, and store their output as a bundle |
|
| 76 |
-bundle_test() {
|
|
| 77 |
- mkdir -p bundles/$VERSION/test |
|
| 78 |
- {
|
|
| 79 |
- date |
|
| 80 |
- for test_dir in $(find_test_dirs); do ( |
|
| 81 |
- set -x |
|
| 82 |
- cd $test_dir |
|
| 83 |
- go test -v -ldflags "$LDFLAGS" |
|
| 84 |
- ) done |
|
| 85 |
- } 2>&1 | tee bundles/$VERSION/test/test.log |
|
| 86 |
-} |
|
| 87 |
- |
|
| 88 |
- |
|
| 89 |
-# This helper function walks the current directory looking for directories |
|
| 90 |
-# holding Go test files, and prints their paths on standard output, one per |
|
| 91 |
-# line. |
|
| 92 |
-find_test_dirs() {
|
|
| 93 |
- find . -name '*_test.go' | grep -v '^./vendor' | |
|
| 94 |
- { while read f; do dirname $f; done; } |
|
|
| 95 |
- sort -u |
|
| 96 |
-} |
|
| 97 |
- |
|
| 98 |
-# Build Docker as a static binary file |
|
| 99 |
-bundle_binary() {
|
|
| 100 |
- mkdir -p bundles/$VERSION/binary |
|
| 101 |
- go build -o bundles/$VERSION/binary/docker-$VERSION \ |
|
| 102 |
- -ldflags "$LDFLAGS" \ |
|
| 103 |
- ./docker |
|
| 104 |
-} |
|
| 105 |
- |
|
| 106 |
-# Build docker as an ubuntu package using FPM and REPREPRO (sue me). |
|
| 107 |
-# bundle_binary must be called first. |
|
| 108 |
-bundle_ubuntu() {
|
|
| 109 |
- mkdir -p bundles/$VERSION/ubuntu |
|
| 110 |
- |
|
| 111 |
- DIR=$(pwd)/bundles/$VERSION/ubuntu/build |
|
| 112 |
- |
|
| 113 |
- # Generate an upstart config file (ubuntu-specific) |
|
| 114 |
- mkdir -p $DIR/etc/init |
|
| 115 |
- echo "$UPSTART_SCRIPT" > $DIR/etc/init/docker.conf |
|
| 116 |
- |
|
| 117 |
- # Copy the binary |
|
| 118 |
- mkdir -p $DIR/usr/bin |
|
| 119 |
- cp bundles/$VERSION/binary/docker-$VERSION $DIR/usr/bin/docker |
|
| 120 | 54 |
|
| 121 |
- # Generate postinstall/prerm scripts |
|
| 122 |
- cat >/tmp/postinstall <<EOF |
|
| 123 |
-#!/bin/sh |
|
| 124 |
-/sbin/stop docker || true |
|
| 125 |
-/sbin/start docker |
|
| 126 |
-EOF |
|
| 127 |
- cat >/tmp/prerm <<EOF |
|
| 128 |
-#!/bin/sh |
|
| 129 |
-/sbin/stop docker || true |
|
| 130 |
-EOF |
|
| 131 |
- chmod +x /tmp/postinstall /tmp/prerm |
|
| 132 |
- |
|
| 133 |
- ( |
|
| 134 |
- cd bundles/$VERSION/ubuntu |
|
| 135 |
- fpm -s dir -C $DIR \ |
|
| 136 |
- --name lxc-docker-$VERSION --version $PKGVERSION \ |
|
| 137 |
- --after-install /tmp/postinstall \ |
|
| 138 |
- --before-remove /tmp/prerm \ |
|
| 139 |
- --architecture "$PACKAGE_ARCHITECTURE" \ |
|
| 140 |
- --prefix / \ |
|
| 141 |
- --depends lxc --depends aufs-tools \ |
|
| 142 |
- --description "$PACKAGE_DESCRIPTION" \ |
|
| 143 |
- --maintainer "$PACKAGE_MAINTAINER" \ |
|
| 144 |
- --conflicts lxc-docker-virtual-package \ |
|
| 145 |
- --provides lxc-docker \ |
|
| 146 |
- --provides lxc-docker-virtual-package \ |
|
| 147 |
- --replaces lxc-docker \ |
|
| 148 |
- --replaces lxc-docker-virtual-package \ |
|
| 149 |
- --url "$PACKAGE_URL" \ |
|
| 150 |
- --vendor "$PACKAGE_VENDOR" \ |
|
| 151 |
- -t deb . |
|
| 152 |
- mkdir empty |
|
| 153 |
- fpm -s dir -C empty \ |
|
| 154 |
- --name lxc-docker --version $PKGVERSION \ |
|
| 155 |
- --architecture "$PACKAGE_ARCHITECTURE" \ |
|
| 156 |
- --depends lxc-docker-$VERSION \ |
|
| 157 |
- --description "$PACKAGE_DESCRIPTION" \ |
|
| 158 |
- --maintainer "$PACKAGE_MAINTAINER" \ |
|
| 159 |
- --url "$PACKAGE_URL" \ |
|
| 160 |
- --vendor "$PACKAGE_VENDOR" \ |
|
| 161 |
- -t deb . |
|
| 162 |
- ) |
|
| 55 |
+bundle() {
|
|
| 56 |
+ bundlescript=$1 |
|
| 57 |
+ bundle=$(basename $bundlescript) |
|
| 58 |
+ echo "---> Making bundle: $bundle" |
|
| 59 |
+ mkdir -p bundles/$VERSION/$bundle |
|
| 60 |
+ source $bundlescript $(pwd)/bundles/$VERSION/$bundle |
|
| 163 | 61 |
} |
| 164 | 62 |
|
| 165 |
- |
|
| 166 | 63 |
main() {
|
| 167 |
- bundle_test |
|
| 168 |
- bundle_binary |
|
| 169 |
- bundle_ubuntu |
|
| 64 |
+ |
|
| 65 |
+ # We want this to fail if the bundles already exist. |
|
| 66 |
+ # This is to avoid mixing bundles from different versions of the code. |
|
| 67 |
+ mkdir -p bundles |
|
| 68 |
+ if [ -e "bundles/$VERSION" ]; then |
|
| 69 |
+ echo "bundles/$VERSION already exists. Removing." |
|
| 70 |
+ rm -fr bundles/$VERSION && mkdir bundles/$VERSION || exit 1 |
|
| 71 |
+ fi |
|
| 72 |
+ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
| 73 |
+ if [ $# -lt 1 ]; then |
|
| 74 |
+ bundles=($DEFAULT_BUNDLES) |
|
| 75 |
+ else |
|
| 76 |
+ bundles=($@) |
|
| 77 |
+ fi |
|
| 78 |
+ for bundle in ${bundles[@]}; do
|
|
| 79 |
+ bundle $SCRIPTDIR/make/$bundle |
|
| 80 |
+ done |
|
| 170 | 81 |
cat <<EOF |
| 171 | 82 |
############################################################################### |
| 172 | 83 |
Now run the resulting image, making sure that you set AWS_S3_BUCKET, |
| ... | ... |
@@ -181,4 +92,4 @@ docker run -e AWS_S3_BUCKET=get-staging.docker.io \\ |
| 181 | 181 |
EOF |
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 |
-main |
|
| 184 |
+main "$@" |
| 185 | 185 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,17 @@ |
| 0 |
+This directory holds scripts called by `make.sh` in the parent directory. |
|
| 1 |
+ |
|
| 2 |
+Each script is named after the bundle it creates. |
|
| 3 |
+They should not be called directly - instead, pass it as argument to make.sh, for example: |
|
| 4 |
+ |
|
| 5 |
+``` |
|
| 6 |
+./hack/make.sh test |
|
| 7 |
+./hack/make.sh binary ubuntu |
|
| 8 |
+ |
|
| 9 |
+# Or to run all bundles: |
|
| 10 |
+./hack/make.sh |
|
| 11 |
+``` |
|
| 12 |
+ |
|
| 13 |
+To add a bundle: |
|
| 14 |
+ |
|
| 15 |
+* Create a shell-compatible file here |
|
| 16 |
+* Add it to $DEFAULT_BUNDLES in make.sh |
| 0 | 4 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,27 @@ |
| 0 |
+DEST=$1 |
|
| 1 |
+ |
|
| 2 |
+set -e |
|
| 3 |
+ |
|
| 4 |
+# Run Docker's test suite, including sub-packages, and store their output as a bundle |
|
| 5 |
+bundle_test() {
|
|
| 6 |
+ {
|
|
| 7 |
+ date |
|
| 8 |
+ for test_dir in $(find_test_dirs); do ( |
|
| 9 |
+ set -x |
|
| 10 |
+ cd $test_dir |
|
| 11 |
+ go test -v -ldflags "$LDFLAGS" |
|
| 12 |
+ ) done |
|
| 13 |
+ } 2>&1 | tee $DEST/test.log |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 16 |
+ |
|
| 17 |
+# This helper function walks the current directory looking for directories |
|
| 18 |
+# holding Go test files, and prints their paths on standard output, one per |
|
| 19 |
+# line. |
|
| 20 |
+find_test_dirs() {
|
|
| 21 |
+ find . -name '*_test.go' | grep -v '^./vendor' | |
|
| 22 |
+ { while read f; do dirname $f; done; } |
|
|
| 23 |
+ sort -u |
|
| 24 |
+} |
|
| 25 |
+ |
|
| 26 |
+bundle_test |
| 0 | 27 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,94 @@ |
| 0 |
+#!/bin/sh |
|
| 1 |
+ |
|
| 2 |
+DEST=$1 |
|
| 3 |
+ |
|
| 4 |
+PKGVERSION="$VERSION" |
|
| 5 |
+if test -n "$(git status --porcelain)" |
|
| 6 |
+then |
|
| 7 |
+ PKGVERSION="$PKGVERSION-$(date +%Y%m%d%H%M%S)-$GITCOMMIT" |
|
| 8 |
+fi |
|
| 9 |
+ |
|
| 10 |
+PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)" |
|
| 11 |
+PACKAGE_URL="http://www.docker.io/" |
|
| 12 |
+PACKAGE_MAINTAINER="docker@dotcloud.com" |
|
| 13 |
+PACKAGE_DESCRIPTION="lxc-docker is a Linux container runtime |
|
| 14 |
+Docker complements LXC with a high-level API which operates at the process |
|
| 15 |
+level. It runs unix processes with strong guarantees of isolation and |
|
| 16 |
+repeatability across servers. |
|
| 17 |
+Docker is a great building block for automating distributed systems: |
|
| 18 |
+large-scale web deployments, database clusters, continuous deployment systems, |
|
| 19 |
+private PaaS, service-oriented architectures, etc." |
|
| 20 |
+ |
|
| 21 |
+UPSTART_SCRIPT='description "Docker daemon" |
|
| 22 |
+ |
|
| 23 |
+start on filesystem and started lxc-net |
|
| 24 |
+stop on runlevel [!2345] |
|
| 25 |
+ |
|
| 26 |
+respawn |
|
| 27 |
+ |
|
| 28 |
+script |
|
| 29 |
+ /usr/bin/docker -d |
|
| 30 |
+end script |
|
| 31 |
+' |
|
| 32 |
+ |
|
| 33 |
+# Build docker as an ubuntu package using FPM and REPREPRO (sue me). |
|
| 34 |
+# bundle_binary must be called first. |
|
| 35 |
+bundle_ubuntu() {
|
|
| 36 |
+ DIR=$DEST/build |
|
| 37 |
+ |
|
| 38 |
+ # Generate an upstart config file (ubuntu-specific) |
|
| 39 |
+ mkdir -p $DIR/etc/init |
|
| 40 |
+ echo "$UPSTART_SCRIPT" > $DIR/etc/init/docker.conf |
|
| 41 |
+ |
|
| 42 |
+ # Copy the binary |
|
| 43 |
+ # This will fail if the binary bundle hasn't been built |
|
| 44 |
+ mkdir -p $DIR/usr/bin |
|
| 45 |
+ # Copy the binary |
|
| 46 |
+ # This will fail if the binary bundle hasn't been built |
|
| 47 |
+ cp $DEST/../binary/docker-$VERSION $DIR/usr/bin/docker |
|
| 48 |
+ |
|
| 49 |
+ # Generate postinstall/prerm scripts |
|
| 50 |
+ cat >/tmp/postinstall <<EOF |
|
| 51 |
+#!/bin/sh |
|
| 52 |
+/sbin/stop docker || true |
|
| 53 |
+/sbin/start docker |
|
| 54 |
+EOF |
|
| 55 |
+ cat >/tmp/prerm <<EOF |
|
| 56 |
+#!/bin/sh |
|
| 57 |
+/sbin/stop docker || true |
|
| 58 |
+EOF |
|
| 59 |
+ chmod +x /tmp/postinstall /tmp/prerm |
|
| 60 |
+ |
|
| 61 |
+ ( |
|
| 62 |
+ cd $DEST |
|
| 63 |
+ fpm -s dir -C $DIR \ |
|
| 64 |
+ --name lxc-docker-$VERSION --version $PKGVERSION \ |
|
| 65 |
+ --after-install /tmp/postinstall \ |
|
| 66 |
+ --before-remove /tmp/prerm \ |
|
| 67 |
+ --architecture "$PACKAGE_ARCHITECTURE" \ |
|
| 68 |
+ --prefix / \ |
|
| 69 |
+ --depends lxc --depends aufs-tools \ |
|
| 70 |
+ --description "$PACKAGE_DESCRIPTION" \ |
|
| 71 |
+ --maintainer "$PACKAGE_MAINTAINER" \ |
|
| 72 |
+ --conflicts lxc-docker-virtual-package \ |
|
| 73 |
+ --provides lxc-docker \ |
|
| 74 |
+ --provides lxc-docker-virtual-package \ |
|
| 75 |
+ --replaces lxc-docker \ |
|
| 76 |
+ --replaces lxc-docker-virtual-package \ |
|
| 77 |
+ --url "$PACKAGE_URL" \ |
|
| 78 |
+ --vendor "$PACKAGE_VENDOR" \ |
|
| 79 |
+ -t deb . |
|
| 80 |
+ mkdir empty |
|
| 81 |
+ fpm -s dir -C empty \ |
|
| 82 |
+ --name lxc-docker --version $PKGVERSION \ |
|
| 83 |
+ --architecture "$PACKAGE_ARCHITECTURE" \ |
|
| 84 |
+ --depends lxc-docker-$VERSION \ |
|
| 85 |
+ --description "$PACKAGE_DESCRIPTION" \ |
|
| 86 |
+ --maintainer "$PACKAGE_MAINTAINER" \ |
|
| 87 |
+ --url "$PACKAGE_URL" \ |
|
| 88 |
+ --vendor "$PACKAGE_VENDOR" \ |
|
| 89 |
+ -t deb . |
|
| 90 |
+ ) |
|
| 91 |
+} |
|
| 92 |
+ |
|
| 93 |
+bundle_ubuntu |