-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Github notification bot. (#264)
Using https://github.com/GoogleCloudPlatform/cloud-build-notifiers as a base, created a Github bot that will add the details of the Google Cloud build to each pull request. Closes #259
- Loading branch information
1 parent
57dd4b6
commit 3fc0a94
Showing
12 changed files
with
821 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM golang AS build-env | ||
COPY . /go-src | ||
WORKDIR /go-src | ||
RUN go build -o /go-app . | ||
|
||
FROM gcr.io/distroless/base | ||
COPY --from=build-env /go-app / | ||
ENTRYPOINT ["/go-app", "--alsologtostderr", "--v=0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2021 Google LLC All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
STORAGE := gs://quilkin-ci-config | ||
|
||
current_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
all: build deploy | ||
|
||
# build: creates the project Cloud Build custom build step and hosts it on gcr.io | ||
build: | ||
gcloud builds submit . --config=cloudbuild.yaml $(ARGS) | ||
|
||
# deploy pushes a new version to Cloud Run | ||
deploy: | ||
-gsutil mb $(STORAGE) | ||
gsutil cp $(current_dir)/github.yaml $(STORAGE) | ||
gcloud run deploy github-bot \ | ||
--image="us-docker.pkg.dev/quilkin/ci/github-bot" \ | ||
--platform managed \ | ||
--no-allow-unauthenticated \ | ||
--region=us-west3 \ | ||
--update-env-vars="CONFIG_PATH=$(STORAGE)/github.yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Github Notification Bot | ||
|
||
This is the bot that created comments on GitHub pull requests whenever a | ||
[Google Cloud Build](https://cloud.google.com/build) build passes or fails. | ||
|
||
## Setup | ||
|
||
### Image | ||
|
||
Run `make build` to submit the cloud build to create the image that will be hosted on | ||
[Cloud Run](https://cloud.google.com/run). | ||
|
||
### Secrets | ||
|
||
It is expected that there will be a secret named `gh-token` with a | ||
[Github auth token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) stored | ||
in it, and the ${PROJECT_NUMBER}-compute@developer.gserviceaccount.com service account has the | ||
role `roles/secretmanager.secretAccessor` for the `gh-token` secret. | ||
|
||
### Deployment | ||
|
||
Run `make deploy` to copy the config to the appropriate bucket, and deploy the notifier image to Cloud Run. | ||
|
||
### Connect to Cloud Build | ||
|
||
Follow https://cloud.google.com/build/docs/subscribe-build-notifications to create the | ||
[Google Cloud PubSub topics](https://cloud.google.com/pubsub) for Google Cloud Build. | ||
|
||
Follow https://cloud.google.com/run/docs/triggering/pubsub-push to setup the Notifier service to be triggered from | ||
PubSub with the `cloud-builds` pubsub topic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2021 Google LLC All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
steps: | ||
- name: gcr.io/cloud-builders/docker | ||
args: | ||
- build | ||
- --tag=${_REGISTRY}/github-bot:latest | ||
- '.' | ||
images: | ||
- ${_REGISTRY}/github-bot | ||
options: | ||
dynamic_substitutions: true | ||
substitutions: | ||
_REGISTRY: "us-docker.pkg.dev/${PROJECT_ID}/ci" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: cloud-build-notifiers/v1 | ||
kind: GithubNotifier | ||
metadata: | ||
name: github-notifier | ||
spec: | ||
notification: | ||
filter: build.status == Build.Status.SUCCESS | ||
delivery: | ||
secrets: | ||
- name: gh-token | ||
value: projects/quilkin/secrets/gh-token/versions/latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
module github-bot | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/GoogleCloudPlatform/cloud-build-notifiers/lib/notifiers v0.0.0-20210219212036-163c92a64b27 | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b | ||
github.com/google/go-github/v35 v35.2.0 | ||
golang.org/x/oauth2 v0.0.0-20210201163806-010130855d6c | ||
golang.org/x/tools v0.1.1 // indirect | ||
google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384 | ||
) |
Oops, something went wrong.