all: fix build timeouts for std dependent snippets

This change addresses two issues that were causing the first build of a
snippet to be unusually slow.

One is to build the standard library with faketime, and CGO_ENABLED=0 in
our final container, which is more similar to our actual build
environment. This fixes staleness issues from std.

Another is to pre-vet std with --tags=faketime. The first vet of a
snippet that contained a significant std package such as net/http would
take 5-6 seconds, and frequently longer than our maxBuildTime of 10s.

Finally, execute vet with the correct tags when a user is vetting their
snippet.

Fixes golang/go#44822

Change-Id: Ie5674bb6aa5f79694bffc6902c46297ac553419a
Reviewed-on: https://go-review.googlesource.com/c/playground/+/337010
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/Dockerfile b/Dockerfile
index f779131..6a94f60 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -46,13 +46,6 @@
 WORKDIR /usr/local/go/src
 RUN ./make.bash
 
-# Make a copy in /usr/local/go-faketime where the standard library
-# is installed with -tags=faketime.
-RUN cp -R /usr/local/go /usr/local/go-faketime
-ENV GOROOT /usr/local/go-faketime
-WORKDIR /usr/local/go-faketime/src
-RUN ../bin/go install --tags=faketime std
-
 ############################################################################
 # Build playground web server.
 FROM debian:buster as build-playground
@@ -79,13 +72,24 @@
 
 RUN apt-get update && apt-get install -y git ca-certificates --no-install-recommends
 
-COPY --from=build-go /usr/local/go-faketime /usr/local/go-faketime
+# Make a copy in /usr/local/go-faketime where the standard library
+# is installed with -tags=faketime.
+COPY --from=build-go /usr/local/go /usr/local/go-faketime
 
+ENV CGO_ENABLED 0
+ENV GOPATH /go
+ENV GOROOT /usr/local/go-faketime
 ARG GO_VERSION
 ENV GO_VERSION ${GO_VERSION}
-ENV GOPATH /go
 ENV PATH="/go/bin:/usr/local/go-faketime/bin:${PATH}"
 
+WORKDIR /usr/local/go-faketime
+RUN ./bin/go install --tags=faketime std
+# Ignore the exit code. go vet std does not pass vet with the faketime
+# patches, but it successfully caches results for when we vet user
+# snippets.
+RUN ./bin/go vet --tags=faketime std || true
+
 RUN mkdir /app
 COPY --from=build-playground /go/bin/playground /app
 COPY edit.html /app
diff --git a/vet.go b/vet.go
index 45c9175..87cf3bc 100644
--- a/vet.go
+++ b/vet.go
@@ -63,7 +63,7 @@
 			mGoVetLatency.M(float64(time.Since(start))/float64(time.Millisecond)))
 	}()
 
-	cmd := exec.Command("go", "vet")
+	cmd := exec.Command("go", "vet", "--tags=faketime")
 	cmd.Dir = dir
 	// Linux go binary is not built with CGO_ENABLED=0.
 	// Prevent vet to compile packages in cgo mode.