22# Use of this source code is governed by a BSD-style
33# license that can be found in the LICENSE file.
44
5- ARG GO_VERSION=go1.14.1
5+ # The playground builds Go from a bootstrap version for two reasons:
6+ # - The playground deployment is triggered before the artifacts are
7+ # published for the latest version of Go.
8+ # - The sandbox builds the Go standard library with a custom build
9+ # flag called faketime.
610
7- FROM debian:buster AS go-faketime
11+ # GO_VERSION is provided by Cloud Build, and is set to the latest
12+ # version of Go. See the configuration in the deploy directory.
13+ ARG GO_VERSION=go1.16
14+
15+ # ###########################################################################
16+ # Build Go at GO_VERSION, and build faketime standard library.
17+ FROM debian:buster AS build-go
818LABEL maintainer="golang-dev@googlegroups.com"
919
1020ENV BUILD_DEPS 'curl git gcc patch libc6-dev ca-certificates'
1121RUN apt-get update && apt-get install -y ${BUILD_DEPS} --no-install-recommends
1222
1323ENV GOPATH /go
14- ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH
15- ENV GO_BOOTSTRAP_VERSION go1.14.1
24+ ENV GOROOT_BOOTSTRAP= /usr/local/go-bootstrap
25+ ENV GO_BOOTSTRAP_VERSION go1.16
1626ARG GO_VERSION
1727ENV GO_VERSION ${GO_VERSION}
1828
19- # Get a version of Go for building the playground
29+ # Get a bootstrap version of Go for building GO_VERSION. At the time
30+ # of this Dockerfile being built, GO_VERSION's artifacts may not yet
31+ # be published.
2032RUN curl -sSL https://dl.google.com/go/$GO_BOOTSTRAP_VERSION.linux-amd64.tar.gz -o /tmp/go.tar.gz
2133RUN curl -sSL https://dl.google.com/go/$GO_BOOTSTRAP_VERSION.linux-amd64.tar.gz.sha256 -o /tmp/go.tar.gz.sha256
2234RUN echo "$(cat /tmp/go.tar.gz.sha256) /tmp/go.tar.gz" | sha256sum -c -
23- RUN mkdir -p /usr/local/go
24- RUN tar --strip=1 -C /usr/local/go -vxzf /tmp/go.tar.gz
35+ RUN mkdir -p $GOROOT_BOOTSTRAP
36+ RUN tar --strip=1 -C $GOROOT_BOOTSTRAP -vxzf /tmp/go.tar.gz
2537
2638RUN mkdir /gocache
2739ENV GOCACHE /gocache
2840ENV GO111MODULE on
2941ENV GOPROXY=https://proxy.golang.org
3042
31- # Compile Go at target sandbox version and install standard library with --tags=faketime .
43+ # Compile Go at target version in /usr/local/go .
3244WORKDIR /usr/local
33- RUN git clone https://go.googlesource.com/go go-faketime && cd go-faketime && git reset --hard $GO_VERSION
34- WORKDIR /usr/local/go-faketime /src
45+ RUN git clone https://go.googlesource.com/go go && cd go && git reset --hard $GO_VERSION
46+ WORKDIR /usr/local/go/src
3547RUN ./make.bash
48+
49+ # Make a copy in /usr/local/go-faketime where the standard library
50+ # is installed with -tags=faketime.
51+ RUN cp -R /usr/local/go /usr/local/go-faketime
3652ENV GOROOT /usr/local/go-faketime
53+ WORKDIR /usr/local/go-faketime/src
3754RUN ../bin/go install --tags=faketime std
3855
39- FROM golang:1.14 as build-playground
56+ # ###########################################################################
57+ # Build playground web server.
58+ FROM debian:buster as build-playground
4059
60+ RUN apt-get update && apt-get install -y ca-certificates --no-install-recommends
61+ # Build playground from Go built at GO_VERSION.
62+ COPY --from=build-go /usr/local/go /usr/local/go
63+ ENV GOROOT /usr/local/go
64+ ENV GOPATH /go
65+ ENV PATH="/go/bin:/usr/local/go/bin:${PATH}"
66+ # Cache dependencies for efficient Dockerfile building.
4167COPY go.mod /go/src/playground/go.mod
4268COPY go.sum /go/src/playground/go.sum
4369WORKDIR /go/src/playground
4470RUN go mod download
4571
46- # Add and compile playground daemon
72+ # Add and compile playground daemon.
4773COPY . /go/src/playground/
4874RUN go install
4975
@@ -53,43 +79,19 @@ FROM debian:buster
5379
5480RUN apt-get update && apt-get install -y git ca-certificates --no-install-recommends
5581
56- COPY --from=go-faketime /usr/local/go-faketime /usr/local/go-faketime
82+ COPY --from=build-go /usr/local/go-faketime /usr/local/go-faketime
5783
5884ARG GO_VERSION
5985ENV GO_VERSION ${GO_VERSION}
6086ENV GOPATH /go
61- ENV PATH /usr/local/go-faketime/bin:$GOPATH/bin:$PATH
62-
63- # Add and compile tour packages
64- RUN go get \
65- golang.org/x/tour/pic \
66- golang.org/x/tour/reader \
67- golang.org/x/tour/tree \
68- golang.org/x/tour/wc \
69- golang.org/x/talks/content/2016/applicative/google && \
70- rm -rf $GOPATH/src/golang.org/x/tour/.git && \
71- rm -rf $GOPATH/src/golang.org/x/talks/.git
72-
73- # Add tour packages under their old import paths (so old snippets still work)
74- RUN mkdir -p $GOPATH/src/code.google.com/p/go-tour && \
75- cp -R $GOPATH/src/golang.org/x/tour/* $GOPATH/src/code.google.com/p/go-tour/ && \
76- sed -i 's_// import_// public import_' $(find $GOPATH/src/code.google.com/p/go-tour/ -name *.go) && \
77- go install \
78- code.google.com/p/go-tour/pic \
79- code.google.com/p/go-tour/reader \
80- code.google.com/p/go-tour/tree \
81- code.google.com/p/go-tour/wc
87+ ENV PATH="/go/bin:/usr/local/go-faketime/bin:${PATH}"
8288
8389RUN mkdir /app
84-
8590COPY --from=build-playground /go/bin/playground /app
8691COPY edit.html /app
8792COPY static /app/static
8893COPY examples /app/examples
8994WORKDIR /app
9095
91- # Whether we allow third-party imports via proxy.golang.org:
92- ENV ALLOW_PLAY_MODULE_DOWNLOADS true
93-
9496EXPOSE 8080
9597ENTRYPOINT ["/app/playground" ]
0 commit comments