From 2ef83adf0eef2074d9eac46b5c014561654e60a9 Mon Sep 17 00:00:00 2001
From: Benjamin Bollen <ben@monax.io>
Date: Fri, 10 Feb 2017 19:17:51 +0100
Subject: [PATCH] release: push latest from master, version tags from release,
 immutable version tag for tagged commits

---
 circle.yml          | 27 +++++++++++++++++++++++----
 docs/build.sh       |  2 +-
 tests/build_tool.sh | 20 ++++++++------------
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/circle.yml b/circle.yml
index b9b3fce9..f2cc9173 100644
--- a/circle.yml
+++ b/circle.yml
@@ -41,23 +41,42 @@ deployment:
     branch: release-0.12
     commands:
       - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
+      # build docker image and tag the image with the version
       - tests/build_tool.sh
-      - "docker tag quay.io/eris/db:build throw:build && docker rmi quay.io/eris/db:build"
       - docker push quay.io/eris/db
+      # push the updated documentation
       - docs/build.sh
   release-0.16:
     branch: release-0.16
     commands:
       - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
+      # build docker image and tag the image with the version
       - tests/build_tool.sh
-      - "docker tag quay.io/eris/db:build throw:build && docker rmi quay.io/eris/db:build"
       - docker push quay.io/eris/db
+      # push the updated documentation
       - docs/build.sh
   master:
     branch: master
     commands:
       - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
+      # build docker image and tag the image with ':latest'
+      # builds on master are considered immutable so we do not push the version
+      # tag to allow for hotfixes
+      - tests/build_tool.sh latest
+      - docker push quay.io/eris/db
+      # push the updated documentation and replace latest
+      - docs/build.sh latest
+  tagged-releases:
+    tag: /v[0-9]+(\.[0-9]+)*/
+    commands:
+      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
+      # build docker image and tag the image with the version;
+      # once the commit is tagged the docker image for this version tag is
+      # considered immutable.
       - tests/build_tool.sh
-      - "docker rmi quay.io/eris/db:latest && docker tag quay.io/eris/db:build throw:build && docker rmi quay.io/eris/db:build"
       - docker push quay.io/eris/db
-      - docs/build.sh release
+      # push the updated documentation
+      - docs/build.sh
+
+
+
diff --git a/docs/build.sh b/docs/build.sh
index d2f09724..ac790cbf 100755
--- a/docs/build.sh
+++ b/docs/build.sh
@@ -28,7 +28,7 @@ cd $repo
 rm -rf $docs_name
 go run ./docs/generator.go
 
-if [[ "$1" == "release" ]]
+if [[ "$1" == "latest" ]]
 then
   mkdir -p $docs_name/$slim_name/latest
   rsync -av $docs_name/$slim_name/$release_min/ $docs_name/$slim_name/latest/
diff --git a/tests/build_tool.sh b/tests/build_tool.sh
index b32f941b..7b272932 100755
--- a/tests/build_tool.sh
+++ b/tests/build_tool.sh
@@ -40,18 +40,14 @@ docker run --rm --entrypoint cat $IMAGE:build /usr/local/bin/$TARGET > $REPO/"$T
 docker run --rm --entrypoint cat $IMAGE:build /usr/local/bin/eris-client > $REPO/eris-client
 docker build -t $IMAGE:$release_min -f Dockerfile.deploy $REPO
 
-# Cleanup
-rm $REPO/"$TARGET"_build_artifact
-rm $REPO/eris-client
-
-# Extra Tags
-if [[ "$branch" = "release" ]]
+# If provided, tag the image with the label provided
+if [ "$1" ]
 then
-  docker tag -f $IMAGE:$release_min $IMAGE:$release_maj
-  docker tag -f $IMAGE:$release_min $IMAGE:latest
+  docker tag $IMAGE:$release_min $IMAGE:$1
+  docker rmi $IMAGE:$release_min
 fi
 
-if [ "$CIRCLE_BRANCH" ]
-then
-  docker tag -f $IMAGE:$release_min $IMAGE:latest
-fi
+# Cleanup
+rm $REPO/"$TARGET"_build_artifact
+rm $REPO/eris-client
+docker rmi $IMAGE:build
-- 
GitLab