Skip to content

Commit da9e5cc

Browse files
committed
x/website: add code and static files for website
All of the code and static assets that the website uses to run have been copied to this repo. There was also a few lines of code added telling the website where the doc directory, favicon.ico and robots.txt are. go repo change-id: Ife6443c32673b38000b90dd2efb2985db37ab773 x/tools repo change-id: Ia979a8b06d1b4db47d25ffdfdf925ba8a0ac67de Real new code additions: - main.go * lines 89-95 added getFullPath method * lines 217-222 mapped paths to doc/, favicon.ico, robots.txt in vfs - appinit.go * lines 147-153 added getFullPath method * lines 80-84 mapped paths to doc/, favicon.ico in vfs Several files were copied from x/tools and go so paths (and corresponding import paths) were changed as follows: "x/tools/cmd/godoc/" --> "x/website/cmd/golangorg/" "x/tools/godoc/static/" --> "x/website/content/static/" "x/tools/godoc/" (without godoc/static/) --> "x/website/cmd/golangorg/godoc/" "x/tools/internal/memcache" --> "x/website/internal/memcache" "go/doc/" --> "x/website/content/doc/" "go/favicon.ico" --> "x/website/favicon.ico" "go/robots.txt" --> "x/website/robots.txt" Updates golang/go#29206 Change-Id: I53985fc027f73e60c6946038f85133acf1ecb08c Reviewed-on: https://go-review.googlesource.com/c/156321 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 0017391 commit da9e5cc

File tree

293 files changed

+69955
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+69955
-0
lines changed

cmd/golangorg/Dockerfile.prod

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Builder
2+
#########
3+
4+
FROM golang:1.11 AS build
5+
6+
RUN apt-get update && apt-get install -y \
7+
zip # required for generate-index.bash
8+
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
20+
21+
RUN go get -v -d \
22+
golang.org/x/net/context \
23+
google.golang.org/appengine \
24+
cloud.google.com/go/datastore \
25+
golang.org/x/build \
26+
github.com/gomodule/redigo/redis
27+
28+
COPY . /go/src/golang.org/x/tools
29+
30+
WORKDIR /go/src/golang.org/x/website/cmd/golangorg
31+
RUN GODOC_DOCSET=/goroot ./generate-index.bash
32+
33+
RUN go build -o /godoc -tags=golangorg golang.org/x/website/cmd/golangorg
34+
35+
# Clean up goroot for the final image.
36+
RUN cd /goroot && git clean -xdf
37+
38+
# Add build metadata.
39+
RUN cd /goroot && echo "go repo HEAD: $(git rev-parse HEAD)" >> /goroot/buildinfo
40+
RUN echo "requested go ref: ${GO_REF}" >> /goroot/buildinfo
41+
ARG TOOLS_HEAD
42+
RUN echo "x/tools HEAD: ${TOOLS_HEAD}" >> /goroot/buildinfo
43+
ARG TOOLS_CLEAN
44+
RUN echo "x/tools clean: ${TOOLS_CLEAN}" >> /goroot/buildinfo
45+
ARG DOCKER_TAG
46+
RUN echo "image: ${DOCKER_TAG}" >> /goroot/buildinfo
47+
ARG BUILD_ENV
48+
RUN echo "build env: ${BUILD_ENV}" >> /goroot/buildinfo
49+
50+
RUN rm -rf /goroot/.git
51+
52+
# Final image
53+
#############
54+
55+
FROM gcr.io/distroless/base
56+
57+
WORKDIR /app
58+
COPY --from=build /godoc /app/
59+
COPY --from=build /go/src/golang.org/x/website/cmd/golangorg/hg-git-mapping.bin /app/
60+
61+
COPY --from=build /goroot /goroot
62+
ENV GOROOT /goroot
63+
64+
COPY --from=build /go/src/golang.org/x/website/cmd/golangorg/index.split.* /app/
65+
ENV GODOC_INDEX_GLOB index.split.*
66+
67+
CMD ["/app/godoc"]

cmd/golangorg/Makefile

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2018 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+
.PHONY: usage
6+
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+
18+
usage:
19+
@echo "See Makefile and README.golangorg-app"
20+
@exit 1
21+
22+
cloud-build: Dockerfile.prod
23+
gcloud builds submit \
24+
--project=$(GCP_PROJECT) \
25+
--config=cloudbuild.yaml \
26+
--substitutions=_GO_REF=$(GO_REF),_TOOLS_HEAD=$(TOOLS_HEAD),_TOOLS_CLEAN=$(TOOLS_CLEAN),_DOCKER_TAG=$(DOCKER_TAG) \
27+
../.. # source code
28+
29+
docker-build: Dockerfile.prod
30+
# NOTE(cbro): move up in directory to include entire tools repo.
31+
# NOTE(cbro): any changes made to this command must also be made in cloudbuild.yaml.
32+
cd ../..; docker build \
33+
-f=cmd/godoc/Dockerfile.prod \
34+
--build-arg=GO_REF=$(GO_REF) \
35+
--build-arg=TOOLS_HEAD=$(TOOLS_HEAD) \
36+
--build-arg=TOOLS_CLEAN=$(TOOLS_CLEAN) \
37+
--build-arg=DOCKER_TAG=$(DOCKER_TAG) \
38+
--build-arg=BUILD_ENV=local \
39+
--tag=$(DOCKER_TAG) \
40+
.
41+
42+
docker-push: docker-build
43+
docker push $(DOCKER_TAG)
44+
45+
deploy:
46+
gcloud -q app deploy app.prod.yaml \
47+
--project=$(GCP_PROJECT) \
48+
--no-promote \
49+
--image-url=$(DOCKER_TAG)
50+
51+
get-latest-url:
52+
@gcloud app versions list \
53+
--service=default \
54+
--project=$(GCP_PROJECT) \
55+
--sort-by=~version.createTime \
56+
--format='value(version.versionUrl)' \
57+
--limit 1 | cut -f1 # NOTE(cbro): gcloud prints out createTime as the second field.
58+
59+
get-latest-id:
60+
@gcloud app versions list \
61+
--service=default \
62+
--project=$(GCP_PROJECT) \
63+
--sort-by=~version.createTime \
64+
--format='value(version.id)' \
65+
--limit 1 | cut -f1 # NOTE(cbro): gcloud prints out createTime as the second field.
66+
67+
regtest:
68+
go test -v \
69+
-regtest.host=$(shell make get-latest-url) \
70+
-run=Live
71+
72+
publish: regtest
73+
gcloud -q app services set-traffic default \
74+
--splits=$(shell make get-latest-id)=1 \
75+
--project=$(GCP_PROJECT)
76+
77+
@echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78+
@echo Stop and/or delete old versions:
79+
@echo "https://console.cloud.google.com/appengine/versions?project=$(GCP_PROJECT)&serviceId=default&versionssize=50"
80+
@echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
godoc on Google App Engine
2+
==========================
3+
4+
Prerequisites
5+
-------------
6+
7+
* Google Cloud SDK
8+
https://cloud.google.com/sdk/
9+
10+
* Redis
11+
12+
* Go sources under $GOROOT
13+
14+
* Godoc sources inside $GOPATH
15+
(go get -d golang.org/x/website/cmd/golangorg)
16+
17+
18+
Running locally, in production mode
19+
-----------------------------------
20+
21+
Build the app:
22+
23+
go build -tags golangorg
24+
25+
Run the app:
26+
27+
./golangorg
28+
29+
godoc should come up at http://localhost:8080
30+
31+
Use the PORT environment variable to change the port:
32+
33+
PORT=8081 ./golangorg
34+
35+
Running locally, in production mode, using Docker
36+
-------------------------------------------------
37+
38+
Build the app's Docker container:
39+
40+
make docker-build
41+
42+
Make sure redis is running on port 6379:
43+
44+
$ echo PING | nc localhost 6379
45+
+PONG
46+
^C
47+
48+
Run the datastore emulator:
49+
50+
gcloud beta emulators datastore start --project golang-org
51+
52+
In another terminal window, run the container:
53+
54+
$(gcloud beta emulators datastore env-init)
55+
56+
docker run --rm \
57+
--net host \
58+
--env GODOC_REDIS_ADDR=localhost:6379 \
59+
--env DATASTORE_EMULATOR_HOST=$DATASTORE_EMULATOR_HOST \
60+
--env DATASTORE_PROJECT_ID=$DATASTORE_PROJECT_ID \
61+
gcr.io/golang-org/godoc
62+
63+
godoc should come up at http://localhost:8080
64+
65+
66+
Deploying to golang.org
67+
-----------------------
68+
69+
Make sure you're signed in to gcloud:
70+
71+
gcloud auth login
72+
73+
Build the image, push it to gcr.io, and deploy to Flex:
74+
75+
make cloud-build deploy
76+
77+
Point the load balancer to the newly deployed version:
78+
(This also runs regression tests)
79+
80+
make publish
81+
82+
Stop and/or delete down any very old versions. (Stopped versions can be re-started.)
83+
Keep at least one older verson to roll back to, just in case.
84+
You can also migrate traffic to the new version via this UI.
85+
86+
https://console.cloud.google.com/appengine/versions?project=golang-org&serviceId=default&versionssize=50
87+
88+
89+
Troubleshooting
90+
---------------
91+
92+
Ensure the Cloud SDK is on your PATH and you have the app-engine-go component
93+
installed (gcloud components install app-engine-go) and your components are
94+
up-to-date (gcloud components update)

cmd/golangorg/app.dev.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
runtime: go
2+
api_version: go1
3+
instance_class: F4_1G
4+
5+
handlers:
6+
- url: /s
7+
script: _go_app
8+
login: admin
9+
- url: /dl/init
10+
script: _go_app
11+
login: admin
12+
- url: /.*
13+
script: _go_app

cmd/golangorg/app.prod.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
runtime: custom
2+
env: flex
3+
4+
env_variables:
5+
GODOC_PROD: true
6+
GODOC_ENFORCE_HOSTS: true
7+
GODOC_REDIS_ADDR: 10.0.0.4:6379 # instance "gophercache"
8+
GODOC_ANALYTICS: UA-11222381-2
9+
DATASTORE_PROJECT_ID: golang-org
10+
11+
network:
12+
name: golang
13+
14+
resources:
15+
cpu: 4
16+
memory_gb: 7.50

0 commit comments

Comments
 (0)