Skip to content

Commit 4dfc99f

Browse files
broadydmitshur
authored andcommitted
[release-branch.go1.11] cmd/godoc: improve deployment scripts, add buildinfo
* Build Go from a given version (make.bash) * Add a /buildinfo file that describes the inputs of the build/deployment. * Use Makefile/environment variables to override Go version and Docker tag. Updates golang/go#28893 Updates golang/go#27205 Change-Id: Ia7a88b75f9d5b2319d2381e56bc963eb53e889c7 Reviewed-on: https://go-review.googlesource.com/c/138978 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-on: https://go-review.googlesource.com/c/150678
1 parent ddbd6be commit 4dfc99f

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
lines changed

cmd/godoc/Dockerfile.prod

+27-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ FROM golang:1.11 AS build
66
RUN apt-get update && apt-get install -y \
77
zip # required for generate-index.bash
88

9-
ENV GODOC_REF release-branch.go1.11
9+
# Check out the desired version of Go, both to build the godoc binary and serve
10+
# as the goroot for content serving.
11+
ARG GO_REF
12+
RUN test -n "$GO_REF" # GO_REF is required.
13+
RUN git clone --single-branch --depth=1 -b $GO_REF https://go.googlesource.com/go /goroot
14+
RUN cd /goroot/src && ./make.bash
15+
16+
ENV GOROOT /goroot
17+
ENV PATH=/goroot/bin:$PATH
18+
19+
RUN go version
1020

1121
RUN go get -v -d \
1222
golang.org/x/net/context \
@@ -18,11 +28,24 @@ RUN go get -v -d \
1828
COPY . /go/src/golang.org/x/tools
1929

2030
WORKDIR /go/src/golang.org/x/tools/cmd/godoc
21-
RUN git clone --single-branch --depth=1 -b $GODOC_REF https://go.googlesource.com/go /docset
22-
RUN GODOC_DOCSET=/docset ./generate-index.bash
31+
RUN GODOC_DOCSET=/goroot ./generate-index.bash
2332

2433
RUN go build -o /godoc -tags=golangorg golang.org/x/tools/cmd/godoc
2534

35+
# Clean up goroot for the final image.
36+
RUN cd /goroot && git clean -xdf
37+
38+
# Add build metadata.
39+
ARG TOOLS_HEAD
40+
ARG TOOLS_CLEAN
41+
ARG DOCKER_TAG
42+
RUN cd /goroot && echo "go repo HEAD: $(git rev-parse HEAD)" >> /goroot/buildinfo
43+
RUN echo "requested go ref: ${GO_REF}" >> /goroot/buildinfo
44+
RUN echo "x/tools HEAD: ${TOOLS_HEAD}" >> /goroot/buildinfo
45+
RUN echo "x/tools clean: ${TOOLS_CLEAN}" >> /goroot/buildinfo
46+
RUN echo "image: ${DOCKER_TAG}" >> /goroot/buildinfo
47+
48+
RUN rm -rf /goroot/.git
2649

2750
# Final image
2851
#############
@@ -33,7 +56,7 @@ WORKDIR /app
3356
COPY --from=build /godoc /app/
3457
COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/hg-git-mapping.bin /app/
3558

36-
COPY --from=build /docset /goroot
59+
COPY --from=build /goroot /goroot
3760
ENV GOROOT /goroot
3861

3962
COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/index.split.* /app/

cmd/godoc/Makefile

+35-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,48 @@
44

55
.PHONY: usage
66

7+
GO_REF ?= release-branch.go1.11
8+
TOOLS_HEAD := $(shell git rev-parse HEAD)
9+
TOOLS_CLEAN := $(shell (git status --porcelain | grep -q .) && echo dirty || echo clean)
10+
ifeq ($(TOOLS_CLEAN),clean)
11+
DOCKER_VERSION ?= $(TOOLS_HEAD)
12+
else
13+
DOCKER_VERSION ?= $(TOOLS_HEAD)-dirty
14+
endif
15+
GCP_PROJECT := golang-org
16+
DOCKER_TAG := gcr.io/$(GCP_PROJECT)/godoc:$(DOCKER_VERSION)
17+
718
usage:
8-
echo "See Makefile"
19+
echo "See Makefile and README.godoc-app"
920
exit 1
1021

11-
docker-prod: Dockerfile.prod
12-
cd ../..; docker build -f cmd/godoc/Dockerfile.prod --tag=gcr.io/golang-org/godoc:$(VERSION) .
22+
docker: Dockerfile.prod
23+
# NOTE(cbro): move up in directory to include entire tools repo.
24+
cd ../..; docker build \
25+
-f cmd/godoc/Dockerfile.prod \
26+
--build-arg GO_REF=$(GO_REF) \
27+
--build-arg TOOLS_HEAD=$(TOOLS_HEAD) \
28+
--build-arg TOOLS_CLEAN=$(TOOLS_CLEAN) \
29+
--build-arg DOCKER_TAG=$(DOCKER_TAG) \
30+
--tag=$(DOCKER_TAG) \
31+
.
1332

14-
push-prod: docker-prod
15-
docker push gcr.io/golang-org/godoc:$(VERSION)
33+
push: docker
34+
docker push $(DOCKER_TAG)
1635

17-
deploy-prod: push-prod
18-
gcloud -q app deploy app.prod.yaml --project golang-org --no-promote --image-url gcr.io/golang-org/godoc:$(VERSION)
36+
deploy: push
37+
gcloud -q app deploy app.prod.yaml \
38+
--project $(GCP_PROJECT) \
39+
--no-promote \
40+
--image-url $(DOCKER_TAG)
1941

2042
get-latest-url:
21-
@gcloud app versions list -s default --project golang-org --sort-by=~version.createTime --format='value(version.versionUrl)' --limit 1 | cut -f1
43+
@gcloud app versions list \
44+
-s default \
45+
--project $(GCP_PROJECT) \
46+
--sort-by=~version.createTime \
47+
--format='value(version.versionUrl)' \
48+
--limit 1 | cut -f1 # NOTE(cbro): gcloud prints out createTime as the second field.
2249

2350
regtest:
2451
./regtest.bash $(shell make get-latest-url)

cmd/godoc/README.godoc-app

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Running locally, in production mode, using Docker
3737

3838
Build the app's Docker container:
3939

40-
VERSION=$(git rev-parse HEAD) make docker-prod
40+
make docker
4141

4242
Make sure redis is running on port 6379:
4343

@@ -68,7 +68,7 @@ Deploying to golang.org
6868

6969
Build the image, push it to gcr.io, and deploy to Flex:
7070

71-
VERSION=$(git rev-parse HEAD) make deploy-prod
71+
make deploy
7272

7373
Run regression tests:
7474

0 commit comments

Comments
 (0)