Skip to content

Commit

Permalink
gotipplay: identify the gotip playground build in the UI
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Alexander Rakoczy <[email protected]>
  • Loading branch information
findleyr committed Nov 17, 2021
1 parent 9bfb5bd commit 6987932
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app.gotip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ readiness_check:

env_variables:
MEMCACHED_ADDR: 'memcached-play-golang:11211'
GOTIP: true

28 changes: 27 additions & 1 deletion edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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())
8 changes: 6 additions & 2 deletions edit.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>The Go Playground</title>
<title>The {{if .Gotip}}Gotip{{else}}Go{{end}} Playground</title>
<link rel="stylesheet" href="/static/style.css">
{{if .Analytics}}
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-11222381-7"></script>
Expand Down Expand Up @@ -103,7 +103,7 @@
<body itemscope itemtype="http://schema.org/CreativeWork">
<input type="button" value="Run" id="embedRun">
<div id="banner">
<div id="head" itemprop="name">The Go Playground</div>
<div id="head" itemprop="name">The {{if .Gotip}}<a href="https://golang.org/dl/gotip">Gotip</a>{{else}}Go{{end}} Playground</div>
<input type="button" value="Run" id="run">
<input type="button" value="Format" id="fmt">
<div id="importsBox">
Expand Down Expand Up @@ -185,7 +185,11 @@
</p>

<p>
{{if .Gotip}}
This playground uses a development version of Go.<br>
{{else}}
The playground uses the latest stable release of Go.<br>
{{end}}
The current version is <a href="/p/Ztyu2FJaajl">{{.GoVersion}}</a>.
</p>

Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func main() {
log.Printf("App (project ID: %q) is NOT caching results", pid)
}
s.log = log
if gotip := os.Getenv("GOTIP"); gotip == "true" {
s.gotip = true
}
return nil
}, enableMetrics)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type server struct {
db store
log logger
cache responseCache
gotip bool // if set, server is using gotip

// When the executable was last modified. Used for caching headers of compiled assets.
modtime time.Time
Expand Down
2 changes: 1 addition & 1 deletion static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ input[type=button],
z-index: 1;
top: 10px;
right: 10px;
}
}

0 comments on commit 6987932

Please sign in to comment.