Skip to content

Commit d790a2e

Browse files
committed
all: fix build timeouts for std dependent snippets
This change addresses two issues that were causing the first build of a snippet to be unusually slow. One is to build the standard library with faketime, and CGO_ENABLED=0 in our final container, which is more similar to our actual build environment. This fixes staleness issues from std. Another is to pre-vet std with --tags=faketime. The first vet of a snippet that contained a significant std package such as net/http would take 5-6 seconds, and frequently longer than our maxBuildTime of 10s. Finally, execute vet with the correct tags when a user is vetting their snippet. Fixes golang/go#44822 Change-Id: Ie5674bb6aa5f79694bffc6902c46297ac553419a Reviewed-on: https://go-review.googlesource.com/c/playground/+/337010 Trust: Alexander Rakoczy <alex@golang.org> Run-TryBot: Alexander Rakoczy <alex@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
1 parent 541c3c3 commit d790a2e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ RUN git clone https://go.googlesource.com/go go && cd go && git reset --hard $GO
4646
WORKDIR /usr/local/go/src
4747
RUN ./make.bash
4848

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
52-
ENV GOROOT /usr/local/go-faketime
53-
WORKDIR /usr/local/go-faketime/src
54-
RUN ../bin/go install --tags=faketime std
55-
5649
############################################################################
5750
# Build playground web server.
5851
FROM debian:buster as build-playground
@@ -79,13 +72,24 @@ FROM debian:buster
7972

8073
RUN apt-get update && apt-get install -y git ca-certificates --no-install-recommends
8174

82-
COPY --from=build-go /usr/local/go-faketime /usr/local/go-faketime
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
8378

79+
ENV CGO_ENABLED 0
80+
ENV GOPATH /go
81+
ENV GOROOT /usr/local/go-faketime
8482
ARG GO_VERSION
8583
ENV GO_VERSION ${GO_VERSION}
86-
ENV GOPATH /go
8784
ENV PATH="/go/bin:/usr/local/go-faketime/bin:${PATH}"
8885

86+
WORKDIR /usr/local/go-faketime
87+
RUN ./bin/go install --tags=faketime std
88+
# Ignore the exit code. go vet std does not pass vet with the faketime
89+
# patches, but it successfully caches results for when we vet user
90+
# snippets.
91+
RUN ./bin/go vet --tags=faketime std || true
92+
8993
RUN mkdir /app
9094
COPY --from=build-playground /go/bin/playground /app
9195
COPY edit.html /app

vet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func vetCheckInDir(ctx context.Context, dir, goPath string) (output string, exec
6363
mGoVetLatency.M(float64(time.Since(start))/float64(time.Millisecond)))
6464
}()
6565

66-
cmd := exec.Command("go", "vet")
66+
cmd := exec.Command("go", "vet", "--tags=faketime")
6767
cmd.Dir = dir
6868
// Linux go binary is not built with CGO_ENABLED=0.
6969
// Prevent vet to compile packages in cgo mode.

0 commit comments

Comments
 (0)