cloud/docker/release: expand release scripts to build exp/cmd/browser

Now that we want people to try the browser, expand the release scripts
to make it possible to build exp.upspin.io/cmd/browser and distrubute it
through release@upspin.io.

Change-Id: Idccb9b21cc9b2d16d069c00863cf0de6b312743e
Reviewed-on: https://upspin-review.googlesource.com/13181
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/cloud/docker/release/README b/cloud/docker/release/README
index 93bd80d..37f75d9 100644
--- a/cloud/docker/release/README
+++ b/cloud/docker/release/README
@@ -14,6 +14,10 @@
    c. Writes the resulting binaries to the release@upspin.io Upspin tree,
    d. Updates the links inside release@upspin.io/latest.
 
+How it works for non-core repositories (exp.upspin.io, for example)
+
+The same as the above, but step 4d is not performed.
+
 Setting it up
 
 This document assumes you have permissions to work with the 'upspin-prod'
@@ -25,6 +29,7 @@
 Create a Source Repository named 'upspin' and configure it to mirror
 the contents of the github.com/upspin/upspin repo.
 	https://cloud.google.com/code/develop/repo
+Do the same for 'exp'.
 
 Generate the keys for release@upspin.io from the secret seed and put them in
 the 'gcp.upspin.io/cloud/docker/release/secrets' directory (talk to your fellow
@@ -39,11 +44,11 @@
 Delete the secrets directory, to prevent leakages:
 	$ rm -r secrets
 
-Create a trigger that runs the 'release' build step
-on each new commit to the 'upspin' repo:
+Create a trigger that runs the relevant build steps
+on each new commit to the 'upspin' and 'exp' repos:
 	$ ./createtriggers.sh
 
-To test that everything is working, trigger the build manually:
+To test that everything is working, trigger the builds manually:
 	https://cloud.google.com/gcr/triggers
 Once complete, fresh binaries should be visible in the release@upspin.io tree.
 If the build fails, look at the log output of the build for clues:
diff --git a/cloud/docker/release/createtriggers.sh b/cloud/docker/release/createtriggers.sh
index 01066ff..f4f754c 100755
--- a/cloud/docker/release/createtriggers.sh
+++ b/cloud/docker/release/createtriggers.sh
@@ -6,6 +6,8 @@
 
 project=upspin-prod
 auth="$(gcloud config config-helper --format='value(credential.access_token)')"
-sed "s/PROJECT_ID/$project/" trigger.yaml | curl -X POST -T - \
-	-H "Authorization: Bearer $auth" \
-	https://cloudbuild.googleapis.com/v1/projects/$project/triggers
+for trigger in trigger-*.yaml; do
+	sed "s/PROJECT_ID/$project/" $trigger | curl -X POST -T - \
+		-H "Authorization: Bearer $auth" \
+		https://cloudbuild.googleapis.com/v1/projects/$project/triggers
+done
diff --git a/cloud/docker/release/makerelease.sh b/cloud/docker/release/makerelease.sh
index 46c7753..3809b43 100755
--- a/cloud/docker/release/makerelease.sh
+++ b/cloud/docker/release/makerelease.sh
@@ -1,37 +1,72 @@
 #!/bin/bash -e
 
-# This script builds the Upspin commands and pushes them to release@upspin.io.
+# Usage:
+#   $ makerelease.sh <repo-base>
+# where repo-base is one of "upspin.io" or "exp.upspin.io".
+#
+# This script builds Upspin commands for multiple platforms and pushes them to
+# the release@upspin.io Upspin tree.
 # It is executed by the release Docker container.
-# The Docker container provides the Upspin repo in the /workspace directory and
-# sets the environment variable COMMIT_SHA to the current Git commit hash of
-# that repo.
+#
+# The Docker container is run by Google Container Builder, which provides the
+# Git repository (nominated as repo-base) in the /workspace directory and sets
+# the environment variable COMMIT_SHA to the current Git commit hash of that
+# repo.
+#
 # The Docker container is built atop xgo (https://github.com/karalabe/xgo)
 # which is a framework for cross-compiling cgo-enabled binaries. Its magic
-# environment variables are EXT_GOPATH, the location of the Go workspace, and
-# TARGETS, a space-separated list of os/arch combinations.
-
-# The commands to build and distribute.
-# Command "upspin" must be one of these,
-# as it is used to copy the files to release@upspin.io.
-cmds="upspin upspinfs cacheserver"
+# environment variables are:
+#  EXT_GOPATH,	the location of the Go workspace, and
+#  TARGETS,	a space-separated list of os/arch combinations.
 
 # The operating systems and processor architectures to build for.
 oses="darwin linux windows"
 arches="amd64"
 
-# Thet tree that contains the release binaries.
+# The tree that contains the release binaries.
 user="release@upspin.io"
 
-echo 1>&2 "Repo has base path $1"
+# The repository to build for.
+repo="$1"
+
+case "$repo" in
+upspin.io|exp.upspin.io)
+	;;
+*)
+	echo >&2 "must supply upspin.io or exp.upspin.io as first argument"
+	exit 1
+esac
+
+echo 1>&2 "Repo has base path ${repo}"
 export EXT_GOPATH="/gopath"
 mkdir -p $EXT_GOPATH/src
-cp -R /workspace/ $EXT_GOPATH/src/$1
-
+cp -R /workspace/ $EXT_GOPATH/src/$repo
 mkdir /build
 
+# The commands to build and distribute for repo "upspin.io".
+cmds="upspin upspinfs cacheserver"
+
+# For other repos, set cmds appropriately, fetch dependencies,
+# and perform code generation.
+case "$repo" in
+exp.upspin.io)
+	cmds="browser"
+	GOPATH="$EXT_GOPATH" go get -d exp.upspin.io/cmd/browser
+	GOPATH="$EXT_GOPATH" go generate exp.upspin.io/cmd/browser/static
+esac
+
 # Generate the version strings for the commands.
+if [[ "$repo" != "upspin.io" ]]; then
+	GOPATH="$EXT_GOPATH" go get -d upspin.io/cmd/upspin
+fi
 GOPATH="$EXT_GOPATH" go generate -run make_version upspin.io/version
 
+# Build the upspin tool, used to copy the files to release@upspin.io.
+if [[ "$repo" != "upspin.io" ]]; then
+	TARGETS="linux/amd64" $BUILD upspin.io/cmd/upspin
+fi
+
+# Build cmds for oses and arches.
 for cmd in $cmds; do
 	TARGETS=""
 	for GOOS in $oses; do
@@ -45,17 +80,24 @@
 	done
 	echo 1>&2 "Building $cmd for $TARGETS"
 	export TARGETS
-	$BUILD upspin.io/cmd/$cmd
+	$BUILD ${repo}/cmd/$cmd
 done
 
+# Upload the built commands to the release@upspin.io tree.
 function upspin() {
 	/build/upspin-linux-amd64 -config=/config "$@"
 }
-
 for GOOS in $oses; do
 	for GOARCH in $arches; do
 		osarch="${GOOS}_${GOARCH}"
-		destdir="$user/all/$osarch/$COMMIT_SHA"
+		destdir="${user}/all/${osarch}/$COMMIT_SHA"
+
+		# Non-core binaries are not versioned, for now.
+		# Just put them in a directory of their own.
+		if [[ "$repo" != "upspin.io" ]]; then
+			destdir="${user}/${repo}/${osarch}"
+		fi
+
 		for cmd in $cmds; do
 			if [[ $GOOS == "windows" && $cmd == "upspinfs" ]]; then
 				# upspinfs doesn't run on Windows.
@@ -75,9 +117,13 @@
 			upspin mkdir $destdir || echo 1>&2 "mkdir can fail if the directory exists"
 			upspin cp $src $dest
 		done
-		link="$user/latest/$osarch"
-		echo 1>&2 "Linking $link to $destdir"
-		upspin rm $link || echo 1>&2 "rm can fail if the link does not already exist"
-		upspin link $destdir $link
+
+		# For the versioned core binaries, re-link the 'latest' link.
+		if [[ "$repo" == "upspin.io" ]]; then
+			link="$user/latest/$osarch"
+			echo 1>&2 "Linking $link to $destdir"
+			upspin rm $link || echo 1>&2 "rm can fail if the link does not already exist"
+			upspin link $destdir $link
+		fi
 	done
 done
diff --git a/cloud/docker/release/trigger.yaml b/cloud/docker/release/trigger-exp.yaml
similarity index 77%
copy from cloud/docker/release/trigger.yaml
copy to cloud/docker/release/trigger-exp.yaml
index e801363..2b7d53a 100644
--- a/cloud/docker/release/trigger.yaml
+++ b/cloud/docker/release/trigger-exp.yaml
@@ -1,15 +1,15 @@
 {
-        "description": "upspin release",
+        "description": "upspin/exp",
         "triggerTemplate": {
                 "project_id": "PROJECT_ID",
-                "repo_name": "upspin",
+                "repo_name": "exp",
                 "branch_name": "master",
         },
         "build": {
                 "steps": [
                         {
                                 "name": "gcr.io/PROJECT_ID/release",
-                                "args": ["upspin.io"],
+                                "args": ["exp.upspin.io"],
                                 "env": [
                                         "COMMIT_SHA=$COMMIT_SHA",
                                 ],
diff --git a/cloud/docker/release/trigger.yaml b/cloud/docker/release/trigger-upspin.yaml
similarity index 92%
rename from cloud/docker/release/trigger.yaml
rename to cloud/docker/release/trigger-upspin.yaml
index e801363..c764e26 100644
--- a/cloud/docker/release/trigger.yaml
+++ b/cloud/docker/release/trigger-upspin.yaml
@@ -1,5 +1,5 @@
 {
-        "description": "upspin release",
+        "description": "upspin/upspin",
         "triggerTemplate": {
                 "project_id": "PROJECT_ID",
                 "repo_name": "upspin",