cmd/coordinator: stop using gitlock, use go modules

Also, along for the ride:

* update from jessie to stretch
* update from Go 1.10 to Go 1.12
* move to multi-stage Dockerfile, including drawterm, reducing image size
* remove the static linking which was resulting in build warnings
* clean up Makefile

Updates golang/go#26872
Updates golang/go#27719

Change-Id: Ic4dc9b8539fb8662c9621c113fa94b70bc7de061
Reviewed-on: https://go-review.googlesource.com/c/build/+/175985
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/coordinator/.gitignore b/cmd/coordinator/.gitignore
index 6a029fb..91d0fb0 100644
--- a/cmd/coordinator/.gitignore
+++ b/cmd/coordinator/.gitignore
@@ -1,4 +1,3 @@
 buildongce/client-*.dat
 buildongce/token.dat
 coordinator
-ca-certificates.crt
diff --git a/cmd/coordinator/Dockerfile b/cmd/coordinator/Dockerfile
index b92b76b..8aac5fc 100644
--- a/cmd/coordinator/Dockerfile
+++ b/cmd/coordinator/Dockerfile
@@ -1,20 +1,68 @@
 # Copyright 2017 The Go Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style
 # license that can be found in the LICENSE file.
-FROM debian:jessie
+
+FROM golang:1.12 AS build
 LABEL maintainer "golang-dev@googlegroups.com"
 
-# openssh client is for the gomote ssh proxy client.
-# telnet is for the gomote ssh proxy to windows. (no ssh server there)
-# git-core, make, gcc, libc6-dev, and libx11-dev are to build 0intro/conterm,
-# used to connect to plan9 instances.
-RUN apt-get update && apt-get install -y \
-	--no-install-recommends \
-	ca-certificates \
-	openssh-client \
-	telnet \
-	git-core make gcc libc6-dev libx11-dev \
-	&& rm -rf /var/lib/apt/lists/*
+ENV GO111MODULE=on
+ENV GOPROXY=https://proxy.golang.org
+
+RUN mkdir /gocache
+ENV GOCACHE /gocache
+
+COPY go.mod /go/src/golang.org/x/build/go.mod
+COPY go.sum /go/src/golang.org/x/build/go.sum
+
+WORKDIR /go/src/golang.org/x/build
+
+# Optimization for iterative docker build speed, not necessary for correctness:
+# TODO: write a tool to make writing Go module-friendly Dockerfiles easier.
+RUN go install \
+    cloud.google.com/go/compute/metadata \
+    cloud.google.com/go/datastore \
+    cloud.google.com/go/errorreporting \
+    cloud.google.com/go/monitoring/apiv3 \
+    cloud.google.com/go/storage \
+    github.com/gliderlabs/ssh \
+    github.com/golang/protobuf/ptypes \
+    github.com/kr/pty \
+    go4.org/syncutil \
+    golang.org/x/crypto/acme/autocert \
+    golang.org/x/crypto/ssh \
+    golang.org/x/oauth2 \
+    golang.org/x/oauth2/google \
+    golang.org/x/perf/storage \
+    golang.org/x/time/rate \
+    google.golang.org/api/compute/v1 \
+    google.golang.org/api/container/v1 \
+    google.golang.org/api/googleapi \
+    google.golang.org/genproto/googleapis/api/metric \
+    google.golang.org/genproto/googleapis/monitoring/v3 \
+    gopkg.in/inf.v0 \
+    grpc.go4.org \
+    && true
+
+# Makefile passes a string with --build-arg version
+# This becomes part of the cache key for all subsequent instructions,
+# so it must not be placed above the "go install" commands above.
+ARG version=unknown
+
+# TODO: ideally we'd first copy all of x/build here EXCEPT
+# cmd/coordinator, then build x/build/..., and *then* COPY in the
+# cmd/coordinator files and then build the final binary. Currently we
+# do too much building of x/build/foo stuff when just modifying
+# cmd/coordinator/*.go files.
+
+COPY . /go/src/golang.org/x/build/
+
+RUN go install -ldflags "-X 'main.Version=$version'" golang.org/x/build/cmd/coordinator
+
+
+FROM debian:stretch AS build_drawterm
+
+RUN apt-get update && apt-get install -y --no-install-recommends \
+    git-core ca-certificates make gcc libc6-dev libx11-dev
 
 # drawterm connects to plan9 instances like:
 #    echo glenda123 | ./drawterm -a <addr> -c <addr> -u glenda -k user=glenda
@@ -25,5 +73,20 @@
     CONF=unix make && mv /tmp/conterm/drawterm /usr/local/bin && \
     rm -rf /tmp/conterm
 
-COPY coordinator /
+
+FROM debian:stretch
+
+# openssh client is for the gomote ssh proxy client.
+# telnet is for the gomote ssh proxy to windows. (no ssh server there)
+RUN apt-get update && apt-get install -y \
+	--no-install-recommends \
+	ca-certificates \
+	openssh-client \
+	telnet \
+	&& rm -rf /var/lib/apt/lists/*
+
+
+COPY --from=build /go/bin/coordinator /
+COPY --from=build_drawterm /usr/local/bin/drawterm /usr/local/bin/
+
 ENTRYPOINT ["/coordinator"]
diff --git a/cmd/coordinator/Dockerfile.0 b/cmd/coordinator/Dockerfile.0
deleted file mode 100644
index d58e575..0000000
--- a/cmd/coordinator/Dockerfile.0
+++ /dev/null
@@ -1,237 +0,0 @@
-# Copyright 2017 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-FROM golang:1.10
-LABEL maintainer "golang-dev@googlegroups.com"
-
-# BEGIN deps (run `make update-deps` to update)
-
-# Repo cloud.google.com/go at 1d0c2da (2018-01-30)
-ENV REV=1d0c2da40456a9b47f5376165f275424acc15c09
-RUN go get -d cloud.google.com/go/bigquery `#and 14 other pkgs` &&\
-    (cd /go/src/cloud.google.com/go && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo github.com/anmitsu/go-shlex at 648efa6 (2016-10-02)
-ENV REV=648efa622239a2f6ff949fed78ee37b48d499ba4
-RUN go get -d github.com/anmitsu/go-shlex &&\
-    (cd /go/src/github.com/anmitsu/go-shlex && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo github.com/gliderlabs/ssh at 3d95f1a (2017-11-12)
-ENV REV=3d95f1a04b0e599e90f3493a39350ecb90ce6686
-RUN go get -d github.com/gliderlabs/ssh &&\
-    (cd /go/src/github.com/gliderlabs/ssh && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo github.com/golang/protobuf at bbd03ef (2018-02-02)
-ENV REV=bbd03ef6da3a115852eaf24c8a1c46aeb39aa175
-RUN go get -d github.com/golang/protobuf/proto `#and 9 other pkgs` &&\
-    (cd /go/src/github.com/golang/protobuf && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo github.com/googleapis/gax-go at 317e000 (2017-09-15)
-ENV REV=317e0006254c44a0ac427cc52a0e083ff0b9622f
-RUN go get -d github.com/googleapis/gax-go &&\
-    (cd /go/src/github.com/googleapis/gax-go && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo github.com/kr/pty at 95d05c1 (2017-10-06)
-ENV REV=95d05c1eef33a45bd58676b6ce28d105839b8d0b
-RUN go get -d github.com/kr/pty &&\
-    (cd /go/src/github.com/kr/pty && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo go4.org at fba789b (2018-01-03)
-ENV REV=fba789b7e39ba524b9e60c45c37a50fae63a2a09
-RUN go get -d go4.org/syncutil &&\
-    (cd /go/src/go4.org && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/crypto at 613d6ea (2018-05-01)
-ENV REV=613d6eafa307c6881a737a3c35c0e312e8d3a8c5
-RUN go get -d golang.org/x/crypto/acme `#and 8 other pkgs` &&\
-    (cd /go/src/golang.org/x/crypto && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/net at a35a21d (2018-04-16)
-ENV REV=a35a21de978d84ffc92f010a153705b170b2f9d1
-RUN go get -d golang.org/x/net/context `#and 9 other pkgs` &&\
-    (cd /go/src/golang.org/x/net && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/oauth2 at cdc340f (2018-05-03)
-ENV REV=cdc340f7c179dbbfa4afd43b7614e8fcadde4269
-RUN go get -d golang.org/x/oauth2 `#and 5 other pkgs` &&\
-    (cd /go/src/golang.org/x/oauth2 && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/perf at ee104fe (2018-01-10)
-ENV REV=ee104fe5b39b63f189a7ac0bbc2f5740094ca063
-RUN go get -d golang.org/x/perf/storage `#and 2 other pkgs` &&\
-    (cd /go/src/golang.org/x/perf && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/sync at fd80eb9 (2017-11-01)
-ENV REV=fd80eb99c8f653c847d294a001bdf2a3a6f768f5
-RUN go get -d golang.org/x/sync/semaphore &&\
-    (cd /go/src/golang.org/x/sync && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/text at b7ef84a (2018-03-02)
-ENV REV=b7ef84aaf62aa3e70962625c80a571ae7c17cb40
-RUN go get -d golang.org/x/text/secure/bidirule `#and 4 other pkgs` &&\
-    (cd /go/src/golang.org/x/text && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo golang.org/x/time at 6dc1736 (2017-09-27)
-ENV REV=6dc17368e09b0e8634d71cac8168d853e869a0c7
-RUN go get -d golang.org/x/time/rate &&\
-    (cd /go/src/golang.org/x/time && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo google.golang.org/api at 7d0e2d3 (2018-01-30)
-ENV REV=7d0e2d350555821bef5a5b8aecf0d12cc1def633
-RUN go get -d google.golang.org/api/bigquery/v2 `#and 16 other pkgs` &&\
-    (cd /go/src/google.golang.org/api && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo google.golang.org/genproto at 4eb30f4 (2018-01-25)
-ENV REV=4eb30f4778eed4c258ba66527a0d4f9ec8a36c45
-RUN go get -d google.golang.org/genproto/googleapis/api/annotations `#and 12 other pkgs` &&\
-    (cd /go/src/google.golang.org/genproto && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo google.golang.org/grpc at 0bd008f (2018-01-25)
-ENV REV=0bd008f5fadb62d228f12b18d016709e8139a7af
-RUN go get -d google.golang.org/grpc `#and 24 other pkgs` &&\
-    (cd /go/src/google.golang.org/grpc && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo gopkg.in/inf.v0 at 3887ee9 (2015-09-11)
-ENV REV=3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
-RUN go get -d gopkg.in/inf.v0 &&\
-    (cd /go/src/gopkg.in/inf.v0 && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Repo grpc.go4.org at 11d0a25 (2017-06-09)
-ENV REV=11d0a25b491971beb5a4625ea7856a3c4afaafa5
-RUN go get -d grpc.go4.org `#and 11 other pkgs` &&\
-    (cd /go/src/grpc.go4.org && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
-
-# Optimization to speed up iterative development, not necessary for correctness:
-RUN go install cloud.google.com/go/bigquery \
-	cloud.google.com/go/civil \
-	cloud.google.com/go/compute/metadata \
-	cloud.google.com/go/datastore \
-	cloud.google.com/go/errorreporting \
-	cloud.google.com/go/errorreporting/apiv1beta1 \
-	cloud.google.com/go/iam \
-	cloud.google.com/go/internal \
-	cloud.google.com/go/internal/atomiccache \
-	cloud.google.com/go/internal/fields \
-	cloud.google.com/go/internal/optional \
-	cloud.google.com/go/internal/version \
-	cloud.google.com/go/monitoring/apiv3 \
-	cloud.google.com/go/storage \
-	github.com/anmitsu/go-shlex \
-	github.com/gliderlabs/ssh \
-	github.com/golang/protobuf/proto \
-	github.com/golang/protobuf/protoc-gen-go/descriptor \
-	github.com/golang/protobuf/ptypes \
-	github.com/golang/protobuf/ptypes/any \
-	github.com/golang/protobuf/ptypes/duration \
-	github.com/golang/protobuf/ptypes/empty \
-	github.com/golang/protobuf/ptypes/struct \
-	github.com/golang/protobuf/ptypes/timestamp \
-	github.com/golang/protobuf/ptypes/wrappers \
-	github.com/googleapis/gax-go \
-	github.com/kr/pty \
-	go4.org/syncutil \
-	golang.org/x/crypto/acme \
-	golang.org/x/crypto/acme/autocert \
-	golang.org/x/crypto/curve25519 \
-	golang.org/x/crypto/ed25519 \
-	golang.org/x/crypto/ed25519/internal/edwards25519 \
-	golang.org/x/crypto/internal/chacha20 \
-	golang.org/x/crypto/poly1305 \
-	golang.org/x/crypto/ssh \
-	golang.org/x/net/context \
-	golang.org/x/net/context/ctxhttp \
-	golang.org/x/net/http/httpguts \
-	golang.org/x/net/http2 \
-	golang.org/x/net/http2/hpack \
-	golang.org/x/net/idna \
-	golang.org/x/net/internal/timeseries \
-	golang.org/x/net/lex/httplex \
-	golang.org/x/net/trace \
-	golang.org/x/oauth2 \
-	golang.org/x/oauth2/google \
-	golang.org/x/oauth2/internal \
-	golang.org/x/oauth2/jws \
-	golang.org/x/oauth2/jwt \
-	golang.org/x/perf/storage \
-	golang.org/x/perf/storage/benchfmt \
-	golang.org/x/sync/semaphore \
-	golang.org/x/text/secure/bidirule \
-	golang.org/x/text/transform \
-	golang.org/x/text/unicode/bidi \
-	golang.org/x/text/unicode/norm \
-	golang.org/x/time/rate \
-	google.golang.org/api/bigquery/v2 \
-	google.golang.org/api/compute/v1 \
-	google.golang.org/api/container/v1 \
-	google.golang.org/api/gensupport \
-	google.golang.org/api/googleapi \
-	google.golang.org/api/googleapi/internal/uritemplates \
-	google.golang.org/api/googleapi/transport \
-	google.golang.org/api/internal \
-	google.golang.org/api/iterator \
-	google.golang.org/api/oauth2/v2 \
-	google.golang.org/api/option \
-	google.golang.org/api/storage/v1 \
-	google.golang.org/api/support/bundler \
-	google.golang.org/api/transport \
-	google.golang.org/api/transport/grpc \
-	google.golang.org/api/transport/http \
-	google.golang.org/genproto/googleapis/api/annotations \
-	google.golang.org/genproto/googleapis/api/distribution \
-	google.golang.org/genproto/googleapis/api/label \
-	google.golang.org/genproto/googleapis/api/metric \
-	google.golang.org/genproto/googleapis/api/monitoredres \
-	google.golang.org/genproto/googleapis/datastore/v1 \
-	google.golang.org/genproto/googleapis/devtools/clouderrorreporting/v1beta1 \
-	google.golang.org/genproto/googleapis/iam/v1 \
-	google.golang.org/genproto/googleapis/monitoring/v3 \
-	google.golang.org/genproto/googleapis/rpc/status \
-	google.golang.org/genproto/googleapis/type/latlng \
-	google.golang.org/genproto/protobuf/field_mask \
-	google.golang.org/grpc \
-	google.golang.org/grpc/balancer \
-	google.golang.org/grpc/balancer/base \
-	google.golang.org/grpc/balancer/roundrobin \
-	google.golang.org/grpc/codes \
-	google.golang.org/grpc/connectivity \
-	google.golang.org/grpc/credentials \
-	google.golang.org/grpc/credentials/oauth \
-	google.golang.org/grpc/encoding \
-	google.golang.org/grpc/encoding/proto \
-	google.golang.org/grpc/grpclb/grpc_lb_v1/messages \
-	google.golang.org/grpc/grpclog \
-	google.golang.org/grpc/internal \
-	google.golang.org/grpc/keepalive \
-	google.golang.org/grpc/metadata \
-	google.golang.org/grpc/naming \
-	google.golang.org/grpc/peer \
-	google.golang.org/grpc/resolver \
-	google.golang.org/grpc/resolver/dns \
-	google.golang.org/grpc/resolver/passthrough \
-	google.golang.org/grpc/stats \
-	google.golang.org/grpc/status \
-	google.golang.org/grpc/tap \
-	google.golang.org/grpc/transport \
-	gopkg.in/inf.v0 \
-	grpc.go4.org \
-	grpc.go4.org/codes \
-	grpc.go4.org/credentials \
-	grpc.go4.org/grpclog \
-	grpc.go4.org/internal \
-	grpc.go4.org/metadata \
-	grpc.go4.org/naming \
-	grpc.go4.org/peer \
-	grpc.go4.org/stats \
-	grpc.go4.org/tap \
-	grpc.go4.org/transport
-# END deps.
-
-# Makefile passes a string with --build-arg version
-# This becomes part of the cache key for all subsequent instructions,
-# so it must not be placed above the "go get" commands above.
-ARG version=unknown
-
-COPY . /go/src/golang.org/x/build/
-
-RUN go install -ldflags "-linkmode=external -extldflags '-static -pthread' -X 'main.Version=$version'" golang.org/x/build/cmd/coordinator
diff --git a/cmd/coordinator/Makefile b/cmd/coordinator/Makefile
index 52eeb22..64370f3 100644
--- a/cmd/coordinator/Makefile
+++ b/cmd/coordinator/Makefile
@@ -20,40 +20,30 @@
 	go install golang.org/x/build/cmd/upload
 	upload --verbose --osarch=linux-amd64 --file=go:golang.org/x/build/cmd/coordinator --public dev-go-builder-data/coordinator
 
-update-deps:
-	go install golang.org/x/build/cmd/gitlock
-	gitlock --update=Dockerfile.0 golang.org/x/build/cmd/coordinator
-
-MUTABLE_VERSION ?= latest
-VERSION ?= $(shell git rev-parse --short HEAD)
+MUTABLE_VERSION := latest
+VERSION := $(shell ./version.sh)
 
 IMAGE_STAGING := gcr.io/go-dashboard-dev/coordinator
 IMAGE_PROD := gcr.io/symbolic-datum-552/coordinator
 
-DOCKER_IMAGE_build0=build0/coordinator:latest
-DOCKER_CTR_build0=coordinator-build0
+DOCKER_IMAGE=golang/coordinator
 
-build0: *.go Dockerfile.0
-	docker build --force-rm -f Dockerfile.0 --build-arg "version=$$(./version.sh)" --tag=$(DOCKER_IMAGE_build0) ../..
+docker: *.go Dockerfile
+	docker build --force-rm -f Dockerfile --build-arg "version=$(VERSION)" --tag=$(DOCKER_IMAGE):$(VERSION) ../..
 
-coordinator: build0
-	docker create --name $(DOCKER_CTR_build0) $(DOCKER_IMAGE_build0)
-	docker cp $(DOCKER_CTR_build0):/go/bin/$@ $@
-	docker rm $(DOCKER_CTR_build0)
-
-docker-prod: Dockerfile coordinator
-	docker build --force-rm --tag=$(IMAGE_PROD):$(VERSION) .
-	docker tag $(IMAGE_PROD):$(VERSION) $(IMAGE_PROD):$(MUTABLE_VERSION)
-docker-staging: Dockerfile coordinator
-	docker build --force-rm --tag=$(IMAGE_STAGING):$(VERSION) .
-	docker tag $(IMAGE_STAGING):$(VERSION) $(IMAGE_STAGING):$(MUTABLE_VERSION)
+docker-prod: docker
+	docker tag $(DOCKER_IMAGE):$(VERSION) $(IMAGE_PROD):$(VERSION)
+	docker tag $(DOCKER_IMAGE):$(VERSION) $(IMAGE_PROD):$(MUTABLE_VERSION)
+docker-staging: docker
+	docker tag $(DOCKER_IMAGE):$(VERSION) $(IMAGE_STAGING):$(VERSION)
+	docker tag $(DOCKER_IMAGE):$(VERSION) $(IMAGE_STAGING):$(MUTABLE_VERSION)
 
 push-prod: docker-prod
-	docker push $(IMAGE_PROD):$(MUTABLE_VERSION)
 	docker push $(IMAGE_PROD):$(VERSION)
+	docker push $(IMAGE_PROD):$(MUTABLE_VERSION)
 push-staging: docker-staging
-	docker push $(IMAGE_STAGING):$(MUTABLE_VERSION)
 	docker push $(IMAGE_STAGING):$(VERSION)
+	docker push $(IMAGE_STAGING):$(MUTABLE_VERSION)
 
 deploy-prod: push-prod
 	go install golang.org/x/build/cmd/xb
@@ -61,7 +51,3 @@
 deploy-staging: push-staging
 	go install golang.org/x/build/cmd/xb
 	xb --staging kubectl set image deployment/coordinator-deployment coordinator=$(IMAGE_STAGING):$(VERSION)
-
-clean: FORCE
-	$(RM) coordinator
-	$(RM) ca-certificates.crt
diff --git a/cmd/coordinator/version.sh b/cmd/coordinator/version.sh
index 95fa79b..4063852 100755
--- a/cmd/coordinator/version.sh
+++ b/cmd/coordinator/version.sh
@@ -11,6 +11,7 @@
   dirty=1
 fi
 if [ -n "$dirty" ] || [ -z "$(git config --get-all "branch.${CURRENT_BRANCH}.remote")" ] || [ -n "$(git rev-list '@{upstream}..HEAD')" ]; then
-  VERSION=$VERSION-$USER-$(date -u +%Y-%m-%dT%H:%M:%SZ)
+  # Append -user-20190509T023926
+  VERSION=$VERSION-$USER-$(git show --quiet --pretty=%cI HEAD | perl -npe 's/[^\dT]//g;$_=substr($_,0,15)')
 fi
 echo "$VERSION"