Skip to content

Commit 6987932

Browse files
committed
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 <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org>
1 parent 9bfb5bd commit 6987932

File tree

8 files changed

+51
-6
lines changed

8 files changed

+51
-6
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ RUN ./make.bash
5050
# Build playground web server.
5151
FROM debian:buster as build-playground
5252

53-
RUN apt-get update && apt-get install -y ca-certificates --no-install-recommends
53+
RUN apt-get update && apt-get install -y ca-certificates git --no-install-recommends
5454
# Build playground from Go built at GO_VERSION.
5555
COPY --from=build-go /usr/local/go /usr/local/go
5656
ENV GOROOT /usr/local/go

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ docker run --name=play --rm -p 8080:8080 golang/playground &
2020
cat /path/to/code.go | go run client.go | curl -s --upload-file - localhost:8080/compile
2121
```
2222

23+
To run the "gotip" version of the playground, set `GOTIP=true`
24+
in your environment (via `-e GOTIP=true` if using `docker run`).
25+
2326
## Deployment
2427

2528
### Deployment Triggers
@@ -39,7 +42,14 @@ using the `push-cloudbuild-trigger` and `pull-cloudbuild-trigger` make targets.
3942
The Cloud Build configuration will always build and deploy with the latest supported release of Go.
4043

4144
```bash
42-
gcloud builds submit --config deploy/deploy.json .
45+
gcloud --project=golang-org builds submit --config deploy/deploy.json .
46+
```
47+
48+
To deploy the "Go tip" version of the playground, which uses the latest
49+
development build, use `deploy_gotip.json` instead:
50+
51+
```bash
52+
gcloud --project=golang-org builds submit --config deploy/deploy_gotip.json .
4353
```
4454

4555
### Deploy via gcloud app deploy

app.gotip.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ readiness_check:
1818

1919
env_variables:
2020
MEMCACHED_ADDR: 'memcached-play-golang:11211'
21+
GOTIP: true
2122

edit.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type editData struct {
2323
Share bool
2424
Analytics bool
2525
GoVersion string
26+
Gotip bool
2627
}
2728

2829
func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) {
@@ -44,7 +45,11 @@ func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) {
4445
return
4546
}
4647

47-
snip := &snippet{Body: []byte(hello)}
48+
content := hello
49+
if s.gotip {
50+
content = helloGotip
51+
}
52+
snip := &snippet{Body: []byte(content)}
4853
if strings.HasPrefix(r.URL.Path, "/p/") {
4954
if !allowShare(r) {
5055
w.WriteHeader(http.StatusUnavailableForLegalReasons)
@@ -82,6 +87,7 @@ func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) {
8287
Share: allowShare(r),
8388
Analytics: r.Host == hostname,
8489
GoVersion: runtime.Version(),
90+
Gotip: s.gotip,
8591
}
8692
if err := editTemplate.Execute(w, data); err != nil {
8793
s.log.Errorf("editTemplate.Execute(w, %+v): %v", data, err)
@@ -99,3 +105,23 @@ func main() {
99105
fmt.Println("Hello, playground")
100106
}
101107
`
108+
109+
var helloGotip = fmt.Sprintf(`package main
110+
111+
import (
112+
"fmt"
113+
)
114+
115+
// This playground uses a development build of Go:
116+
// %s
117+
118+
func Print[T any](s ...T) {
119+
for _, v := range s {
120+
fmt.Print(v)
121+
}
122+
}
123+
124+
func main() {
125+
Print("Hello, ", "playground\n")
126+
}
127+
`, runtime.Version())

edit.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<title>The Go Playground</title>
4+
<title>The {{if .Gotip}}Gotip{{else}}Go{{end}} Playground</title>
55
<link rel="stylesheet" href="/static/style.css">
66
{{if .Analytics}}
77
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-11222381-7"></script>
@@ -103,7 +103,7 @@
103103
<body itemscope itemtype="http://schema.org/CreativeWork">
104104
<input type="button" value="Run" id="embedRun">
105105
<div id="banner">
106-
<div id="head" itemprop="name">The Go Playground</div>
106+
<div id="head" itemprop="name">The {{if .Gotip}}<a href="https://golang.org/dl/gotip">Gotip</a>{{else}}Go{{end}} Playground</div>
107107
<input type="button" value="Run" id="run">
108108
<input type="button" value="Format" id="fmt">
109109
<div id="importsBox">
@@ -185,7 +185,11 @@
185185
</p>
186186

187187
<p>
188+
{{if .Gotip}}
189+
This playground uses a development version of Go.<br>
190+
{{else}}
188191
The playground uses the latest stable release of Go.<br>
192+
{{end}}
189193
The current version is <a href="/p/Ztyu2FJaajl">{{.GoVersion}}</a>.
190194
</p>
191195

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func main() {
4444
log.Printf("App (project ID: %q) is NOT caching results", pid)
4545
}
4646
s.log = log
47+
if gotip := os.Getenv("GOTIP"); gotip == "true" {
48+
s.gotip = true
49+
}
4750
return nil
4851
}, enableMetrics)
4952
if err != nil {

server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type server struct {
1919
db store
2020
log logger
2121
cache responseCache
22+
gotip bool // if set, server is using gotip
2223

2324
// When the executable was last modified. Used for caching headers of compiled assets.
2425
modtime time.Time

static/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@ input[type=button],
182182
z-index: 1;
183183
top: 10px;
184184
right: 10px;
185-
}
185+
}

0 commit comments

Comments
 (0)