Browse code

Hack: improve the Dockerfile for an easier development workflow. Build dev container once, run a shell with source mount-binded, run tests as you edit. LIKE A BOSS.

Solomon Hykes authored on 2013/09/07 12:14:03
Showing 7 changed files
... ...
@@ -16,7 +16,7 @@
16 16
 # -e AWS_ACCESS_KEY=foo \
17 17
 # -e AWS_SECRET_KEY=bar \
18 18
 # -e GPG_PASSPHRASE=gloubiboulga \
19
-# -lxc-conf=lxc.aa_profile=unconfined -privileged docker hack/release/release.sh
19
+# -lxc-conf=lxc.aa_profile=unconfined -privileged docker hack/release.sh
20 20
 # 
21 21
 
22 22
 docker-version 0.6.1
... ...
@@ -52,13 +52,9 @@ run	PKG=github.com/gorilla/context/ REV=708054d61e5; git clone http://$PKG /go/s
52 52
 run	PKG=github.com/gorilla/mux/ REV=9b36453141c;	 git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV
53 53
 run	PKG=github.com/dotcloud/tar/ REV=e5ea6bb21a3294;	 git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV
54 54
 run	PKG=code.google.com/p/go.net/ REV=84a4013f96e0;  hg  clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && hg  checkout    $REV
55
-# Upload docker source
56
-add	.       /go/src/github.com/dotcloud/docker
57
-run	ln -s	/go/src/github.com/dotcloud/docker /src
58 55
 volume	/var/lib/docker
59
-# Build the binary
60
-run	cd /go/src/github.com/dotcloud/docker && hack/release/make.sh
61 56
 workdir	/go/src/github.com/dotcloud/docker
62 57
 # Wrap all commands in the "docker-in-docker" script to allow nested containers
63 58
 entrypoint ["hack/dind"]
64
-cmd	cd /go/src/github.com/dotcloud/docker && hack/release/release.sh
59
+# Upload docker source
60
+add	.       /go/src/github.com/dotcloud/docker
65 61
new file mode 100644
... ...
@@ -0,0 +1,106 @@
0
+## A maintainer's guide to releasing Docker
1
+
2
+So you're in charge of a Docker release? Cool. Here's what to do.
3
+
4
+If your experience deviates from this document, please document the changes
5
+to keep it up-to-date.
6
+
7
+
8
+### 1. Pull from master and create a release branch
9
+
10
+```bash
11
+git checkout master
12
+git pull
13
+git checkout -b bump_$VERSION
14
+```
15
+
16
+### 2. Update CHANGELOG.md
17
+
18
+You can run this command for reference:
19
+
20
+```bash
21
+LAST_VERSION=$(git tag | grep -E "v[0-9\.]+$" | sort -nr | head -n 1)
22
+git log $LAST_VERSION..HEAD
23
+```
24
+
25
+Each change should be formatted as ```BULLET CATEGORY: DESCRIPTION```
26
+
27
+* BULLET is either ```-```, ```+``` or ```*```, to indicate a bugfix,
28
+  new feature or upgrade, respectively.
29
+
30
+* CATEGORY should describe which part of the project is affected.
31
+  Valid categories are:
32
+  * Builder
33
+  * Documentation
34
+  * Hack
35
+  * Packaging
36
+  * Remote API
37
+  * Runtime
38
+
39
+* DESCRIPTION: a concise description of the change that is relevant to the 
40
+  end-user, using the present tense. Changes should be described in terms 
41
+  of how they affect the user, for example "new feature X which allows Y", 
42
+  "fixed bug which caused X", "increased performance of Y".
43
+
44
+EXAMPLES:
45
+
46
+```
47
++ Builder: 'docker build -t FOO' applies the tag FOO to the newly built
48
+  container.
49
+* Runtime: improve detection of kernel version
50
+- Remote API: fix a bug in the optional unix socket transport
51
+```
52
+
53
+### 3. Change the contents of the VERSION file
54
+
55
+### 4. Run all tests
56
+
57
+```bash
58
+go test
59
+```
60
+
61
+### 5. Commit and create a pull request
62
+
63
+```bash
64
+git add CHANGELOG.md
65
+git commit -m "Bump version to $VERSION"
66
+git push origin bump_$VERSION
67
+```
68
+
69
+### 6. Get 2 other maintainers to validate the pull request
70
+
71
+### 7. Merge the pull request and apply tags
72
+
73
+```bash
74
+git checkout master
75
+git merge bump_$VERSION
76
+git tag -a v$VERSION # Don't forget the v!
77
+git tag -f -a latest
78
+git push
79
+git push --tags
80
+```
81
+
82
+### 8. Publish binaries
83
+
84
+To run this you will need access to the release credentials.
85
+Get them from [the infrastructure maintainers](
86
+https://github.com/dotcloud/docker/blob/master/hack/infrastructure/MAINTAINERS).
87
+
88
+```bash
89
+docker build -t releasedocker .
90
+docker run  \
91
+	-e AWS_S3_BUCKET=get-nightly.docker.io \
92
+	-e AWS_ACCESS_KEY=$(cat ~/.aws/access_key) \
93
+	-e AWS_SECRET_KEY=$(cat ~/.aws/secret_key) \
94
+	-e GPG_PASSPHRASE=supersecretsesame \
95
+	releasedocker
96
+```
97
+
98
+It will build and upload the binaries on the specified bucket (you should
99
+use get-nightly.docker.io for general testing, and once everything is fine,
100
+switch to get.docker.io).
101
+
102
+
103
+### 9. Rejoice!
104
+
105
+Congratulations! You're done.
0 106
new file mode 100755
... ...
@@ -0,0 +1,179 @@
0
+#!/bin/sh
1
+
2
+# This script builds various binary artifacts from a checkout of the docker
3
+# source code.
4
+#
5
+# Requirements:
6
+# - The current directory should be a checkout of the docker source code
7
+#   (http://github.com/dotcloud/docker). Whatever version is checked out
8
+#   will be built.
9
+# - The VERSION file, at the root of the repository, should exist, and
10
+#   will be used as Docker binary version and package version.
11
+# - The hash of the git commit will also be included in the Docker binary,
12
+#   with the suffix -dirty if the repository isn't clean.
13
+# - The script is intented to be run as part of a docker build, as defined
14
+#   in the Dockerfile at the root of the source. In other words:
15
+#   DO NOT CALL THIS SCRIPT DIRECTLY.
16
+# - The right way to call this script is to invoke "docker build ." from
17
+#   your checkout of the Docker repository.
18
+# 
19
+
20
+set -e
21
+
22
+# We're a nice, sexy, little shell script, and people might try to run us;
23
+# but really, they shouldn't. We want to be in a container!
24
+RESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
25
+grep -q "$RESOLVCONF" /proc/mounts || {
26
+	echo "# I will only run within a container."
27
+	echo "# Try this instead:"
28
+	echo "docker build ."
29
+	exit 1
30
+}
31
+
32
+VERSION=$(cat ./VERSION)
33
+PKGVERSION="$VERSION"
34
+GITCOMMIT=$(git rev-parse --short HEAD)
35
+if test -n "$(git status --porcelain)"
36
+then
37
+	GITCOMMIT="$GITCOMMIT-dirty"
38
+	PKGVERSION="$PKGVERSION-$(date +%Y%m%d%H%M%S)-$GITCOMMIT"
39
+fi
40
+
41
+PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)"
42
+PACKAGE_URL="http://www.docker.io/"
43
+PACKAGE_MAINTAINER="docker@dotcloud.com"
44
+PACKAGE_DESCRIPTION="lxc-docker is a Linux container runtime
45
+Docker complements LXC with a high-level API which operates at the process
46
+level. It runs unix processes with strong guarantees of isolation and
47
+repeatability across servers.
48
+Docker is a great building block for automating distributed systems:
49
+large-scale web deployments, database clusters, continuous deployment systems,
50
+private PaaS, service-oriented architectures, etc."
51
+
52
+UPSTART_SCRIPT='description     "Docker daemon"
53
+
54
+start on filesystem and started lxc-net
55
+stop on runlevel [!2345]
56
+
57
+respawn
58
+
59
+script
60
+    /usr/bin/docker -d
61
+end script
62
+'
63
+
64
+# Each "bundle" is a different type of build artefact: static binary, Ubuntu
65
+# package, etc.
66
+
67
+# Build Docker as a static binary file
68
+bundle_binary() {
69
+	mkdir -p bundles/$VERSION/binary
70
+	go build -o bundles/$VERSION/binary/docker-$VERSION \
71
+		-ldflags "-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w" \
72
+		./docker
73
+}
74
+
75
+
76
+# Build Docker's test suite as a collection of binary files (one per
77
+# sub-package to test)
78
+bundle_test() {
79
+	mkdir -p bundles/$VERSION/test
80
+	for test_dir in $(find_test_dirs); do
81
+		test_binary=$(
82
+			cd $test_dir
83
+			go test -c -v -ldflags "-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w" >&2
84
+			find . -maxdepth 1 -type f -name '*.test' -executable
85
+		)
86
+		cp $test_dir/$test_binary bundles/$VERSION/test/
87
+	done
88
+}
89
+
90
+# Build docker as an ubuntu package using FPM and REPREPRO (sue me).
91
+# bundle_binary must be called first.
92
+bundle_ubuntu() {
93
+	mkdir -p bundles/$VERSION/ubuntu
94
+
95
+	DIR=$(pwd)/bundles/$VERSION/ubuntu/build
96
+
97
+	# Generate an upstart config file (ubuntu-specific)
98
+	mkdir -p $DIR/etc/init
99
+	echo "$UPSTART_SCRIPT" > $DIR/etc/init/docker.conf
100
+
101
+	# Copy the binary
102
+	mkdir -p $DIR/usr/bin
103
+	cp bundles/$VERSION/binary/docker-$VERSION $DIR/usr/bin/docker
104
+
105
+	# Generate postinstall/prerm scripts
106
+	cat >/tmp/postinstall <<EOF
107
+#!/bin/sh
108
+/sbin/stop docker || true
109
+/sbin/start docker
110
+EOF
111
+	cat >/tmp/prerm <<EOF
112
+#!/bin/sh
113
+/sbin/stop docker || true
114
+EOF
115
+	chmod +x /tmp/postinstall /tmp/prerm
116
+
117
+	(
118
+		cd bundles/$VERSION/ubuntu
119
+		fpm -s dir -C $DIR \
120
+		    --name lxc-docker-$VERSION --version $PKGVERSION \
121
+		    --after-install /tmp/postinstall \
122
+		    --before-remove /tmp/prerm \
123
+		    --architecture "$PACKAGE_ARCHITECTURE" \
124
+		    --prefix / \
125
+		    --depends lxc --depends aufs-tools \
126
+		    --description "$PACKAGE_DESCRIPTION" \
127
+		    --maintainer "$PACKAGE_MAINTAINER" \
128
+		    --conflicts lxc-docker-virtual-package \
129
+		    --provides lxc-docker \
130
+		    --provides lxc-docker-virtual-package \
131
+		    --replaces lxc-docker \
132
+		    --replaces lxc-docker-virtual-package \
133
+		    --url "$PACKAGE_URL" \
134
+		    --vendor "$PACKAGE_VENDOR" \
135
+		    -t deb .
136
+		mkdir empty
137
+		fpm -s dir -C empty \
138
+		    --name lxc-docker --version $PKGVERSION \
139
+		    --architecture "$PACKAGE_ARCHITECTURE" \
140
+		    --depends lxc-docker-$VERSION \
141
+		    --description "$PACKAGE_DESCRIPTION" \
142
+		    --maintainer "$PACKAGE_MAINTAINER" \
143
+		    --url "$PACKAGE_URL" \
144
+		    --vendor "$PACKAGE_VENDOR" \
145
+		    -t deb .
146
+	)
147
+}
148
+
149
+
150
+# This helper function walks the current directory looking for directories
151
+# holding Go test files, and prints their paths on standard output, one per
152
+# line.
153
+find_test_dirs() {
154
+	find . -name '*_test.go' | 
155
+		{ while read f; do dirname $f; done; } | 
156
+		sort -u
157
+}
158
+
159
+
160
+main() {
161
+	bundle_binary
162
+	bundle_ubuntu
163
+	#bundle_test
164
+	cat <<EOF
165
+###############################################################################
166
+Now run the resulting image, making sure that you set AWS_S3_BUCKET,
167
+AWS_ACCESS_KEY, and AWS_SECRET_KEY environment variables:
168
+
169
+docker run -e AWS_S3_BUCKET=get-staging.docker.io \\
170
+              AWS_ACCESS_KEY=AKI1234... \\
171
+              AWS_SECRET_KEY=sEs3mE... \\
172
+              GPG_PASSPHRASE=sesame... \\
173
+              image_id_or_name
174
+###############################################################################
175
+EOF
176
+}
177
+
178
+main
0 179
new file mode 100755
... ...
@@ -0,0 +1,175 @@
0
+#!/bin/sh
1
+
2
+# This script looks for bundles built by make.sh, and releases them on a
3
+# public S3 bucket.
4
+#
5
+# Bundles should be available for the VERSION string passed as argument.
6
+#
7
+# The correct way to call this script is inside a container built by the
8
+# official Dockerfile at the root of the Docker source code. The Dockerfile,
9
+# make.sh and release.sh should all be from the same source code revision.
10
+
11
+set -e
12
+
13
+# Print a usage message and exit.
14
+usage() {
15
+	cat <<EOF
16
+To run, I need:
17
+- to be in a container generated by the Dockerfile at the top of the Docker
18
+  repository;
19
+- to be provided with the name of an S3 bucket, in environment variable
20
+  AWS_S3_BUCKET;
21
+- to be provided with AWS credentials for this S3 bucket, in environment
22
+  variables AWS_ACCESS_KEY and AWS_SECRET_KEY;
23
+- the passphrase to unlock the GPG key which will sign the deb packages
24
+  (passed as environment variable GPG_PASSPHRASE);
25
+- a generous amount of good will and nice manners.
26
+The canonical way to run me is to run the image produced by the Dockerfile: e.g.:"
27
+
28
+docker run -e AWS_S3_BUCKET=get-staging.docker.io \\
29
+              AWS_ACCESS_KEY=AKI1234... \\
30
+              AWS_SECRET_KEY=sEs4mE... \\
31
+              GPG_PASSPHRASE=m0resEs4mE... \\
32
+              f0058411
33
+EOF
34
+	exit 1
35
+}
36
+
37
+[ "$AWS_S3_BUCKET" ] || usage
38
+[ "$AWS_ACCESS_KEY" ] || usage
39
+[ "$AWS_SECRET_KEY" ] || usage
40
+[ "$GPG_PASSPHRASE" ] || usage
41
+[ -d /go/src/github.com/dotcloud/docker/ ] || usage
42
+cd /go/src/github.com/dotcloud/docker/ 
43
+
44
+VERSION=$(cat VERSION)
45
+BUCKET=$AWS_S3_BUCKET
46
+
47
+setup_s3() {
48
+	# Try creating the bucket. Ignore errors (it might already exist).
49
+	s3cmd mb s3://$BUCKET 2>/dev/null || true
50
+	# Check access to the bucket.
51
+	# s3cmd has no useful exit status, so we cannot check that.
52
+	# Instead, we check if it outputs anything on standard output.
53
+	# (When there are problems, it uses standard error instead.)
54
+	s3cmd info s3://$BUCKET | grep -q .
55
+	# Make the bucket accessible through website endpoints.
56
+	s3cmd ws-create --ws-index index --ws-error error s3://$BUCKET
57
+}
58
+
59
+# write_to_s3 uploads the contents of standard input to the specified S3 url.
60
+write_to_s3() {
61
+	DEST=$1
62
+	F=`mktemp`
63
+	cat > $F
64
+	s3cmd --acl-public put $F $DEST
65
+	rm -f $F
66
+}
67
+
68
+s3_url() {
69
+	echo "http://$BUCKET.s3.amazonaws.com"
70
+}
71
+
72
+# Upload the 'ubuntu' bundle to S3:
73
+# 1. A full APT repository is published at $BUCKET/ubuntu/
74
+# 2. Instructions for using the APT repository are uploaded at $BUCKET/ubuntu/info
75
+release_ubuntu() {
76
+	# Make sure that we have our keys
77
+	mkdir -p /.gnupg/
78
+	s3cmd sync s3://$BUCKET/ubuntu/.gnupg/ /.gnupg/ || true
79
+	gpg --list-keys releasedocker >/dev/null || {
80
+		gpg --gen-key --batch <<EOF   
81
+Key-Type: RSA
82
+Key-Length: 2048
83
+Passphrase: $GPG_PASSPHRASE
84
+Name-Real: Docker Release Tool
85
+Name-Email: docker@dotcloud.com
86
+Name-Comment: releasedocker
87
+Expire-Date: 0
88
+%commit
89
+EOF
90
+	}
91
+
92
+	# Sign our packages
93
+	dpkg-sig -g "--passphrase $GPG_PASSPHRASE" -k releasedocker \
94
+		 --sign builder bundles/$VERSION/ubuntu/*.deb
95
+
96
+	# Setup the APT repo
97
+	APTDIR=bundles/$VERSION/ubuntu/apt
98
+	mkdir -p $APTDIR/conf $APTDIR/db
99
+	s3cmd sync s3://$BUCKET/ubuntu/db/ $APTDIR/db/ || true
100
+	cat > $APTDIR/conf/distributions <<EOF
101
+Codename: docker
102
+Components: main
103
+Architectures: amd64 i386
104
+EOF
105
+
106
+	# Add the DEB package to the APT repo
107
+	DEBFILE=bundles/$VERSION/ubuntu/lxc-docker*.deb
108
+	reprepro -b $APTDIR includedeb docker $DEBFILE
109
+
110
+	# Sign
111
+	for F in $(find $APTDIR -name Release)
112
+	do
113
+		gpg -u releasedocker --passphrase $GPG_PASSPHRASE \
114
+			--armor --sign --detach-sign \
115
+			--output $F.gpg $F
116
+	done
117
+
118
+	# Upload keys
119
+	s3cmd sync /.gnupg/ s3://$BUCKET/ubuntu/.gnupg/
120
+	gpg --armor --export releasedocker > bundles/$VERSION/ubuntu/gpg
121
+	s3cmd --acl-public put bundles/$VERSION/ubuntu/gpg s3://$BUCKET/gpg
122
+
123
+	# Upload repo
124
+	s3cmd --acl-public sync $APTDIR/ s3://$BUCKET/ubuntu/
125
+	cat <<EOF | write_to_s3 s3://$BUCKET/ubuntu/info
126
+# Add the repository to your APT sources
127
+echo deb $(s3_url $BUCKET)/ubuntu docker main > /etc/apt/sources.list.d/docker.list
128
+# Then import the repository key
129
+curl $(s3_url $BUCKET)/gpg | apt-key add -
130
+# Install docker
131
+apt-get update ; apt-get install -y lxc-docker
132
+EOF
133
+	echo "APT repository uploaded. Instructions available at $(s3_url $BUCKET)/ubuntu/info"
134
+}
135
+
136
+# Upload a static binary to S3
137
+release_binary() {
138
+	[ -e bundles/$VERSION ]
139
+	S3DIR=s3://$BUCKET/builds/Linux/x86_64
140
+	s3cmd --acl-public put bundles/$VERSION/binary/docker-$VERSION $S3DIR/docker-$VERSION
141
+	cat <<EOF | write_to_s3 s3://$BUCKET/builds/info
142
+# To install, run the following command as root:
143
+curl -O http://$BUCKET.s3.amazonaws.com/builds/Linux/x86_64/docker-$VERSION && chmod +x docker-$VERSION && sudo mv docker-$VERSION /usr/local/bin/docker
144
+# Then start docker in daemon mode:
145
+sudo /usr/local/bin/docker -d
146
+EOF
147
+	if [ -z "$NOLATEST" ]; then
148
+		echo "Copying docker-$VERSION to docker-latest"
149
+		s3cmd --acl-public cp $S3DIR/docker-$VERSION $S3DIR/docker-latest
150
+		echo "Advertising $VERSION on $BUCKET as most recent version"
151
+		echo $VERSION | write_to_s3 s3://$BUCKET/latest
152
+	fi
153
+}
154
+
155
+# Upload the index script
156
+release_index() {
157
+	(
158
+	if [ "$BUCKET" != "get.docker.io" ]
159
+	then
160
+		sed s,https://get.docker.io/,http://$BUCKET.s3.amazonaws.com/, contrib/install.sh
161
+	else
162
+		cat contrib/install.sh
163
+	fi
164
+	) | write_to_s3 s3://$BUCKET/index
165
+}
166
+
167
+main() {
168
+	setup_s3
169
+	release_binary
170
+	release_ubuntu
171
+	release_index
172
+}
173
+
174
+main
0 175
deleted file mode 100644
... ...
@@ -1,106 +0,0 @@
1
-## A maintainer's guide to releasing Docker
2
-
3
-So you're in charge of a Docker release? Cool. Here's what to do.
4
-
5
-If your experience deviates from this document, please document the changes
6
-to keep it up-to-date.
7
-
8
-
9
-### 1. Pull from master and create a release branch
10
-
11
-```bash
12
-git checkout master
13
-git pull
14
-git checkout -b bump_$VERSION
15
-```
16
-
17
-### 2. Update CHANGELOG.md
18
-
19
-You can run this command for reference:
20
-
21
-```bash
22
-LAST_VERSION=$(git tag | grep -E "v[0-9\.]+$" | sort -nr | head -n 1)
23
-git log $LAST_VERSION..HEAD
24
-```
25
-
26
-Each change should be formatted as ```BULLET CATEGORY: DESCRIPTION```
27
-
28
-* BULLET is either ```-```, ```+``` or ```*```, to indicate a bugfix,
29
-  new feature or upgrade, respectively.
30
-
31
-* CATEGORY should describe which part of the project is affected.
32
-  Valid categories are:
33
-  * Builder
34
-  * Documentation
35
-  * Hack
36
-  * Packaging
37
-  * Remote API
38
-  * Runtime
39
-
40
-* DESCRIPTION: a concise description of the change that is relevant to the 
41
-  end-user, using the present tense. Changes should be described in terms 
42
-  of how they affect the user, for example "new feature X which allows Y", 
43
-  "fixed bug which caused X", "increased performance of Y".
44
-
45
-EXAMPLES:
46
-
47
-```
48
-+ Builder: 'docker build -t FOO' applies the tag FOO to the newly built
49
-  container.
50
-* Runtime: improve detection of kernel version
51
-- Remote API: fix a bug in the optional unix socket transport
52
-```
53
-
54
-### 3. Change the contents of the VERSION file
55
-
56
-### 4. Run all tests
57
-
58
-```bash
59
-go test
60
-```
61
-
62
-### 5. Commit and create a pull request
63
-
64
-```bash
65
-git add CHANGELOG.md
66
-git commit -m "Bump version to $VERSION"
67
-git push origin bump_$VERSION
68
-```
69
-
70
-### 6. Get 2 other maintainers to validate the pull request
71
-
72
-### 7. Merge the pull request and apply tags
73
-
74
-```bash
75
-git checkout master
76
-git merge bump_$VERSION
77
-git tag -a v$VERSION # Don't forget the v!
78
-git tag -f -a latest
79
-git push
80
-git push --tags
81
-```
82
-
83
-### 8. Publish binaries
84
-
85
-To run this you will need access to the release credentials.
86
-Get them from [the infrastructure maintainers](
87
-https://github.com/dotcloud/docker/blob/master/hack/infrastructure/MAINTAINERS).
88
-
89
-```bash
90
-docker build -t releasedocker .
91
-docker run  \
92
-	-e AWS_S3_BUCKET=get-nightly.docker.io \
93
-	-e AWS_ACCESS_KEY=$(cat ~/.aws/access_key) \
94
-	-e AWS_SECRET_KEY=$(cat ~/.aws/secret_key) \
95
-	-e GPG_PASSPHRASE=supersecretsesame \
96
-	releasedocker
97
-```
98
-
99
-It will build and upload the binaries on the specified bucket (you should
100
-use get-nightly.docker.io for general testing, and once everything is fine,
101
-switch to get.docker.io).
102
-
103
-
104
-### 9. Rejoice!
105
-
106
-Congratulations! You're done.
107 1
deleted file mode 100755
... ...
@@ -1,179 +0,0 @@
1
-#!/bin/sh
2
-
3
-# This script builds various binary artifacts from a checkout of the docker
4
-# source code.
5
-#
6
-# Requirements:
7
-# - The current directory should be a checkout of the docker source code
8
-#   (http://github.com/dotcloud/docker). Whatever version is checked out
9
-#   will be built.
10
-# - The VERSION file, at the root of the repository, should exist, and
11
-#   will be used as Docker binary version and package version.
12
-# - The hash of the git commit will also be included in the Docker binary,
13
-#   with the suffix -dirty if the repository isn't clean.
14
-# - The script is intented to be run as part of a docker build, as defined
15
-#   in the Dockerfile at the root of the source. In other words:
16
-#   DO NOT CALL THIS SCRIPT DIRECTLY.
17
-# - The right way to call this script is to invoke "docker build ." from
18
-#   your checkout of the Docker repository.
19
-# 
20
-
21
-set -e
22
-
23
-# We're a nice, sexy, little shell script, and people might try to run us;
24
-# but really, they shouldn't. We want to be in a container!
25
-RESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
26
-grep -q "$RESOLVCONF" /proc/mounts || {
27
-	echo "# I will only run within a container."
28
-	echo "# Try this instead:"
29
-	echo "docker build ."
30
-	exit 1
31
-}
32
-
33
-VERSION=$(cat ./VERSION)
34
-PKGVERSION="$VERSION"
35
-GITCOMMIT=$(git rev-parse --short HEAD)
36
-if test -n "$(git status --porcelain)"
37
-then
38
-	GITCOMMIT="$GITCOMMIT-dirty"
39
-	PKGVERSION="$PKGVERSION-$(date +%Y%m%d%H%M%S)-$GITCOMMIT"
40
-fi
41
-
42
-PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)"
43
-PACKAGE_URL="http://www.docker.io/"
44
-PACKAGE_MAINTAINER="docker@dotcloud.com"
45
-PACKAGE_DESCRIPTION="lxc-docker is a Linux container runtime
46
-Docker complements LXC with a high-level API which operates at the process
47
-level. It runs unix processes with strong guarantees of isolation and
48
-repeatability across servers.
49
-Docker is a great building block for automating distributed systems:
50
-large-scale web deployments, database clusters, continuous deployment systems,
51
-private PaaS, service-oriented architectures, etc."
52
-
53
-UPSTART_SCRIPT='description     "Docker daemon"
54
-
55
-start on filesystem and started lxc-net
56
-stop on runlevel [!2345]
57
-
58
-respawn
59
-
60
-script
61
-    /usr/bin/docker -d
62
-end script
63
-'
64
-
65
-# Each "bundle" is a different type of build artefact: static binary, Ubuntu
66
-# package, etc.
67
-
68
-# Build Docker as a static binary file
69
-bundle_binary() {
70
-	mkdir -p bundles/$VERSION/binary
71
-	go build -o bundles/$VERSION/binary/docker-$VERSION \
72
-		-ldflags "-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w" \
73
-		./docker
74
-}
75
-
76
-
77
-# Build Docker's test suite as a collection of binary files (one per
78
-# sub-package to test)
79
-bundle_test() {
80
-	mkdir -p bundles/$VERSION/test
81
-	for test_dir in $(find_test_dirs); do
82
-		test_binary=$(
83
-			cd $test_dir
84
-			go test -c -v -ldflags "-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w" >&2
85
-			find . -maxdepth 1 -type f -name '*.test' -executable
86
-		)
87
-		cp $test_dir/$test_binary bundles/$VERSION/test/
88
-	done
89
-}
90
-
91
-# Build docker as an ubuntu package using FPM and REPREPRO (sue me).
92
-# bundle_binary must be called first.
93
-bundle_ubuntu() {
94
-	mkdir -p bundles/$VERSION/ubuntu
95
-
96
-	DIR=$(pwd)/bundles/$VERSION/ubuntu/build
97
-
98
-	# Generate an upstart config file (ubuntu-specific)
99
-	mkdir -p $DIR/etc/init
100
-	echo "$UPSTART_SCRIPT" > $DIR/etc/init/docker.conf
101
-
102
-	# Copy the binary
103
-	mkdir -p $DIR/usr/bin
104
-	cp bundles/$VERSION/binary/docker-$VERSION $DIR/usr/bin/docker
105
-
106
-	# Generate postinstall/prerm scripts
107
-	cat >/tmp/postinstall <<EOF
108
-#!/bin/sh
109
-/sbin/stop docker || true
110
-/sbin/start docker
111
-EOF
112
-	cat >/tmp/prerm <<EOF
113
-#!/bin/sh
114
-/sbin/stop docker || true
115
-EOF
116
-	chmod +x /tmp/postinstall /tmp/prerm
117
-
118
-	(
119
-		cd bundles/$VERSION/ubuntu
120
-		fpm -s dir -C $DIR \
121
-		    --name lxc-docker-$VERSION --version $PKGVERSION \
122
-		    --after-install /tmp/postinstall \
123
-		    --before-remove /tmp/prerm \
124
-		    --architecture "$PACKAGE_ARCHITECTURE" \
125
-		    --prefix / \
126
-		    --depends lxc --depends aufs-tools \
127
-		    --description "$PACKAGE_DESCRIPTION" \
128
-		    --maintainer "$PACKAGE_MAINTAINER" \
129
-		    --conflicts lxc-docker-virtual-package \
130
-		    --provides lxc-docker \
131
-		    --provides lxc-docker-virtual-package \
132
-		    --replaces lxc-docker \
133
-		    --replaces lxc-docker-virtual-package \
134
-		    --url "$PACKAGE_URL" \
135
-		    --vendor "$PACKAGE_VENDOR" \
136
-		    -t deb .
137
-		mkdir empty
138
-		fpm -s dir -C empty \
139
-		    --name lxc-docker --version $PKGVERSION \
140
-		    --architecture "$PACKAGE_ARCHITECTURE" \
141
-		    --depends lxc-docker-$VERSION \
142
-		    --description "$PACKAGE_DESCRIPTION" \
143
-		    --maintainer "$PACKAGE_MAINTAINER" \
144
-		    --url "$PACKAGE_URL" \
145
-		    --vendor "$PACKAGE_VENDOR" \
146
-		    -t deb .
147
-	)
148
-}
149
-
150
-
151
-# This helper function walks the current directory looking for directories
152
-# holding Go test files, and prints their paths on standard output, one per
153
-# line.
154
-find_test_dirs() {
155
-	find . -name '*_test.go' | 
156
-		{ while read f; do dirname $f; done; } | 
157
-		sort -u
158
-}
159
-
160
-
161
-main() {
162
-	bundle_binary
163
-	bundle_ubuntu
164
-	#bundle_test
165
-	cat <<EOF
166
-###############################################################################
167
-Now run the resulting image, making sure that you set AWS_S3_BUCKET,
168
-AWS_ACCESS_KEY, and AWS_SECRET_KEY environment variables:
169
-
170
-docker run -e AWS_S3_BUCKET=get-staging.docker.io \\
171
-              AWS_ACCESS_KEY=AKI1234... \\
172
-              AWS_SECRET_KEY=sEs3mE... \\
173
-              GPG_PASSPHRASE=sesame... \\
174
-              image_id_or_name
175
-###############################################################################
176
-EOF
177
-}
178
-
179
-main
180 1
deleted file mode 100755
... ...
@@ -1,175 +0,0 @@
1
-#!/bin/sh
2
-
3
-# This script looks for bundles built by make.sh, and releases them on a
4
-# public S3 bucket.
5
-#
6
-# Bundles should be available for the VERSION string passed as argument.
7
-#
8
-# The correct way to call this script is inside a container built by the
9
-# official Dockerfile at the root of the Docker source code. The Dockerfile,
10
-# make.sh and release.sh should all be from the same source code revision.
11
-
12
-set -e
13
-
14
-# Print a usage message and exit.
15
-usage() {
16
-	cat <<EOF
17
-To run, I need:
18
-- to be in a container generated by the Dockerfile at the top of the Docker
19
-  repository;
20
-- to be provided with the name of an S3 bucket, in environment variable
21
-  AWS_S3_BUCKET;
22
-- to be provided with AWS credentials for this S3 bucket, in environment
23
-  variables AWS_ACCESS_KEY and AWS_SECRET_KEY;
24
-- the passphrase to unlock the GPG key which will sign the deb packages
25
-  (passed as environment variable GPG_PASSPHRASE);
26
-- a generous amount of good will and nice manners.
27
-The canonical way to run me is to run the image produced by the Dockerfile: e.g.:"
28
-
29
-docker run -e AWS_S3_BUCKET=get-staging.docker.io \\
30
-              AWS_ACCESS_KEY=AKI1234... \\
31
-              AWS_SECRET_KEY=sEs4mE... \\
32
-              GPG_PASSPHRASE=m0resEs4mE... \\
33
-              f0058411
34
-EOF
35
-	exit 1
36
-}
37
-
38
-[ "$AWS_S3_BUCKET" ] || usage
39
-[ "$AWS_ACCESS_KEY" ] || usage
40
-[ "$AWS_SECRET_KEY" ] || usage
41
-[ "$GPG_PASSPHRASE" ] || usage
42
-[ -d /go/src/github.com/dotcloud/docker/ ] || usage
43
-cd /go/src/github.com/dotcloud/docker/ 
44
-
45
-VERSION=$(cat VERSION)
46
-BUCKET=$AWS_S3_BUCKET
47
-
48
-setup_s3() {
49
-	# Try creating the bucket. Ignore errors (it might already exist).
50
-	s3cmd mb s3://$BUCKET 2>/dev/null || true
51
-	# Check access to the bucket.
52
-	# s3cmd has no useful exit status, so we cannot check that.
53
-	# Instead, we check if it outputs anything on standard output.
54
-	# (When there are problems, it uses standard error instead.)
55
-	s3cmd info s3://$BUCKET | grep -q .
56
-	# Make the bucket accessible through website endpoints.
57
-	s3cmd ws-create --ws-index index --ws-error error s3://$BUCKET
58
-}
59
-
60
-# write_to_s3 uploads the contents of standard input to the specified S3 url.
61
-write_to_s3() {
62
-	DEST=$1
63
-	F=`mktemp`
64
-	cat > $F
65
-	s3cmd --acl-public put $F $DEST
66
-	rm -f $F
67
-}
68
-
69
-s3_url() {
70
-	echo "http://$BUCKET.s3.amazonaws.com"
71
-}
72
-
73
-# Upload the 'ubuntu' bundle to S3:
74
-# 1. A full APT repository is published at $BUCKET/ubuntu/
75
-# 2. Instructions for using the APT repository are uploaded at $BUCKET/ubuntu/info
76
-release_ubuntu() {
77
-	# Make sure that we have our keys
78
-	mkdir -p /.gnupg/
79
-	s3cmd sync s3://$BUCKET/ubuntu/.gnupg/ /.gnupg/ || true
80
-	gpg --list-keys releasedocker >/dev/null || {
81
-		gpg --gen-key --batch <<EOF   
82
-Key-Type: RSA
83
-Key-Length: 2048
84
-Passphrase: $GPG_PASSPHRASE
85
-Name-Real: Docker Release Tool
86
-Name-Email: docker@dotcloud.com
87
-Name-Comment: releasedocker
88
-Expire-Date: 0
89
-%commit
90
-EOF
91
-	}
92
-
93
-	# Sign our packages
94
-	dpkg-sig -g "--passphrase $GPG_PASSPHRASE" -k releasedocker \
95
-		 --sign builder bundles/$VERSION/ubuntu/*.deb
96
-
97
-	# Setup the APT repo
98
-	APTDIR=bundles/$VERSION/ubuntu/apt
99
-	mkdir -p $APTDIR/conf $APTDIR/db
100
-	s3cmd sync s3://$BUCKET/ubuntu/db/ $APTDIR/db/ || true
101
-	cat > $APTDIR/conf/distributions <<EOF
102
-Codename: docker
103
-Components: main
104
-Architectures: amd64 i386
105
-EOF
106
-
107
-	# Add the DEB package to the APT repo
108
-	DEBFILE=bundles/$VERSION/ubuntu/lxc-docker*.deb
109
-	reprepro -b $APTDIR includedeb docker $DEBFILE
110
-
111
-	# Sign
112
-	for F in $(find $APTDIR -name Release)
113
-	do
114
-		gpg -u releasedocker --passphrase $GPG_PASSPHRASE \
115
-			--armor --sign --detach-sign \
116
-			--output $F.gpg $F
117
-	done
118
-
119
-	# Upload keys
120
-	s3cmd sync /.gnupg/ s3://$BUCKET/ubuntu/.gnupg/
121
-	gpg --armor --export releasedocker > bundles/$VERSION/ubuntu/gpg
122
-	s3cmd --acl-public put bundles/$VERSION/ubuntu/gpg s3://$BUCKET/gpg
123
-
124
-	# Upload repo
125
-	s3cmd --acl-public sync $APTDIR/ s3://$BUCKET/ubuntu/
126
-	cat <<EOF | write_to_s3 s3://$BUCKET/ubuntu/info
127
-# Add the repository to your APT sources
128
-echo deb $(s3_url $BUCKET)/ubuntu docker main > /etc/apt/sources.list.d/docker.list
129
-# Then import the repository key
130
-curl $(s3_url $BUCKET)/gpg | apt-key add -
131
-# Install docker
132
-apt-get update ; apt-get install -y lxc-docker
133
-EOF
134
-	echo "APT repository uploaded. Instructions available at $(s3_url $BUCKET)/ubuntu/info"
135
-}
136
-
137
-# Upload a static binary to S3
138
-release_binary() {
139
-	[ -e bundles/$VERSION ]
140
-	S3DIR=s3://$BUCKET/builds/Linux/x86_64
141
-	s3cmd --acl-public put bundles/$VERSION/binary/docker-$VERSION $S3DIR/docker-$VERSION
142
-	cat <<EOF | write_to_s3 s3://$BUCKET/builds/info
143
-# To install, run the following command as root:
144
-curl -O http://$BUCKET.s3.amazonaws.com/builds/Linux/x86_64/docker-$VERSION && chmod +x docker-$VERSION && sudo mv docker-$VERSION /usr/local/bin/docker
145
-# Then start docker in daemon mode:
146
-sudo /usr/local/bin/docker -d
147
-EOF
148
-	if [ -z "$NOLATEST" ]; then
149
-		echo "Copying docker-$VERSION to docker-latest"
150
-		s3cmd --acl-public cp $S3DIR/docker-$VERSION $S3DIR/docker-latest
151
-		echo "Advertising $VERSION on $BUCKET as most recent version"
152
-		echo $VERSION | write_to_s3 s3://$BUCKET/latest
153
-	fi
154
-}
155
-
156
-# Upload the index script
157
-release_index() {
158
-	(
159
-	if [ "$BUCKET" != "get.docker.io" ]
160
-	then
161
-		sed s,https://get.docker.io/,http://$BUCKET.s3.amazonaws.com/, contrib/install.sh
162
-	else
163
-		cat contrib/install.sh
164
-	fi
165
-	) | write_to_s3 s3://$BUCKET/index
166
-}
167
-
168
-main() {
169
-	setup_s3
170
-	release_binary
171
-	release_ubuntu
172
-	release_index
173
-}
174
-
175
-main