all: normalize GKE configs/Makefiles to follow common patterns

When a push is made, the latest image is pushed to the registry
with the git hash of the repo and also the same image is pushed
with the :latest tag. This ensures that :latest always points to
the most recent image and that kubectl set image will trigger an
update on the pods without having to delete them.

Fixes golang/go#21772

Change-Id: I97c893f181cdd8891eb87efb3f9ab42ede107d97
Reviewed-on: https://go-review.googlesource.com/61730
Reviewed-by: Sarah Adams <shadams@google.com>
diff --git a/cmd/gitmirror/Makefile b/cmd/gitmirror/Makefile
index 073df8d..71dd590 100644
--- a/cmd/gitmirror/Makefile
+++ b/cmd/gitmirror/Makefile
@@ -2,7 +2,12 @@
 # Use of this source code is governed by a BSD-style
 # license that can be found in the LICENSE file.
 
-VERSION=latest
+MUTABLE_VERSION ?= latest
+VERSION ?= $(shell git rev-parse --short HEAD)
+
+IMAGE_STAGING := gcr.io/go-dashboard-dev/gitmirror
+IMAGE_PROD := gcr.io/symbolic-datum-552/gitmirror
+
 DOCKER_IMAGE_build0=build0/gitmirror:latest
 DOCKER_CTR_build0=gitmirror-build0
 
@@ -19,14 +24,23 @@
 	gitlock --update=Dockerfile.0 golang.org/x/build/cmd/gitmirror
 
 docker-prod: Dockerfile gitmirror
-	docker build --force-rm --tag=gcr.io/symbolic-datum-552/gitmirror:$(VERSION) .
+	docker build --force-rm --tag=$(IMAGE_PROD):$(VERSION) .
+	docker tag $(IMAGE_PROD):$(VERSION) $(IMAGE_PROD):$(MUTABLE_VERSION)
 docker-staging: Dockerfile gitmirror
-	docker build --force-rm --tag=gcr.io/go-dashboard-dev/gitmirror:latest .
+	docker build --force-rm --tag=$(IMAGE_STAGING):$(VERSION) .
+	docker tag $(IMAGE_STAGING):$(VERSION) $(IMAGE_STAGING):$(MUTABLE_VERSION)
 
 push-prod: docker-prod
-	gcloud docker -- push gcr.io/symbolic-datum-552/gitmirror:$(VERSION)
+	gcloud docker -- push $(IMAGE_PROD):$(MUTABLE_VERSION)
+	gcloud docker -- push $(IMAGE_PROD):$(VERSION)
 push-staging: docker-staging
-	gcloud docker -- push gcr.io/go-dashboard-dev/gitmirror:latest
+	gcloud docker -- push $(IMAGE_STAGING):$(MUTABLE_VERSION)
+	gcloud docker -- push $(IMAGE_STAGING):$(VERSION)
+
+deploy-prod: push-prod
+	kubectl set image deployment/gitmirror-deployment gitmirror=$(IMAGE_PROD):$(VERSION)
+deploy-staging: push-staging
+	kubectl set image deployment/gitmirror-deployment gitmirror=$(IMAGE_STAGING):$(VERSION)
 
 .PHONY: clean
 clean: