From 6987932bb9222b19164ec873610ecc944f34a579 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 15 Nov 2021 15:31:49 -0500 Subject: [PATCH] gotipplay: identify the gotip playground build in the UI Attempt to clearly label the Go tip playground as a development build, and surface the version string. For some reason I had to install git in the build-playground phase of the Docker build, to avoid errors from the Go command. I'm not sure why this is, but it seems harmless. For golang/go#48517 Change-Id: I35b150686c9f177d76024cc38ff62cb8785525e0 Reviewed-on: https://go-review.googlesource.com/c/playground/+/363980 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Alexander Rakoczy --- Dockerfile | 2 +- README.md | 12 +++++++++++- app.gotip.yaml | 1 + edit.go | 28 +++++++++++++++++++++++++++- edit.html | 8 ++++++-- main.go | 3 +++ server.go | 1 + static/style.css | 2 +- 8 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6a94f607..af37ec48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,7 +50,7 @@ RUN ./make.bash # Build playground web server. FROM debian:buster as build-playground -RUN apt-get update && apt-get install -y ca-certificates --no-install-recommends +RUN apt-get update && apt-get install -y ca-certificates git --no-install-recommends # Build playground from Go built at GO_VERSION. COPY --from=build-go /usr/local/go /usr/local/go ENV GOROOT /usr/local/go diff --git a/README.md b/README.md index 5001f98c..b145b8c6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ docker run --name=play --rm -p 8080:8080 golang/playground & cat /path/to/code.go | go run client.go | curl -s --upload-file - localhost:8080/compile ``` +To run the "gotip" version of the playground, set `GOTIP=true` +in your environment (via `-e GOTIP=true` if using `docker run`). + ## Deployment ### Deployment Triggers @@ -39,7 +42,14 @@ using the `push-cloudbuild-trigger` and `pull-cloudbuild-trigger` make targets. The Cloud Build configuration will always build and deploy with the latest supported release of Go. ```bash -gcloud builds submit --config deploy/deploy.json . +gcloud --project=golang-org builds submit --config deploy/deploy.json . +``` + +To deploy the "Go tip" version of the playground, which uses the latest +development build, use `deploy_gotip.json` instead: + +```bash +gcloud --project=golang-org builds submit --config deploy/deploy_gotip.json . ``` ### Deploy via gcloud app deploy diff --git a/app.gotip.yaml b/app.gotip.yaml index 5894c9e1..2e129bcf 100644 --- a/app.gotip.yaml +++ b/app.gotip.yaml @@ -18,4 +18,5 @@ readiness_check: env_variables: MEMCACHED_ADDR: 'memcached-play-golang:11211' + GOTIP: true diff --git a/edit.go b/edit.go index c8cb9740..3d63848c 100644 --- a/edit.go +++ b/edit.go @@ -23,6 +23,7 @@ type editData struct { Share bool Analytics bool GoVersion string + Gotip bool } func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) { @@ -44,7 +45,11 @@ func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) { return } - snip := &snippet{Body: []byte(hello)} + content := hello + if s.gotip { + content = helloGotip + } + snip := &snippet{Body: []byte(content)} if strings.HasPrefix(r.URL.Path, "/p/") { if !allowShare(r) { w.WriteHeader(http.StatusUnavailableForLegalReasons) @@ -82,6 +87,7 @@ func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) { Share: allowShare(r), Analytics: r.Host == hostname, GoVersion: runtime.Version(), + Gotip: s.gotip, } if err := editTemplate.Execute(w, data); err != nil { s.log.Errorf("editTemplate.Execute(w, %+v): %v", data, err) @@ -99,3 +105,23 @@ func main() { fmt.Println("Hello, playground") } ` + +var helloGotip = fmt.Sprintf(`package main + +import ( + "fmt" +) + +// This playground uses a development build of Go: +// %s + +func Print[T any](s ...T) { + for _, v := range s { + fmt.Print(v) + } +} + +func main() { + Print("Hello, ", "playground\n") +} +`, runtime.Version()) diff --git a/edit.html b/edit.html index 14b5e4b5..bf5e4df4 100644 --- a/edit.html +++ b/edit.html @@ -1,7 +1,7 @@ - The Go Playground + The {{if .Gotip}}Gotip{{else}}Go{{end}} Playground {{if .Analytics}} @@ -103,7 +103,7 @@