Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plumbing for releases stolen straight from weave. #143

Merged
merged 1 commit into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Release 0.1.0

- Intial release.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SCOPE_IMAGE=$(DOCKERHUB_USER)/scope
SCOPE_EXPORT=scope.tar
SCOPE_UI_BUILD_EXPORT=scope_ui_build.tar
SCOPE_UI_BUILD_IMAGE=$(DOCKERHUB_USER)/scope-ui-build
GIT_REVISION=$(shell git rev-parse HEAD)
SCOPE_VERSION=$(shell git rev-parse HEAD)

all: $(SCOPE_EXPORT)

Expand All @@ -35,7 +35,7 @@ $(PROBE_EXE): probe/*.go report/*.go xfer/*.go

$(APP_EXE) $(PROBE_EXE):
go get -tags netgo ./$(@D)
go build -ldflags "-extldflags \"-static\" -X main.version $(GIT_REVISION)" -tags netgo -o $@ ./$(@D)
go build -ldflags "-extldflags \"-static\" -X main.version $(SCOPE_VERSION)" -tags netgo -o $@ ./$(@D)

static: client/build/app.js
esc -o app/static.go -prefix client/build client/build
Expand Down Expand Up @@ -71,4 +71,5 @@ deps:
github.com/fzipp/gocyclo \
github.com/mattn/goveralls \
github.com/mjibson/esc \
github.com/kisielk/errcheck
github.com/kisielk/errcheck \
github.com/aktau/github-release
6 changes: 6 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ func main() {
batch = flag.Duration("batch", 1*time.Second, "batch interval")
window = flag.Duration("window", 15*time.Second, "window")
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
printVersion = flag.Bool("version", false, "print version number and exit")
)
flag.Parse()
probes := append(defaultProbes, flag.Args()...)

if *printVersion {
fmt.Println(version)
return
}

switch *logfile {
case "stderr":
break // by default
Expand Down
192 changes: 192 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#! /bin/bash

set -e

SUDO=${SUDO-sudo}
GITHUB_USER=${GITHUB_USER:-weaveworks}
DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}
RELEASE_NAME=${RELEASE_NAME:-"Weave Scope"}
RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION:-"Container Visibility"}

PWD=`pwd`

setup() {
## Get the new version number from the most recent tag
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)
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
}

build() {
setup

echo "== Clone repo at $LATEST_TAG for version $VERSION"
if [ -d $RELEASE_DIR ]; then
echo -e "\u2757 Release directory $RELEASE_DIR already exists, you may want to" >&2
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
cd $RELEASE_DIR

## Check that the top changelog entry is this version
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

echo
echo "== Build and test"

## Inject the version numbers and build the distributables
## (library versions?)
sed -i "/SCRIPT_VERSION=/ c\SCRIPT_VERSION=\"$VERSION\"" ./scope
make SUDO=$SUDO SCOPE_VERSION=$VERSION DOCKERHUB_USER=$DOCKERHUB_USER

if ./bin/test; then
echo -e '\u2713 Tests pass'
else
echo -e "\u2757 Tests failed, probably best not publish this one" >&2
exit 1
fi

## Run tests with the distributables, including version check
v=$(./app/app -version | grep -o '[0-9].*')
if ! [ "$v" == "$VERSION" ]; then
echo "Version of distributable "$v" does not match release version $VERSION" >&2
exit 1
fi

echo -e '\u2713 Build OK'
echo '** Release artefacts in' $RELEASE_DIR
}

publish() {
setup
cd $PWD/$RELEASE_DIR

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

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/scope/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/scope/tags" >&2
echo "You may need to" >&2
echo -e "\tgit push git@github.com:$GITHUB_USER/scope $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/scope/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/scope/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/scope latest_release"
exit 1
fi

echo -e "\u2713 Tag $LATEST_TAG exists in GitHub repo $GITHUB_USER/scope"

## Check that the version doesn't already exist by looking at github
## releases
if github-release info --user $GITHUB_USER --repo scope --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/scope/releases/$LATEST_TAG" >&2
exit 1
fi

echo '** Sanity checks OK for publishing tag' $LATEST_TAG as $DOCKERHUB_USER/scope:$VERSION

echo "== Tagging and publishing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f $DOCKERHUB_USER/scope $DOCKERHUB_USER/scope:$VERSION
$SUDO docker push $DOCKERHUB_USER/scope:$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 \
--user $GITHUB_USER \
--repo scope \
--tag $LATEST_TAG \
--name "$RELEASE_NAME $VERSION" \
--description "$RELEASE_DESCRIPTION"

github-release upload \
--user $GITHUB_USER \
--repo scope \
--tag $LATEST_TAG \
--name "scope" \
--file "./scope"

echo "** Published release $RELEASE_NAME $VERSION"
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"

if github-release info --user $GITHUB_USER --repo scope \
--tag latest_release >/dev/null 2>&1; then
github-release delete \
--user $GITHUB_USER \
--repo scope \
--tag latest_release
fi

github-release release \
--user $GITHUB_USER \
--repo scope \
--tag latest_release \
--name "$RELEASE_NAME latest ($VERSION)" \
--description "$RELEASE_DESCRIPTION"

github-release upload \
--user $GITHUB_USER \
--repo scope \
--tag latest_release \
--name "scope" \
--file "./scope"

echo "** Published $RELEASE_NAME as latest_release at"
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/latest_release"
}

usage() {
echo "Usage:"
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"
}

case "$1" in
build)
build
;;
publish)
publish
;;
*)
echo "Unknown command \"$1\""
usage
;;
esac
9 changes: 8 additions & 1 deletion scope
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ usage() {
exit 1
}

SCOPE_IMAGE=weaveworks/scope
SCRIPT_VERSION="(unreleased version)"
if [ "$SCRIPT_VERSION" = "(unreleased version)" ] ; then
IMAGE_VERSION=latest
else
IMAGE_VERSION=$SCRIPT_VERSION
fi

This comment was marked as abuse.

This comment was marked as abuse.

IMAGE_VERSION=${VERSION:-$IMAGE_VERSION}
SCOPE_IMAGE=weaveworks/scope:$IMAGE_VERSION
CONTAINER_NAME=weavescope
DNS_CONTAINER_NAME=weavedns
DNS_HTTP_PORT=6785
Expand Down