golang.org/x/playground@v0.0.0-20230418134305-14ebe15bcd59/Dockerfile (about)

     1  # Copyright 2017 The Go Authors. All rights reserved.
     2  # Use of this source code is governed by a BSD-style
     3  # license that can be found in the LICENSE file.
     4  
     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.
    10  
    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.19
    14  
    15  ############################################################################
    16  # Build Go at GO_VERSION, and build faketime standard library.
    17  FROM debian:buster AS build-go
    18  LABEL maintainer="golang-dev@googlegroups.com"
    19  
    20  ENV BUILD_DEPS 'curl git gcc patch libc6-dev ca-certificates'
    21  RUN apt-get update && apt-get install -y ${BUILD_DEPS} --no-install-recommends
    22  
    23  ENV GOPATH /go
    24  ENV GOROOT_BOOTSTRAP=/usr/local/go-bootstrap
    25  ENV GO_BOOTSTRAP_VERSION go1.18
    26  ARG GO_VERSION
    27  ENV GO_VERSION ${GO_VERSION}
    28  
    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.
    32  RUN curl -sSL https://dl.google.com/go/$GO_BOOTSTRAP_VERSION.linux-amd64.tar.gz -o /tmp/go.tar.gz
    33  RUN curl -sSL https://dl.google.com/go/$GO_BOOTSTRAP_VERSION.linux-amd64.tar.gz.sha256 -o /tmp/go.tar.gz.sha256
    34  RUN echo "$(cat /tmp/go.tar.gz.sha256) /tmp/go.tar.gz" | sha256sum -c -
    35  RUN mkdir -p $GOROOT_BOOTSTRAP
    36  RUN tar --strip=1 -C $GOROOT_BOOTSTRAP -vxzf /tmp/go.tar.gz
    37  
    38  RUN mkdir /gocache
    39  ENV GOCACHE /gocache
    40  ENV GO111MODULE on
    41  ENV GOPROXY=https://proxy.golang.org
    42  
    43  # Compile Go at target version in /usr/local/go.
    44  WORKDIR /usr/local
    45  RUN git clone https://go.googlesource.com/go go && cd go && git reset --hard $GO_VERSION
    46  WORKDIR /usr/local/go/src
    47  RUN ./make.bash
    48  
    49  ############################################################################
    50  # Build playground web server.
    51  FROM debian:buster as build-playground
    52  
    53  RUN apt-get update && apt-get install -y ca-certificates git --no-install-recommends
    54  # Build playground from Go built at GO_VERSION.
    55  COPY --from=build-go /usr/local/go /usr/local/go
    56  ENV GOROOT /usr/local/go
    57  ENV GOPATH /go
    58  ENV PATH="/go/bin:/usr/local/go/bin:${PATH}"
    59  # Cache dependencies for efficient Dockerfile building.
    60  COPY go.mod /go/src/playground/go.mod
    61  COPY go.sum /go/src/playground/go.sum
    62  WORKDIR /go/src/playground
    63  RUN go mod download
    64  
    65  # Add and compile playground daemon.
    66  COPY . /go/src/playground/
    67  RUN go install
    68  
    69  ############################################################################
    70  # Final stage.
    71  FROM debian:buster
    72  
    73  RUN apt-get update && apt-get install -y git ca-certificates --no-install-recommends
    74  
    75  # Make a copy in /usr/local/go-faketime where the standard library
    76  # is installed with -tags=faketime.
    77  COPY --from=build-go /usr/local/go /usr/local/go-faketime
    78  
    79  ENV CGO_ENABLED 0
    80  ENV GOPATH /go
    81  ENV GOROOT /usr/local/go-faketime
    82  ARG GO_VERSION
    83  ENV GO_VERSION ${GO_VERSION}
    84  ENV PATH="/go/bin:/usr/local/go-faketime/bin:${PATH}"
    85  
    86  WORKDIR /usr/local/go-faketime
    87  # golang/go#57495: install std to warm the build cache. We only set
    88  # GOCACHE=/gocache here to keep it as small as possible, since it must be
    89  # copied on every build.
    90  RUN GOCACHE=/gocache ./bin/go install --tags=faketime std
    91  # Ignore the exit code. go vet std does not pass vet with the faketime
    92  # patches, but it successfully caches results for when we vet user
    93  # snippets.
    94  RUN ./bin/go vet --tags=faketime std || true
    95  
    96  RUN mkdir /app
    97  COPY --from=build-playground /go/bin/playground /app
    98  COPY edit.html /app
    99  COPY static /app/static
   100  COPY examples /app/examples
   101  WORKDIR /app
   102  
   103  EXPOSE 8080
   104  ENTRYPOINT ["/app/playground"]