Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit dba155b

Browse files
author
Ian Lewis
authored
Merge branch 'master' into twitter-card-image
2 parents e5504cd + 68e7205 commit dba155b

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ APP_TARGET = $(patsubst cmd/gvisor-website/%,public/%,$(APP_SOURCE))
1414
default: website
1515
.PHONY: default
1616

17-
website: all-upstream app public/static
17+
website: all-upstream app static-production
1818
.PHONY: website
1919

2020
app: $(APP_TARGET)
@@ -44,8 +44,13 @@ content/docs/community/sigs: upstream/community $(wildcard upstream/community/si
4444
$(APP_TARGET): public $(APP_SOURCE)
4545
cp -a cmd/gvisor-website/$(patsubst public/%,%,$@) public/
4646

47-
public/static: compatibility-docs node_modules config.toml $(shell find archetypes assets content themes -type f | sed 's/ /\\ /g')
47+
static-production: compatibility-docs node_modules config.toml $(shell find archetypes assets content themes -type f | sed 's/ /\\ /g')
4848
HUGO_ENV="production" $(HUGO)
49+
.PHONY: static-production
50+
51+
static-staging: compatibility-docs node_modules config.toml $(shell find archetypes assets content themes -type f | sed 's/ /\\ /g')
52+
$(HUGO) -b "https://staging-$(shell git branch | grep \* | cut -d ' ' -f2)-dot-gvisor-website.appspot.com"
53+
.PHONY: static-staging
4954

5055
node_modules: package.json package-lock.json
5156
# Use npm ci because npm install will update the package-lock.json.
@@ -77,10 +82,17 @@ server: website
7782
.PHONY: server
7883

7984
# Deploy the website to App Engine.
80-
deploy: $(APP_TARGET)
85+
deploy: website
8186
cd public && $(GCLOUD) app deploy
8287
.PHONY: deploy
8388

89+
# Stage the website to App Engine at a version based on the git branch name.
90+
stage: all-upstream app static-staging
91+
# Disallow indexing staged content.
92+
printf "User-agent: *\nDisallow: /" > public/static/robots.txt
93+
cd public && $(GCLOUD) app deploy -v staging-$(shell git branch | grep \* | cut -d ' ' -f2) --no-promote
94+
.PHONY: stage
95+
8496
# CI related Commmands
8597
##############################################################################
8698

cmd/gvisor-website/app.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: go111
15+
runtime: go112
1616

1717
handlers:
1818
- url: /.*
@@ -21,4 +21,3 @@ handlers:
2121
- url: /rebuild
2222
secure: always
2323
script: auto
24-
login: admin

cmd/gvisor-website/main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ var (
7171
goGetHTML5 = `<!doctype html><html><head><meta charset=utf-8>` + goGetHeader + `<title>Go-get</title></head><body></html>`
7272
)
7373

74+
// cronHandler wraps an http.Handler to check that the request is from the App
75+
// Engine Cron service.
76+
// See: https://cloud.google.com/appengine/docs/standard/go112/scheduling-jobs-with-cron-yaml#validating_cron_requests
77+
func cronHandler(h http.Handler) http.Handler {
78+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
79+
if r.Header.Get("X-Appengine-Cron") != "true" {
80+
http.NotFound(w, r)
81+
return
82+
}
83+
// Fallthrough.
84+
h.ServeHTTP(w, r)
85+
})
86+
}
87+
7488
// wrappedHandler wraps an http.Handler.
7589
//
7690
// If the query parameters include go-get=1, then we redirect to a single
@@ -174,7 +188,7 @@ func registerRebuild(mux *http.ServeMux) {
174188
mux = http.DefaultServeMux
175189
}
176190

177-
mux.Handle("/rebuild", wrappedHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
191+
mux.Handle("/rebuild", cronHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
178192
ctx := context.Background()
179193
credentials, err := google.FindDefaultCredentials(ctx, cloudbuild.CloudPlatformScope)
180194
if err != nil {
-12 Bytes
Loading

0 commit comments

Comments
 (0)