Skip to content

Commit ac48f4d

Browse files
authored
Merge pull request #127 from glasnt/new-googlechat
New notifier: Google Chat
2 parents 2f9eebc + 5871851 commit ac48f4d

8 files changed

+470
-1
lines changed

googlechat/Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM golang AS build-env
16+
COPY . /go-src/
17+
WORKDIR /go-src/googlechat
18+
RUN go test /go-src/googlechat
19+
RUN go build -o /go-app .
20+
21+
# From the Cloud Run docs:
22+
# https://cloud.google.com/run/docs/tutorials/pubsub#looking_at_the_code
23+
# Use the official Debian slim image for a lean production container.
24+
# https://hub.docker.com/_/debian
25+
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
26+
FROM debian:buster-slim
27+
RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
28+
ca-certificates && \
29+
rm -rf /var/lib/apt/lists/*
30+
31+
FROM gcr.io/distroless/base
32+
COPY --from=build-env /go-app /
33+
ENTRYPOINT ["/go-app", "--alsologtostderr", "--v=0"]

googlechat/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cloud Build Google Chat Notifier
2+
3+
This notifier uses [Google Chat Webhooks](https://developers.google.com/chat/how-tos/webhooks) to
4+
send notifications to your Google Chat space.
5+
6+
This notifier runs as a container via Google Cloud Run and responds to
7+
events that Cloud Build publishes via its
8+
[Pub/Sub topic](https://cloud.google.com/cloud-build/docs/send-build-notifications).
9+
10+
For detailed instructions on setting up this notifier,
11+
see [Configuring Google Chat notifications](https://cloud.google.com/cloud-build/docs/configuring-notifications/configure-googlechat).
12+
13+
## Configuration Variables
14+
15+
This notifier expects the following fields in the `delivery` map to be set:
16+
17+
- `webhook_url`: The `secretRef: <GoogleChat-webhook-URL>` map that references the
18+
Slack webhook URL resource path in the `secrets` section.

googlechat/buildtest.cloudbuild.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
- name: gcr.io/cloud-builders/docker
17+
args:
18+
- build
19+
- --file=./googlechat/Dockerfile
20+
- '.'
21+
22+
tags:
23+
- cloud-build-notifiers-googlechat

googlechat/deploy.cloudbuild.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
# Build the binary and put it into the builder image.
17+
- name: gcr.io/cloud-builders/docker
18+
args:
19+
- build
20+
- --tag=${_REGISTRY}/googlechat:${TAG_NAME}
21+
- --tag=${_REGISTRY}/googlechat:${_MAJOR_LATEST}
22+
- --tag=${_REGISTRY}/googlechat:latest
23+
- --file=./googlechat/Dockerfile
24+
- '.'
25+
# Run the smoketest to verify that everything built correctly.
26+
- name: ${_REGISTRY}/googlechat:${TAG_NAME}
27+
args:
28+
- --smoketest
29+
- --alsologtostderr
30+
31+
# Push the image with tags.
32+
images:
33+
- ${_REGISTRY}/googlechat:${TAG_NAME}
34+
- ${_REGISTRY}/googlechat:${_MAJOR_LATEST}
35+
- ${_REGISTRY}/googlechat:latest
36+
37+
options:
38+
dynamic_substitutions: true
39+
40+
substitutions:
41+
_REGISTRY: us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers
42+
# Looks like: $NOTIF-$MAJOR-latest. Not meant for overriding.
43+
_MAJOR_LATEST: "${TAG_NAME%%.*}-latest"
44+
45+
tags:
46+
- cloud-build-notifiers-googlechat
47+
- googlechat-${TAG_NAME}

googlechat/googlechat.yaml.example

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: cloud-build-notifiers/v1
16+
kind: GoogleChatNotifier
17+
metadata:
18+
name: example-googlechat-notifier
19+
spec:
20+
notification:
21+
filter: build.status == Build.Status.SUCCESS
22+
delivery:
23+
webhookUrl:
24+
secretRef: webhook-url
25+
secrets:
26+
- name: webhook-url
27+
value: projects/example-project/secrets/example-googlechat-notifier-webhook-url/versions/latest

0 commit comments

Comments
 (0)