Skip to content

Commit

Permalink
cmd/gopherbot: add Kubernetes config
Browse files Browse the repository at this point in the history
Updates golang/go#18817

Change-Id: I8947eaf02d9b4ea49db00879bef8d1c6cb54184a
Reviewed-on: https://go-review.googlesource.com/42251
Reviewed-by: Quentin Smith <[email protected]>
  • Loading branch information
bradfitz authored and kevinburke committed May 2, 2017
1 parent 37abedf commit 2b6ab5e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/gopherbot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gopherbot
ca-certificates.crt
9 changes: 9 additions & 0 deletions cmd/gopherbot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2017 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
FROM scratch
LABEL maintainer "[email protected]"

COPY ca-certificates.crt /etc/ssl/certs/
COPY gopherbot /
ENTRYPOINT ["/gopherbot"]
42 changes: 42 additions & 0 deletions cmd/gopherbot/Dockerfile.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2017 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
FROM golang:1.8
LABEL maintainer "[email protected]"

RUN go get -d cloud.google.com/go/compute/metadata && \
cd /go/src/cloud.google.com/go/compute/metadata && \
git reset --hard cd0da878c66091060d2e7403abd62192b3e387e0

RUN go get -d golang.org/x/oauth2 && \
cd /go/src/golang.org/x/oauth2 && \
git reset --hard 314dd2c0bf3ebd592ec0d20847d27e79d0dbe8dd

RUN go get -d github.com/golang/protobuf/proto && \
cd /go/src/github.com/golang/protobuf/proto && \
git reset --hard 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8

RUN go get -d github.com/google/go-github/github && \
cd /go/src/github.com/google/go-github/github && \
git reset --hard e8d46665e050742f457a58088b1e6b794b2ae966

RUN go get -d github.com/googleapis/gax-go && \
cd /go/src/github.com/googleapis/gax-go && \
git reset --hard 9af46dd5a1713e8b5cd71106287eba3cefdde50b

RUN go get -d golang.org/x/sync/errgroup && \
cd /go/src/golang.org/x/sync/errgroup && \
git reset --hard 457c5828408160d6a47e17645169cf8fa20218c4

RUN go get -d github.com/gregjones/httpcache && \
cd /go/src/github.com/gregjones/httpcache && \
git reset --hard d02018f006d98f58512bf3adfc171d88d17626df

RUN go get -d go4.org/types && \
cd /go/src/go4.org && \
git reset --hard 7ce08ca145dbe0e66a127c447b80ee7914f3e4f9

COPY . /go/src/golang.org/x/build/

RUN go install -ldflags "-linkmode=external -extldflags '-static -pthread'" golang.org/x/build/cmd/gopherbot

35 changes: 35 additions & 0 deletions cmd/gopherbot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2017 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

VERSION=latest
DOCKER_IMAGE_build0=build0/gopherbot:latest
DOCKER_CTR_build0=gopherbot-build0

build0: *.go Dockerfile.0
docker build --force-rm -f Dockerfile.0 --tag=$(DOCKER_IMAGE_build0) ../..

gopherbot: build0
docker create --name $(DOCKER_CTR_build0) $(DOCKER_IMAGE_build0)
docker cp $(DOCKER_CTR_build0):/go/bin/$@ $@
docker rm $(DOCKER_CTR_build0)

ca-certificates.crt:
docker create --name $(DOCKER_CTR_build0) $(DOCKER_IMAGE_build0)
docker cp $(DOCKER_CTR_build0):/etc/ssl/certs/$@ $@
docker rm $(DOCKER_CTR_build0)

docker-prod: Dockerfile gopherbot ca-certificates.crt
docker build --force-rm --tag=gcr.io/symbolic-datum-552/gopherbot:$(VERSION) .
docker-dev: Dockerfile gopherbot ca-certificates.crt
docker build --force-rm --tag=gcr.io/go-dashboard-dev/gopherbot:latest .

push-prod: docker-prod
gcloud docker -- push gcr.io/symbolic-datum-552/gopherbot:$(VERSION)
push-dev: docker-dev
gcloud docker -- push gcr.io/go-dashboard-dev/gopherbot:latest

.PHONY: clean
clean:
$(RM) gopherbot
$(RM) ca-certificates.crt
31 changes: 31 additions & 0 deletions cmd/gopherbot/deployment-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: gopherbot-deployment
spec:
replicas: 1 # more than 1 might cause duplicate GitHub comments
template:
metadata:
labels:
app: gopherbot
spec:
volumes:
- name: cache-volume
emptyDir: {}
containers:
- name: gopherbot
image: gcr.io/symbolic-datum-552/gopherbot:latest
imagePullPolicy: Always
env:
- name: XDG_CACHE_HOME
value: "/cache"
command: ["/gopherbot", "--daemon"]
volumeMounts:
- mountPath: /cache
name: cache-volume
resources:
requests:
cpu: "1"
memory: "1Gi"
limits:
memory: "2Gi"
10 changes: 9 additions & 1 deletion cmd/gopherbot/gopherbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strings"
"time"

"cloud.google.com/go/compute/metadata"
"github.com/google/go-github/github"
"golang.org/x/build/maintner"
"golang.org/x/build/maintner/godata"
Expand All @@ -32,7 +33,14 @@ var (
)

func getGithubToken() (string, error) {
// TODO: get from GCE metadata, etc.
if metadata.OnGCE() {
for _, key := range []string{"gopherbot-github-token", "maintner-github-token"} {
token, err := metadata.ProjectAttributeValue(key)
if err == nil {
return token, nil
}
}
}
tokenFile := filepath.Join(os.Getenv("HOME"), "keys", "github-gobot")
slurp, err := ioutil.ReadFile(tokenFile)
if err != nil {
Expand Down

0 comments on commit 2b6ab5e

Please sign in to comment.