playground: use Go 1.12

Go 1.12 has been released┬╣ and should be used, so that it's possible
to play with Go programs that rely on Go 1.12-only features.

In Go 1.12, build cache is required. Either GOCACHE must be set,
or HOME must be set so that GOCACHE can be implicitly deduced.
Set HOME and pass it on to the go build invocation inside the
compileAndRun function.

This fixes the following error, detected by the playground test:

	2019/02/26 06:28:44 compile error: build cache is required, but could not
	be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME
	are defined
	The command '/bin/sh -c /app/playground test' returned a non-zero code: 1

This is related to issues golang/go#29243 and golang/go#29251,
and the fix in CL 154181.


Fixes golang/go#30397

Change-Id: I44c5c8928060732f31fd935b114568258c7298c7
Reviewed-by: Brad Fitzpatrick <>
diff --git a/Dockerfile b/Dockerfile
index 646866d..30453d1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -8,7 +8,7 @@
 ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH
 ENV GOROOT_BOOTSTRAP /usr/local/gobootstrap
 ENV BUILD_DEPS 'curl bzip2 git gcc patch libc6-dev ca-certificates'
 # Fake time
@@ -174,6 +174,10 @@
 COPY --from=builder /usr/local/go /usr/local/go
 COPY --from=builder /tmp/sel_ldr_x86_64 /usr/local/bin
+# For implicit GOCACHE (issues 29243 and 29251), set HOME:
+RUN mkdir -p /home/gopher
+ENV HOME /home/gopher
 ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH
diff --git a/sandbox.go b/sandbox.go
index 7fb6964..8e21a96 100644
--- a/sandbox.go
+++ b/sandbox.go
@@ -324,7 +324,7 @@
 	exe := filepath.Join(tmpDir, "a.out")
 	cmd := exec.Command("go", "build", "-o", exe, in)
-	cmd.Env = []string{"GOOS=nacl", "GOARCH=amd64p32", "GOPATH=" + os.Getenv("GOPATH")}
+	cmd.Env = []string{"GOOS=nacl", "GOARCH=amd64p32", "GOPATH=" + os.Getenv("GOPATH"), "HOME=" + os.Getenv("HOME")}
 	if out, err := cmd.CombinedOutput(); err != nil {
 		if _, ok := err.(*exec.ExitError); ok {
 			// Return compile errors to the user.