[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
This commit is contained in:
Chris Broadfoot 2018-10-02 02:08:51 -07:00 committed by Dmitri Shuralyov
parent ddbd6bea01
commit 4dfc99feba
3 changed files with 64 additions and 14 deletions

View File

@ -6,7 +6,17 @@ FROM golang:1.11 AS build
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
zip # required for generate-index.bash zip # required for generate-index.bash
ENV GODOC_REF release-branch.go1.11 # Check out the desired version of Go, both to build the godoc binary and serve
# as the goroot for content serving.
ARG GO_REF
RUN test -n "$GO_REF" # GO_REF is required.
RUN git clone --single-branch --depth=1 -b $GO_REF https://go.googlesource.com/go /goroot
RUN cd /goroot/src && ./make.bash
ENV GOROOT /goroot
ENV PATH=/goroot/bin:$PATH
RUN go version
RUN go get -v -d \ RUN go get -v -d \
golang.org/x/net/context \ golang.org/x/net/context \
@ -18,11 +28,24 @@ RUN go get -v -d \
COPY . /go/src/golang.org/x/tools COPY . /go/src/golang.org/x/tools
WORKDIR /go/src/golang.org/x/tools/cmd/godoc WORKDIR /go/src/golang.org/x/tools/cmd/godoc
RUN git clone --single-branch --depth=1 -b $GODOC_REF https://go.googlesource.com/go /docset RUN GODOC_DOCSET=/goroot ./generate-index.bash
RUN GODOC_DOCSET=/docset ./generate-index.bash
RUN go build -o /godoc -tags=golangorg golang.org/x/tools/cmd/godoc RUN go build -o /godoc -tags=golangorg golang.org/x/tools/cmd/godoc
# Clean up goroot for the final image.
RUN cd /goroot && git clean -xdf
# Add build metadata.
ARG TOOLS_HEAD
ARG TOOLS_CLEAN
ARG DOCKER_TAG
RUN cd /goroot && echo "go repo HEAD: $(git rev-parse HEAD)" >> /goroot/buildinfo
RUN echo "requested go ref: ${GO_REF}" >> /goroot/buildinfo
RUN echo "x/tools HEAD: ${TOOLS_HEAD}" >> /goroot/buildinfo
RUN echo "x/tools clean: ${TOOLS_CLEAN}" >> /goroot/buildinfo
RUN echo "image: ${DOCKER_TAG}" >> /goroot/buildinfo
RUN rm -rf /goroot/.git
# Final image # Final image
############# #############
@ -33,7 +56,7 @@ WORKDIR /app
COPY --from=build /godoc /app/ COPY --from=build /godoc /app/
COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/hg-git-mapping.bin /app/ COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/hg-git-mapping.bin /app/
COPY --from=build /docset /goroot COPY --from=build /goroot /goroot
ENV GOROOT /goroot ENV GOROOT /goroot
COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/index.split.* /app/ COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/index.split.* /app/

View File

@ -4,21 +4,48 @@
.PHONY: usage .PHONY: usage
GO_REF ?= release-branch.go1.11
TOOLS_HEAD := $(shell git rev-parse HEAD)
TOOLS_CLEAN := $(shell (git status --porcelain | grep -q .) && echo dirty || echo clean)
ifeq ($(TOOLS_CLEAN),clean)
DOCKER_VERSION ?= $(TOOLS_HEAD)
else
DOCKER_VERSION ?= $(TOOLS_HEAD)-dirty
endif
GCP_PROJECT := golang-org
DOCKER_TAG := gcr.io/$(GCP_PROJECT)/godoc:$(DOCKER_VERSION)
usage: usage:
echo "See Makefile" echo "See Makefile and README.godoc-app"
exit 1 exit 1
docker-prod: Dockerfile.prod docker: Dockerfile.prod
cd ../..; docker build -f cmd/godoc/Dockerfile.prod --tag=gcr.io/golang-org/godoc:$(VERSION) . # NOTE(cbro): move up in directory to include entire tools repo.
cd ../..; docker build \
-f cmd/godoc/Dockerfile.prod \
--build-arg GO_REF=$(GO_REF) \
--build-arg TOOLS_HEAD=$(TOOLS_HEAD) \
--build-arg TOOLS_CLEAN=$(TOOLS_CLEAN) \
--build-arg DOCKER_TAG=$(DOCKER_TAG) \
--tag=$(DOCKER_TAG) \
.
push-prod: docker-prod push: docker
docker push gcr.io/golang-org/godoc:$(VERSION) docker push $(DOCKER_TAG)
deploy-prod: push-prod deploy: push
gcloud -q app deploy app.prod.yaml --project golang-org --no-promote --image-url gcr.io/golang-org/godoc:$(VERSION) gcloud -q app deploy app.prod.yaml \
--project $(GCP_PROJECT) \
--no-promote \
--image-url $(DOCKER_TAG)
get-latest-url: get-latest-url:
@gcloud app versions list -s default --project golang-org --sort-by=~version.createTime --format='value(version.versionUrl)' --limit 1 | cut -f1 @gcloud app versions list \
-s default \
--project $(GCP_PROJECT) \
--sort-by=~version.createTime \
--format='value(version.versionUrl)' \
--limit 1 | cut -f1 # NOTE(cbro): gcloud prints out createTime as the second field.
regtest: regtest:
./regtest.bash $(shell make get-latest-url) ./regtest.bash $(shell make get-latest-url)

View File

@ -37,7 +37,7 @@ Running locally, in production mode, using Docker
Build the app's Docker container: Build the app's Docker container:
VERSION=$(git rev-parse HEAD) make docker-prod make docker
Make sure redis is running on port 6379: Make sure redis is running on port 6379:
@ -68,7 +68,7 @@ Deploying to golang.org
Build the image, push it to gcr.io, and deploy to Flex: Build the image, push it to gcr.io, and deploy to Flex:
VERSION=$(git rev-parse HEAD) make deploy-prod make deploy
Run regression tests: Run regression tests: