From bfc9df4d25816c151a8cc63e62e24f7257a39638 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Fri, 5 Dec 2014 14:04:45 +0000 Subject: [PATCH 01/22] Skeleton of a release script --- bin/release | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 bin/release diff --git a/bin/release b/bin/release new file mode 100755 index 00000000..8f07c2c2 --- /dev/null +++ b/bin/release @@ -0,0 +1,24 @@ +#! /bin/bash + +# Preparation + +## Get the new version number from the most recent tag + +# Sanity checks + +## Check that the version doesn't already exist by looking at github +## releases + +## Check that the top changelog entry is this version + +# Build and test + +# Clone the repo at the tag, inject the version numbers, build +# distributables (library versions?) + +# Run tests with the distributables, including version check + +# Publish + +# Either leave the distributables in a directory for the dev to +# upload, or upload them automatically? From ccf7e9993a1d21108aee87762e0e2328cfd6933a Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Fri, 5 Dec 2014 17:38:22 +0000 Subject: [PATCH 02/22] Add version reporting to weaver --- bin/release | 55 +++++++++++++++++++++++++++++++++++++++++++------- weaver/main.go | 28 ++++++++++++++++--------- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/bin/release b/bin/release index 8f07c2c2..67f92869 100755 --- a/bin/release +++ b/bin/release @@ -1,24 +1,65 @@ #! /bin/bash +set -e +set -o nounset + # Preparation ## Get the new version number from the most recent tag -# Sanity checks +LATEST_TAG=$(git describe --abbrev=0 --match='v*') +VERSION=${LATEST_TAG#v} +echo Attempt to build distributables for version $VERSION +# NB does not check that this tag is on master + +echo +echo == Sanity checks ## Check that the version doesn't already exist by looking at github ## releases +if curl -sSf https://api.github.com/repos/zettio/weave/releases/$LATEST_TAG 2>/dev/null; then + echo Release $LATEST_TAG already exists on GitHub + echo https://github.com/zettio/weave/releases/$LATEST_TAG + exit 1 +fi + +## Clone the repo at the tag and go there +RELEASE_DIR=releases/$LATEST_TAG +mkdir -p releases +git clone -q -b $LATEST_TAG . $RELEASE_DIR +cd $RELEASE_DIR ## Check that the top changelog entry is this version +latest_changelog=$(grep -o "Release v.*" -m1 ./CHANGELOG.md) +if ! [ `echo "$latest_changelog" | grep -o 'v[^ ]*'` == $LATEST_TAG ]; then + echo Latest changelog entry $latest_changelog does not match + echo the latest tag $LATEST_TAG + exit 1 +fi -# Build and test +echo Sanity checks OK for releasing tag $LATEST_TAG -# Clone the repo at the tag, inject the version numbers, build -# distributables (library versions?) +echo +echo == Build and test -# Run tests with the distributables, including version check +## Inject the version numbers and build the distributables +## (library versions?) + +sed -i "/var version = / c\var version = \"$VERSION\"" weaver/main.go +make + +## Run tests with the distributables, including version check +v=$(./weaver/weaver --version) +if ! [ "$v" == "weaver $VERSION" ]; then + echo Version of distributable "$v" does not match tag $LATEST_TAG + exit 1 +fi + +make tests + +echo Build and tests OK # Publish -# Either leave the distributables in a directory for the dev to -# upload, or upload them automatically? +## Either leave the distributables in a directory for the dev to +## upload, or upload them automatically? diff --git a/weaver/main.go b/weaver/main.go index 177f14ba..c28b9bb9 100644 --- a/weaver/main.go +++ b/weaver/main.go @@ -18,6 +18,8 @@ import ( "syscall" ) +var version = "(unreleased version)" + func main() { log.SetPrefix(weave.Protocol + " ") @@ -32,17 +34,19 @@ func main() { runtime.GOMAXPROCS(procs) var ( - ifaceName string - routerName string - password string - wait int - debug bool - prof string - peers []string - connLimit int - bufSz int + justVersion bool + ifaceName string + routerName string + password string + wait int + debug bool + prof string + peers []string + connLimit int + bufSz int ) + flag.BoolVar(&justVersion, "version", false, "print version and exit") flag.StringVar(&ifaceName, "iface", "", "name of interface to read from") flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC)") flag.StringVar(&password, "password", "", "network password") @@ -54,6 +58,11 @@ func main() { flag.Parse() peers = flag.Args() + if justVersion { + io.WriteString(os.Stdout, fmt.Sprintf("weaver %s\n", version)) + os.Exit(0) + } + options := make(map[string]string) flag.Visit(func(f *flag.Flag) { value := f.Value.String() @@ -127,6 +136,7 @@ func main() { func handleHttp(router *weave.Router) { http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, fmt.Sprintln("weaver version", version)) io.WriteString(w, router.Status()) }) http.HandleFunc("/connect", func(w http.ResponseWriter, r *http.Request) { From ab4aa21ccac5c04276643a2d784683520bcfceb9 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Thu, 18 Dec 2014 18:18:41 +0000 Subject: [PATCH 03/22] Up to the point of making a git release (under my own account for the minute) --- bin/release | 146 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 46 deletions(-) diff --git a/bin/release b/bin/release index 67f92869..007ac51b 100755 --- a/bin/release +++ b/bin/release @@ -1,65 +1,119 @@ #! /bin/bash set -e -set -o nounset -# Preparation +PWD=`pwd` +GITHUB_USER=squaremo +RELEASE_NAME="Weave" +RELEASE_DESCRIPTION="Weaving Containers into Applications" -## Get the new version number from the most recent tag +setup() { + ## Get the new version number from the most recent tag + LATEST_TAG=$(git describe --abbrev=0 --match='v*') + VERSION=${LATEST_TAG#v} + # NB does not check that this tag is on master + RELEASE_DIR=./releases/$LATEST_TAG +} -LATEST_TAG=$(git describe --abbrev=0 --match='v*') -VERSION=${LATEST_TAG#v} -echo Attempt to build distributables for version $VERSION -# NB does not check that this tag is on master +prepare() { + setup -echo -echo == Sanity checks + echo "Attempting to build distributables for version $VERSION" + if [ -d $RELEASE_DIR ]; then + echo Release directory $RELEASE_DIR already exists, you may want to >&2 + echo rm -rf $RELEASE_DIR >&2 + exit 1 + fi + + ## Clone the repo at the tag and go there + mkdir -p releases + git clone -q -b $LATEST_TAG . $RELEASE_DIR 2>/dev/null + cd $RELEASE_DIR -## Check that the version doesn't already exist by looking at github -## releases -if curl -sSf https://api.github.com/repos/zettio/weave/releases/$LATEST_TAG 2>/dev/null; then - echo Release $LATEST_TAG already exists on GitHub - echo https://github.com/zettio/weave/releases/$LATEST_TAG - exit 1 -fi + ## Check that the top changelog entry is this version + latest_changelog=$(grep -o "Release v.*" -m1 ./CHANGELOG.md) + if ! [ `echo "$latest_changelog" | grep -o 'v[^ ]*'` == $LATEST_TAG ]; then + echo Latest changelog entry $latest_changelog does not match >&2 + echo the latest tag $LATEST_TAG >&2 + exit 1 + fi -## Clone the repo at the tag and go there -RELEASE_DIR=releases/$LATEST_TAG -mkdir -p releases -git clone -q -b $LATEST_TAG . $RELEASE_DIR -cd $RELEASE_DIR + echo + echo == Build and test -## Check that the top changelog entry is this version -latest_changelog=$(grep -o "Release v.*" -m1 ./CHANGELOG.md) -if ! [ `echo "$latest_changelog" | grep -o 'v[^ ]*'` == $LATEST_TAG ]; then - echo Latest changelog entry $latest_changelog does not match - echo the latest tag $LATEST_TAG - exit 1 -fi + ## Inject the version numbers and build the distributables + ## (library versions?) -echo Sanity checks OK for releasing tag $LATEST_TAG + sed -i "/var version = / c\var version = \"$VERSION\"" weaver/main.go + make -echo -echo == Build and test + if make tests; then + echo '** Tests pass' + else + echo Tests failed, probably best not publish this one >&2 + exit 1 + fi -## Inject the version numbers and build the distributables -## (library versions?) + ## Run tests with the distributables, including version check + v=$(./weaver/weaver --version) + if ! [ "$v" == "weaver $VERSION" ]; then + echo Version of distributable "$v" does not match tag $LATEST_TAG >&2 + exit 1 + fi -sed -i "/var version = / c\var version = \"$VERSION\"" weaver/main.go -make + echo '** Build OK' + echo '** Release artefacts in' $RELEASE_DIR +} -## Run tests with the distributables, including version check -v=$(./weaver/weaver --version) -if ! [ "$v" == "weaver $VERSION" ]; then - echo Version of distributable "$v" does not match tag $LATEST_TAG - exit 1 -fi +publish() { + setup + cd $PWD/$RELEASE_DIR -make tests + echo == Sanity checks -echo Build and tests OK + ## Check that the version doesn't already exist by looking at github + ## releases + if curl -sSf https://api.github.com/repos/zettio/weave/releases/$LATEST_TAG 2>/dev/null; then + echo Release $LATEST_TAG already exists on GitHub >&2 + echo https://github.com/zettio/weave/releases/$LATEST_TAG >&2 + exit 1 + fi -# Publish + echo '** Sanity checks OK for publishing tag' $LATEST_TAG as zettio/weave:$VERSION -## Either leave the distributables in a directory for the dev to -## upload, or upload them automatically? + if ! which github-release; then + echo Please install git-release: + echo go get github.com/aktau/github-release + echo and create a git token per https://github.com/aktau/github-release + exit 1 + fi + + echo == Creating GitHub release $VERSION + github-release release --user $GITHUB_USER \ + --repo weave \ + --tag $LATEST_TAG \ + --name "$RELEASE_NAME" \ + --description "$RELEASE_DESCRIPTION" \ + --pre-release +} + +usage() { + echo Usage: + echo ./bin/release prepare + echo -- Build artefacts for the latest version tag + echo ./bin/release publish + echo -- Publish the artefacts for the latest tag to GitHub and DockerHub +} + +case "$1" in + prepare) + prepare + ;; + publish) + publish + ;; + *) + echo Unknown command "$1" + usage + ;; +esac From 801ca43fbf500bfe2c973780119248ec5c2236d8 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Fri, 19 Dec 2014 15:26:26 +0000 Subject: [PATCH 04/22] Better (working) way of checking for a release --- bin/release | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/bin/release b/bin/release index 007ac51b..3fce666a 100755 --- a/bin/release +++ b/bin/release @@ -71,30 +71,52 @@ publish() { echo == Sanity checks + if ! which github-release >/dev/null; then + echo Please install git-release: >&2 + echo -e "\tgo get github.com/aktau/github-release" >&2 + echo and create a git token per https://github.com/aktau/github-release >&2 + exit 1 + fi + + ## Check that the tag exists by looking at github + if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/weave/git/tags/$LATEST_TAG_SHA >/dev/null 2>&1; then + echo -e "\u2757 Tag $LATEST_TAG is not on GitHub" >&2 + echo -e "\thttps://github.com/$GITHUB_USER/weave/tags" >&2 + echo "You may need to" >&2 + echo -e "\tgit push --tags" + exit 1 + fi + echo -e "\u2713 Tag $LATEST_TAG exists in GitHub repo $GITHUB_USER/weave" + ## Check that the version doesn't already exist by looking at github ## releases - if curl -sSf https://api.github.com/repos/zettio/weave/releases/$LATEST_TAG 2>/dev/null; then - echo Release $LATEST_TAG already exists on GitHub >&2 - echo https://github.com/zettio/weave/releases/$LATEST_TAG >&2 + if github-release info --user $GITHUB_USER --repo weave --tag $LATEST_TAG >/dev/null 2>&1; then + echo -e "\u2757 Release $LATEST_TAG already exists on GitHub" >&2 + echo -e "\thttps://github.com/$GITHUB_USER/weave/releases/$LATEST_TAG" >&2 exit 1 fi echo '** Sanity checks OK for publishing tag' $LATEST_TAG as zettio/weave:$VERSION - if ! which github-release; then - echo Please install git-release: - echo go get github.com/aktau/github-release - echo and create a git token per https://github.com/aktau/github-release - exit 1 - fi - - echo == Creating GitHub release $VERSION - github-release release --user $GITHUB_USER \ + echo == Creating GitHub release $RELEASE_NAME $VERSION + # This cannot be done as a draft because of a bug in + # github-release: https://github.com/aktau/github-release/issues/7 + github-release release \ + --user $GITHUB_USER \ --repo weave \ --tag $LATEST_TAG \ - --name "$RELEASE_NAME" \ - --description "$RELEASE_DESCRIPTION" \ - --pre-release + --name "$RELEASE_NAME $VERSION" \ + --description "$RELEASE_DESCRIPTION" + + github-release upload \ + --user $GITHUB_USER \ + --repo weave \ + --tag $LATEST_TAG \ + --name "weave" \ + --file "./weave" + + echo "** Published release $RELEASE_NAME $VERSION" + echo -e "\thttps://github.com/$GITHUB_USER/weave/releases/$LATEST_TAG" } usage() { From ef82e81c3faecd758b41f01fc90477667a35830e Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 22 Dec 2014 11:19:56 +0000 Subject: [PATCH 05/22] Push tagged images to docker --- bin/release | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bin/release b/bin/release index 3fce666a..190b5d64 100755 --- a/bin/release +++ b/bin/release @@ -4,12 +4,14 @@ set -e PWD=`pwd` GITHUB_USER=squaremo +DOCKERHUB_USER=squaremo RELEASE_NAME="Weave" RELEASE_DESCRIPTION="Weaving Containers into Applications" setup() { ## Get the new version number from the most recent tag LATEST_TAG=$(git describe --abbrev=0 --match='v*') + LATEST_TAG_SHA=$(git rev-parse $LATEST_TAG) VERSION=${LATEST_TAG#v} # NB does not check that this tag is on master RELEASE_DIR=./releases/$LATEST_TAG @@ -45,7 +47,9 @@ prepare() { ## (library versions?) sed -i "/var version = / c\var version = \"$VERSION\"" weaver/main.go - make + make \ + WEAVER_IMAGE=$DOCKERHUB_USER/weave \ + WEAVEDNS_IMAGE=$DOCKERHUB_USER/weavedns if make tests; then echo '** Tests pass' @@ -96,7 +100,16 @@ publish() { exit 1 fi - echo '** Sanity checks OK for publishing tag' $LATEST_TAG as zettio/weave:$VERSION + echo '** Sanity checks OK for publishing tag' $LATEST_TAG as $DOCKERHUB_USER/weave:$VERSION + + echo == Tagging $DOCKERHUB_USER/weave and $DOCKERHUB_USER/weavedns as $VERSION + docker tag $DOCKERHUB_USER/weave $DOCKERHUB_USER/weave:$VERSION + docker tag $DOCKERHUB_USER/weavedns $DOCKERHUB_USER/weavedns:$VERSION + + docker push $DOCKERHUB_USER/weave:$VERSION + echo == Pushed $DOCKERHUB_USER/weave:$VERSION to docker hub + docker push $DOCKERHUB_USER/weavedns:$VERSION + echo == Pushed $DOCKERHUB_USER/weavedns:$VERSION to docker hub echo == Creating GitHub release $RELEASE_NAME $VERSION # This cannot be done as a draft because of a bug in From 0348767d73b8e5a32a709d51c73c677255f2ecaf Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 22 Dec 2014 11:23:08 +0000 Subject: [PATCH 06/22] prepare -> build to better avoid mistakes --- bin/release | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/release b/bin/release index 190b5d64..e72678b8 100755 --- a/bin/release +++ b/bin/release @@ -17,7 +17,7 @@ setup() { RELEASE_DIR=./releases/$LATEST_TAG } -prepare() { +build() { setup echo "Attempting to build distributables for version $VERSION" @@ -141,8 +141,8 @@ usage() { } case "$1" in - prepare) - prepare + build) + build ;; publish) publish From b014d98c78d151f0b08f4d8d9a43ea8b7ffbdfc1 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 23 Dec 2014 13:14:42 +0000 Subject: [PATCH 07/22] Put versions in the script and weavedns too, and report them sudo weave version --- bin/release | 2 ++ weave | 13 +++++++++++-- weavedns/main.go | 25 ++++++++++++++++++------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bin/release b/bin/release index e72678b8..514074a5 100755 --- a/bin/release +++ b/bin/release @@ -47,6 +47,8 @@ build() { ## (library versions?) sed -i "/var version = / c\var version = \"$VERSION\"" weaver/main.go + sed -i "/var version = / c\var version = \"$VERSION\"" weavedns/main.go + sed -i "/SCRIPT_VERSION=/ c\SCRIPT_VERSION=\"$VERSION\"" ./weave make \ WEAVER_IMAGE=$DOCKERHUB_USER/weave \ WEAVEDNS_IMAGE=$DOCKERHUB_USER/weavedns diff --git a/weave b/weave index 1b010a6e..2a9f1a6f 100755 --- a/weave +++ b/weave @@ -1,6 +1,8 @@ #!/bin/sh set -e +SCRIPT_VERSION="(unreleased version)" + usage() { echo "Usage:" echo "weave launch [-password | -passwordfile ] ..." @@ -479,14 +481,21 @@ case "$COMMAND" in ;; version) [ $# -eq 0 ] || usage - # Try the running container first; if no luck try the image + echo weave script $SCRIPT_VERSION if ! DOCKERIMAGE=$(docker inspect --format='{{ .Image }}' $CONTAINER_NAME 2>/dev/null) ; then if ! DOCKERIMAGE=$(docker inspect --format='{{ .Id }}' $IMAGE 2>/dev/null) ; then echo "Unable to find $IMAGE image." >&2 exit 1 fi fi - docker images --no-trunc | grep $DOCKERIMAGE | grep -v latest | tr -s ' ' | cut -d ' ' -f 2 + docker run --rm $DOCKERIMAGE --version + if ! DOCKERIMAGE=$(docker inspect --format='{{ .Image }}' $DNS_CONTAINER_NAME 2>/dev/null) ; then + if ! DOCKERIMAGE=$(docker inspect --format='{{ .Id }}' $DNS_IMAGE 2>/dev/null) ; then + echo "Unable to find $DNS_IMAGE image." >&2 + exit 1 + fi + fi + docker run --rm $DOCKERIMAGE --version ;; run) [ $# -gt 0 ] || usage diff --git a/weavedns/main.go b/weavedns/main.go index b06e7f1b..1185dc75 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -2,24 +2,30 @@ package main import ( "flag" + "fmt" weavedns "github.com/zettio/weave/nameserver" weavenet "github.com/zettio/weave/net" + "io" "io/ioutil" "net" "os" ) +var version = "(unreleased version)" + func main() { var ( - ifaceName string - apiPath string - dnsPort int - httpPort int - wait int - watch bool - debug bool + justVersion bool + ifaceName string + apiPath string + dnsPort int + httpPort int + wait int + watch bool + debug bool ) + flag.BoolVar(&justVersion, "version", false, "print version and exit") flag.StringVar(&ifaceName, "iface", "", "name of interface to use for multicast") flag.StringVar(&apiPath, "api", "unix:///var/run/docker.sock", "Path to Docker API socket") flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up") @@ -29,6 +35,11 @@ func main() { flag.BoolVar(&debug, "debug", false, "output debugging info to stderr") flag.Parse() + if justVersion { + io.WriteString(os.Stdout, fmt.Sprintf("weavedns %s\n", version)) + os.Exit(0) + } + debugOut := ioutil.Discard if debug { debugOut = os.Stderr From b0b7649c8e06a57c57830794ff9457cb562bae20 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 23 Dec 2014 13:46:26 +0000 Subject: [PATCH 08/22] Switch to proper github and dockerhub repo --- bin/release | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/release b/bin/release index 514074a5..fd8a6897 100755 --- a/bin/release +++ b/bin/release @@ -3,8 +3,8 @@ set -e PWD=`pwd` -GITHUB_USER=squaremo -DOCKERHUB_USER=squaremo +GITHUB_USER=zettio +DOCKERHUB_USER=zettio RELEASE_NAME="Weave" RELEASE_DESCRIPTION="Weaving Containers into Applications" From 0a14eb58b20e2118eae4fdf0bf33d62c5a73101f Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 24 Dec 2014 11:12:14 +0000 Subject: [PATCH 09/22] Don't hardwire executable names; use logical names instead We could use `os.Args[0]` instead of hardwired names, but that ends up being e.g. `/home/weave/weaver`. So, use logical names instead. --- weavedns/main.go | 2 +- weaver/main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/weavedns/main.go b/weavedns/main.go index 1185dc75..ab5ecbd4 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -36,7 +36,7 @@ func main() { flag.Parse() if justVersion { - io.WriteString(os.Stdout, fmt.Sprintf("weavedns %s\n", version)) + io.WriteString(os.Stdout, fmt.Sprintf("weave DNS %s\n", version)) os.Exit(0) } diff --git a/weaver/main.go b/weaver/main.go index c28b9bb9..ac24973d 100644 --- a/weaver/main.go +++ b/weaver/main.go @@ -59,7 +59,7 @@ func main() { peers = flag.Args() if justVersion { - io.WriteString(os.Stdout, fmt.Sprintf("weaver %s\n", version)) + io.WriteString(os.Stdout, fmt.Sprintf("weave router %s\n", version)) os.Exit(0) } @@ -136,7 +136,7 @@ func main() { func handleHttp(router *weave.Router) { http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, fmt.Sprintln("weaver version", version)) + io.WriteString(w, fmt.Sprintln("weave router", version)) io.WriteString(w, router.Status()) }) http.HandleFunc("/connect", func(w http.ResponseWriter, r *http.Request) { From 8b783af8323b07a7b5702cbc20d78fcb2f0e80a5 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 24 Dec 2014 12:04:53 +0000 Subject: [PATCH 10/22] Quote all echoings and be consistent about the message prefix --- bin/release | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/bin/release b/bin/release index fd8a6897..3c0afdc0 100755 --- a/bin/release +++ b/bin/release @@ -20,10 +20,10 @@ setup() { build() { setup - echo "Attempting to build distributables for version $VERSION" + echo "== Clone repo at $LATEST_TAG for version $VERSION" if [ -d $RELEASE_DIR ]; then - echo Release directory $RELEASE_DIR already exists, you may want to >&2 - echo rm -rf $RELEASE_DIR >&2 + echo -e "\u2757 Release directory $RELEASE_DIR already exists, you may want to" >&2 + echo -e "\trm -rf $RELEASE_DIR" >&2 exit 1 fi @@ -35,13 +35,13 @@ build() { ## Check that the top changelog entry is this version latest_changelog=$(grep -o "Release v.*" -m1 ./CHANGELOG.md) if ! [ `echo "$latest_changelog" | grep -o 'v[^ ]*'` == $LATEST_TAG ]; then - echo Latest changelog entry $latest_changelog does not match >&2 - echo the latest tag $LATEST_TAG >&2 + echo -e "\u2757 Latest changelog entry $latest_changelog does not match" >&2 + echo "the latest tag $LATEST_TAG" >&2 exit 1 fi echo - echo == Build and test + echo "== Build and test" ## Inject the version numbers and build the distributables ## (library versions?) @@ -54,20 +54,20 @@ build() { WEAVEDNS_IMAGE=$DOCKERHUB_USER/weavedns if make tests; then - echo '** Tests pass' + echo -e '\u2713 Tests pass' else - echo Tests failed, probably best not publish this one >&2 + echo -e "\u2757 Tests failed, probably best not publish this one" >&2 exit 1 fi ## Run tests with the distributables, including version check v=$(./weaver/weaver --version) if ! [ "$v" == "weaver $VERSION" ]; then - echo Version of distributable "$v" does not match tag $LATEST_TAG >&2 + echo "Version of distributable "$v" does not match tag $LATEST_TAG" >&2 exit 1 fi - echo '** Build OK' + echo -e '\u2713 Build OK' echo '** Release artefacts in' $RELEASE_DIR } @@ -75,12 +75,12 @@ publish() { setup cd $PWD/$RELEASE_DIR - echo == Sanity checks + echo "== Sanity checks" if ! which github-release >/dev/null; then - echo Please install git-release: >&2 + echo "Please install git-release:" >&2 echo -e "\tgo get github.com/aktau/github-release" >&2 - echo and create a git token per https://github.com/aktau/github-release >&2 + echo "and create a git token per https://github.com/aktau/github-release" >&2 exit 1 fi @@ -109,11 +109,11 @@ publish() { docker tag $DOCKERHUB_USER/weavedns $DOCKERHUB_USER/weavedns:$VERSION docker push $DOCKERHUB_USER/weave:$VERSION - echo == Pushed $DOCKERHUB_USER/weave:$VERSION to docker hub + echo "** Pushed $DOCKERHUB_USER/weave:$VERSION to docker hub" docker push $DOCKERHUB_USER/weavedns:$VERSION - echo == Pushed $DOCKERHUB_USER/weavedns:$VERSION to docker hub + echo "** Pushed $DOCKERHUB_USER/weavedns:$VERSION to docker hub" - echo == Creating GitHub release $RELEASE_NAME $VERSION + echo "== Creating GitHub release $RELEASE_NAME $VERSION" # This cannot be done as a draft because of a bug in # github-release: https://github.com/aktau/github-release/issues/7 github-release release \ @@ -135,11 +135,11 @@ publish() { } usage() { - echo Usage: - echo ./bin/release prepare - echo -- Build artefacts for the latest version tag - echo ./bin/release publish - echo -- Publish the artefacts for the latest tag to GitHub and DockerHub + echo "Usage:" + echo -e "\t./bin/release prepare" + echo "-- Build artefacts for the latest version tag" + echo -e "\t./bin/release publish" + echo "-- Publish the artefacts for the latest tag to GitHub and DockerHub" } case "$1" in @@ -150,7 +150,7 @@ case "$1" in publish ;; *) - echo Unknown command "$1" + echo "Unknown command \"$1\"" usage ;; esac From f842b22eb89771f6bd4ec1dbe529f56c8bdc8b92 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 24 Dec 2014 12:43:39 +0000 Subject: [PATCH 11/22] Do better with checking the changelog Before, this could fail without a message if there was a changelog but no matching line. Also change the changelog format == Release v0.0.1 to == Release 0.0.1 --- bin/release | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bin/release b/bin/release index 3c0afdc0..7eb4efe2 100755 --- a/bin/release +++ b/bin/release @@ -33,10 +33,9 @@ build() { cd $RELEASE_DIR ## Check that the top changelog entry is this version - latest_changelog=$(grep -o "Release v.*" -m1 ./CHANGELOG.md) - if ! [ `echo "$latest_changelog" | grep -o 'v[^ ]*'` == $LATEST_TAG ]; then - echo -e "\u2757 Latest changelog entry $latest_changelog does not match" >&2 - echo "the latest tag $LATEST_TAG" >&2 + if ! latest_changelog=$(grep -o "== Release [0-9].*" -m1 ./CHANGELOG.md) || \ + ! [ `echo "$latest_changelog" | grep -o '[0-9][^ ]*'` == "$VERSION" ]; then + echo -e "\u2757 Latest changelog entry \"$latest_changelog\" does not match the release version $VERSION" >&2 exit 1 fi @@ -61,9 +60,9 @@ build() { fi ## Run tests with the distributables, including version check - v=$(./weaver/weaver --version) - if ! [ "$v" == "weaver $VERSION" ]; then - echo "Version of distributable "$v" does not match tag $LATEST_TAG" >&2 + v=$(./weaver/weaver --version | grep -o '[0-9].*') + if ! [ "$v" == "$VERSION" ]; then + echo "Version of distributable "$v" does not match release version $VERSION" >&2 exit 1 fi From 3e1d96995a6fc6ba1945c1b159d4000205992967 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 Dec 2014 12:01:29 +0000 Subject: [PATCH 12/22] cosmetic --- bin/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/release b/bin/release index 7eb4efe2..57345f85 100755 --- a/bin/release +++ b/bin/release @@ -26,7 +26,7 @@ build() { echo -e "\trm -rf $RELEASE_DIR" >&2 exit 1 fi - + ## Clone the repo at the tag and go there mkdir -p releases git clone -q -b $LATEST_TAG . $RELEASE_DIR 2>/dev/null From 314fff0cffecea18da65856b41c934498d014006 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 24 Dec 2014 13:51:51 +0000 Subject: [PATCH 13/22] No need for make publish --- Makefile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Makefile b/Makefile index 982b6e8c..4e22b2c5 100644 --- a/Makefile +++ b/Makefile @@ -40,14 +40,6 @@ $(WEAVEDNS_EXPORT): weavedns/Dockerfile $(WEAVEDNS_EXE) tests: cd nameserver; go test -tags netgo -publish: $(WEAVER_EXPORT) tests - $(SUDO) docker tag $(WEAVER_IMAGE) $(WEAVER_IMAGE):git-`git rev-parse --short=12 HEAD` - $(SUDO) docker push $(WEAVER_IMAGE):latest - $(SUDO) docker push $(WEAVER_IMAGE):git-`git rev-parse --short=12 HEAD` - $(SUDO) docker tag $(WEAVEDNS_IMAGE) $(WEAVEDNS_IMAGE):git-`git rev-parse --short=12 HEAD` - $(SUDO) docker push $(WEAVEDNS_IMAGE):latest - $(SUDO) docker push $(WEAVEDNS_IMAGE):git-`git rev-parse --short=12 HEAD` - clean: -$(SUDO) docker rmi $(WEAVER_IMAGE) $(WEAVEDNS_IMAGE) rm -f $(WEAVER_EXE) $(WEAVEDNS_EXE) $(WEAVER_EXPORT) $(WEAVEDNS_EXPORT) From 6c2bef5f88f194a63e9cef45a6a3dd92ceea2c94 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 29 Dec 2014 11:53:00 +0000 Subject: [PATCH 14/22] Missed change of command in usage message --- bin/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/release b/bin/release index 57345f85..a39157e5 100755 --- a/bin/release +++ b/bin/release @@ -135,7 +135,7 @@ publish() { usage() { echo "Usage:" - echo -e "\t./bin/release prepare" + echo -e "\t./bin/release build" echo "-- Build artefacts for the latest version tag" echo -e "\t./bin/release publish" echo "-- Publish the artefacts for the latest tag to GitHub and DockerHub" From ec7dc556ed8a115c65bf2aadd612f354182a8c82 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 29 Dec 2014 12:04:45 +0000 Subject: [PATCH 15/22] Factor out ask_version and don't exit 1 if it fails --- weave | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/weave b/weave index 2a9f1a6f..ba21800b 100755 --- a/weave +++ b/weave @@ -387,6 +387,15 @@ uname -s -r | sed -n 's|^\([^ ]*\) \([0-9]\+\)\.\([0-9]\+\).*|\1 \2 \3|p' | { fi } +ask_version() { + if ! DOCKERIMAGE=$(docker inspect --format='{{ .Image }}' $1 2>/dev/null) ; then + if ! DOCKERIMAGE=$(docker inspect --format='{{ .Id }}' $2 2>/dev/null) ; then + echo "Unable to find $2 image." >&2 + fi + fi + [ -n "$DOCKERIMAGE" ] && docker run --rm $DOCKERIMAGE --version +} + if ! command_exists ip ; then echo "ERROR: ip utility is missing. Please install it." >&2 exit 1 @@ -482,20 +491,8 @@ case "$COMMAND" in version) [ $# -eq 0 ] || usage echo weave script $SCRIPT_VERSION - if ! DOCKERIMAGE=$(docker inspect --format='{{ .Image }}' $CONTAINER_NAME 2>/dev/null) ; then - if ! DOCKERIMAGE=$(docker inspect --format='{{ .Id }}' $IMAGE 2>/dev/null) ; then - echo "Unable to find $IMAGE image." >&2 - exit 1 - fi - fi - docker run --rm $DOCKERIMAGE --version - if ! DOCKERIMAGE=$(docker inspect --format='{{ .Image }}' $DNS_CONTAINER_NAME 2>/dev/null) ; then - if ! DOCKERIMAGE=$(docker inspect --format='{{ .Id }}' $DNS_IMAGE 2>/dev/null) ; then - echo "Unable to find $DNS_IMAGE image." >&2 - exit 1 - fi - fi - docker run --rm $DOCKERIMAGE --version + ask_version $CONTAINER_NAME $IMAGE + ask_version $DNS_CONTAINER_NAME $DNS_IMAGE ;; run) [ $# -gt 0 ] || usage From 7c8586b57652e25243bf46577aeb559bad20025a Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 Dec 2014 12:27:42 +0000 Subject: [PATCH 16/22] nicer error when there is no version tag --- bin/release | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/release b/bin/release index a39157e5..c0483a9f 100755 --- a/bin/release +++ b/bin/release @@ -10,7 +10,10 @@ RELEASE_DESCRIPTION="Weaving Containers into Applications" setup() { ## Get the new version number from the most recent tag - LATEST_TAG=$(git describe --abbrev=0 --match='v*') + if ! LATEST_TAG=$(git describe --abbrev=0 --match='v*' 2>/dev/null) ; then + echo "Could not find a 'v*' version tag." >&2 + exit 1 + fi LATEST_TAG_SHA=$(git rev-parse $LATEST_TAG) VERSION=${LATEST_TAG#v} # NB does not check that this tag is on master From d31a4ea3319181bb79fe7200b94027827970c8bf Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 Dec 2014 13:27:35 +0000 Subject: [PATCH 17/22] more idiomatic go build time variable setting avoiding the use of 'sed' --- Makefile | 3 ++- bin/release | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4e22b2c5..5482f582 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ # If you can use docker without being root, you can do "make SUDO=" SUDO=sudo +WEAVE_VERSION=git-$(shell git rev-parse --short=12 HEAD) WEAVER_EXE=weaver/weaver WEAVEDNS_EXE=weavedns/weavedns WEAVER_IMAGE=zettio/weave @@ -15,7 +16,7 @@ all: $(WEAVER_EXPORT) $(WEAVEDNS_EXPORT) $(WEAVER_EXE) $(WEAVEDNS_EXE): go get -tags netgo ./$(shell dirname $@) - go build -ldflags '-extldflags "-static"' -tags netgo -o $@ ./$(shell dirname $@) + go build -ldflags '-extldflags "-static"' -ldflags "-X main.version $(WEAVE_VERSION)" -tags netgo -o $@ ./$(shell dirname $@) @strings $@ | grep cgo_stub\\\.go >/dev/null || { \ rm $@; \ echo "\nYour go standard library was built without the 'netgo' build tag."; \ diff --git a/bin/release b/bin/release index c0483a9f..749622f7 100755 --- a/bin/release +++ b/bin/release @@ -47,11 +47,9 @@ build() { ## Inject the version numbers and build the distributables ## (library versions?) - - sed -i "/var version = / c\var version = \"$VERSION\"" weaver/main.go - sed -i "/var version = / c\var version = \"$VERSION\"" weavedns/main.go sed -i "/SCRIPT_VERSION=/ c\SCRIPT_VERSION=\"$VERSION\"" ./weave make \ + WEAVE_VERSION=$VERSION \ WEAVER_IMAGE=$DOCKERHUB_USER/weave \ WEAVEDNS_IMAGE=$DOCKERHUB_USER/weavedns From 50d94529bf28d3a9c25873391849116a9fe3b4d9 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 Dec 2014 13:49:46 +0000 Subject: [PATCH 18/22] accept lightweight tags --- bin/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/release b/bin/release index 749622f7..745340e2 100755 --- a/bin/release +++ b/bin/release @@ -10,7 +10,7 @@ RELEASE_DESCRIPTION="Weaving Containers into Applications" setup() { ## Get the new version number from the most recent tag - if ! LATEST_TAG=$(git describe --abbrev=0 --match='v*' 2>/dev/null) ; then + if ! LATEST_TAG=$(git describe --tags --abbrev=0 --match='v*' 2>/dev/null) ; then echo "Could not find a 'v*' version tag." >&2 exit 1 fi From f9593ac571c6e3097e069cc5deaad91c35e24297 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 Dec 2014 13:51:45 +0000 Subject: [PATCH 19/22] ignore release dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a23bb285..dc3e5a85 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ _testmain.go # Project specific weavedns/weavedns +releases From cca0f5fc794b369a58e8e378ed7537bcb769a34b Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 Dec 2014 14:27:21 +0000 Subject: [PATCH 20/22] don't allow lightweight tags after all --- bin/release | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/release b/bin/release index 745340e2..df7d4534 100755 --- a/bin/release +++ b/bin/release @@ -10,8 +10,8 @@ RELEASE_DESCRIPTION="Weaving Containers into Applications" setup() { ## Get the new version number from the most recent tag - if ! LATEST_TAG=$(git describe --tags --abbrev=0 --match='v*' 2>/dev/null) ; then - echo "Could not find a 'v*' version tag." >&2 + if ! LATEST_TAG=$(git describe --abbrev=0 --match='v*' 2>/dev/null) ; then + echo "Could not find an annotated 'v*' version tag." >&2 exit 1 fi LATEST_TAG_SHA=$(git rev-parse $LATEST_TAG) From 82dfe1cc02f6860c8cde0b22271de88fb887080e Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 29 Dec 2014 16:42:41 +0000 Subject: [PATCH 21/22] Upload the release artefact to a "latest_release" release We would like to have a stable URL for the most recently released script, so that we can mention it in the README and people can use it in update scripts. Since GitHub's releases/latest URL redirects, and anyway doesn't work for downloads, we have to create (possibly delete first) a release tagged "latest_release" and update it. --- bin/release | 54 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/bin/release b/bin/release index df7d4534..9d5026da 100755 --- a/bin/release +++ b/bin/release @@ -15,6 +15,7 @@ setup() { exit 1 fi LATEST_TAG_SHA=$(git rev-parse $LATEST_TAG) + LATEST_RELEASE_SHA=$(git rev-parse latest_release) VERSION=${LATEST_TAG#v} # NB does not check that this tag is on master RELEASE_DIR=./releases/$LATEST_TAG @@ -84,14 +85,30 @@ publish() { exit 1 fi - ## Check that the tag exists by looking at github - if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/weave/git/tags/$LATEST_TAG_SHA >/dev/null 2>&1; then - echo -e "\u2757 Tag $LATEST_TAG is not on GitHub" >&2 - echo -e "\thttps://github.com/$GITHUB_USER/weave/tags" >&2 - echo "You may need to" >&2 - echo -e "\tgit push --tags" + if ! [ $(git rev-list -1 $LATEST_TAG) == $(git rev-list -1 latest_release) ]; then + echo -e "\u2757 The tag latest_release does not point to the same commit as $LATEST_TAG" exit 1 fi + + ## Check that the tag exists by looking at github + if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/weave/git/tags/$LATEST_TAG_SHA >/dev/null 2>&1; then + echo -e "\u2757 Tag $LATEST_TAG is not on GitHub, or is not the same as the local tag" >&2 + echo -e "\thttps://github.com/$GITHUB_USER/weave/tags" >&2 + echo "You may need to" >&2 + echo -e "\tgit push git@github.com:$GITHUB_USER/weave $LATEST_TAG" + exit 1 + fi + + ## Check that the 'latest_release' tag exists by looking at github + if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/weave/git/tags/$LATEST_RELEASE_SHA >/dev/null 2>&1; then + echo -e "\u2757 Tag latest_release is not on GitHub, or is not the same as the local tag" >&2 + echo -e "\thttps://github.com/$GITHUB_USER/weave/tags" >&2 + echo "You may need to" >&2 + echo -e "\tgit tag -af latest_release" + echo -e "\tgit push -f git@github.com:$GITHUB_USER/weave latest_release" + exit 1 + fi + echo -e "\u2713 Tag $LATEST_TAG exists in GitHub repo $GITHUB_USER/weave" ## Check that the version doesn't already exist by looking at github @@ -132,6 +149,31 @@ publish() { echo "** Published release $RELEASE_NAME $VERSION" echo -e "\thttps://github.com/$GITHUB_USER/weave/releases/$LATEST_TAG" + + if github-release info --user $GITHUB_USER --repo weave \ + --tag latest_release >/dev/null 2>&1; then + github-release delete \ + --user $GITHUB_USER \ + --repo weave \ + --tag latest_release + fi + + github-release release \ + --user $GITHUB_USER \ + --repo weave \ + --tag latest_release \ + --name "$RELEASE_NAME latest ($VERSION)" \ + --description "$RELEASE_DESCRIPTION" + + github-release upload \ + --user $GITHUB_USER \ + --repo weave \ + --tag latest_release \ + --name "weave" \ + --file "./weave" + + echo "** Published $RELEASE_NAME as latest_release at" + echo -e "\thttps://github.com/$GITHUB_USER/weave/releases/latest_release" } usage() { From 29f94fd64f96c92630d990f0e775dd51429d1332 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 30 Dec 2014 12:50:46 +0000 Subject: [PATCH 22/22] Update the example `weave status` output --- site/troubleshooting.md | 1 + 1 file changed, 1 insertion(+) diff --git a/site/troubleshooting.md b/site/troubleshooting.md index 1603b939..8c0fcb3f 100644 --- a/site/troubleshooting.md +++ b/site/troubleshooting.md @@ -56,6 +56,7 @@ reports on the current status of the weave router. This produces output like: ```` +weave router 0.7.0 Our name is 7a:f4:56:87:76:3b Sniffing traffic on &{39 65535 ethwe ae:e3:07:9c:8c:d4 up|broadcast|multicast} MACs: