From 5ac6e03771d42de1fec071bbd6bfc8507609379c Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 17 Jun 2020 13:39:51 -0400 Subject: [PATCH 1/9] all: go2goplay.golang.org source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL contains the altered playground source that is served at go2goplay.golang.org. It compiles the toolchain at the dev.go2go branch of the main Go repository, translates .go2 programs using the go2go tool, and compiles the playground frontend binary using the dev.go2go toolchain (to support code formatting). The header and “About” text is updated to differentiate from the normal playground and explain its differences, code location, etc. Most features present on play.golang.org are missing, and this instance only supports single-file, non-test, main-package programs. This was done for initial simplicity of the implementation. Updates golang/go#39675 Fixes golang/go#39809 Change-Id: Id9461830c4233ab3f938dc6d21da3e5f2d8adbc3 Reviewed-on: https://go-review.googlesource.com/c/playground/+/240541 Reviewed-by: Alexander Rakoczy --- Dockerfile | 19 ++++++++----- Makefile | 8 +++--- README.md | 6 ++-- app.yaml | 4 +-- edit.go | 11 +++++-- edit.html | 71 ++++++++++++++++++++++++++-------------------- examples/clear.txt | 18 ------------ examples/hello.txt | 8 +++++- examples/image.txt | 40 -------------------------- examples/min.txt | 21 ++++++++++++++ examples/queue.txt | 31 ++++++++++++++++++++ fmt.go | 4 ++- sandbox.go | 63 +++++++++++++++++++++++----------------- static/style.css | 6 +++- 14 files changed, 174 insertions(+), 136 deletions(-) delete mode 100644 examples/clear.txt delete mode 100644 examples/image.txt create mode 100644 examples/min.txt create mode 100644 examples/queue.txt diff --git a/Dockerfile b/Dockerfile index 5a314c16..b2162d4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,6 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -ARG GO_VERSION=go1.14.1 - FROM debian:buster AS go-faketime LABEL maintainer="golang-dev@googlegroups.com" @@ -13,8 +11,6 @@ RUN apt-get update && apt-get install -y ${BUILD_DEPS} --no-install-recommends ENV GOPATH /go ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH ENV GO_BOOTSTRAP_VERSION go1.14.1 -ARG GO_VERSION -ENV GO_VERSION ${GO_VERSION} # Get a version of Go for building the playground RUN curl -sSL https://dl.google.com/go/$GO_BOOTSTRAP_VERSION.linux-amd64.tar.gz -o /tmp/go.tar.gz @@ -30,7 +26,7 @@ ENV GOPROXY=https://proxy.golang.org # Compile Go at target sandbox version and install standard library with --tags=faketime. WORKDIR /usr/local -RUN git clone https://go.googlesource.com/go go-faketime && cd go-faketime && git reset --hard $GO_VERSION +RUN git clone https://go.googlesource.com/go go-faketime && cd go-faketime && git checkout dev.go2go WORKDIR /usr/local/go-faketime/src RUN ./make.bash ENV GOROOT /usr/local/go-faketime @@ -38,6 +34,17 @@ RUN ../bin/go install --tags=faketime std FROM golang:1.14 as build-playground +# Compile Go using dev.go2go branch to get go2go-compatible go/format. +WORKDIR /usr/local +RUN git clone https://go.googlesource.com/go go2go && cd go2go && git checkout dev.go2go +WORKDIR /usr/local/go2go/src +RUN ./make.bash +ENV GOROOT /usr/local/go2go + +WORKDIR / + +ENV PATH /usr/local/go2go/bin:$PATH + COPY go.mod /go/src/playground/go.mod COPY go.sum /go/src/playground/go.sum WORKDIR /go/src/playground @@ -55,8 +62,6 @@ RUN apt-get update && apt-get install -y git ca-certificates --no-install-recomm COPY --from=go-faketime /usr/local/go-faketime /usr/local/go-faketime -ARG GO_VERSION -ENV GO_VERSION ${GO_VERSION} ENV GOPATH /go ENV PATH /usr/local/go-faketime/bin:$GOPATH/bin:$PATH diff --git a/Makefile b/Makefile index e670713b..49aa3881 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,12 @@ GCLOUD_ACCESS_TOKEN := $(shell gcloud auth print-access-token) .PHONY: docker test update-cloudbuild-trigger docker: - docker build -t golang/playground . + docker build -t golang/playground-go2go . -runlocal: +runlocal: docker docker network create sandnet || true docker kill play_dev || true - docker run --name=play_dev --rm --network=sandnet -ti -p 127.0.0.1:8081:8080/tcp golang/playground --backend-url="http://sandbox_dev.sandnet/run" + docker run --name=play_dev --rm --network=sandnet -ti -p 127.0.0.1:8081:8080/tcp golang/playground-go2go --backend-url="http://sandbox_dev.sandnet/run" test_go: # Run fast tests first: (and tests whether, say, things compile) @@ -20,7 +20,7 @@ test_go: test_gvisor: docker docker kill sandbox_front_test || true - docker run --rm --name=sandbox_front_test --network=sandnet -t golang/playground --runtests + docker run --rm --name=sandbox_front_test --network=sandnet -t golang/playground-go2go --runtests # Note: test_gvisor is not included in "test" yet, because it requires # running a separate server first ("make runlocal" in the sandbox diff --git a/README.md b/README.md index 5ee85f9a..cf8d4c7c 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,9 @@ Alternatively, to avoid Cloud Build and build locally: ```bash make docker -docker tag golang/playground:latest gcr.io/golang-org/playground:latest -docker push gcr.io/golang-org/playground:latest -gcloud --project=golang-org --account=you@google.com app deploy app.yaml --image-url=gcr.io/golang-org/playground:latest +docker tag golang/playground-go2go:latest gcr.io/golang-org/playground-go2go:latest +docker push gcr.io/golang-org/playground-go2go:latest +gcloud --project=golang-org --account=you@google.com app deploy app.yaml --image-url=gcr.io/golang-org/playground-go2go:latest ``` Then: diff --git a/app.yaml b/app.yaml index 967b168f..d3abb158 100644 --- a/app.yaml +++ b/app.yaml @@ -1,4 +1,4 @@ -service: play +service: go2goplay runtime: custom env: flex @@ -13,7 +13,7 @@ automatic_scaling: min_num_instances: 5 readiness_check: - path: "/_ah/health" + path: '/_ah/health' check_interval_sec: 10 env_variables: diff --git a/edit.go b/edit.go index c8cb9740..cb3a45b2 100644 --- a/edit.go +++ b/edit.go @@ -14,7 +14,8 @@ import ( "cloud.google.com/go/datastore" ) -const hostname = "play.golang.org" +// TODO(golang.org/issue/39675): parameterize before merging. +const hostname = "go2goplay.golang.org" var editTemplate = template.Must(template.ParseFiles("edit.html")) @@ -95,7 +96,13 @@ import ( "fmt" ) +func Print(type T)(s []T) { + for _, v := range s { + fmt.Print(v) + } +} + func main() { - fmt.Println("Hello, playground") + Print([]string{"Hello, ", "playground\n"}) } ` diff --git a/edit.html b/edit.html index 677c2f42..3d5febc7 100644 --- a/edit.html +++ b/edit.html @@ -1,7 +1,7 @@ - The Go Playground + The go2go Playground {{if .Analytics}} @@ -103,7 +103,11 @@