Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions deployment/live/cloudbuild/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Cloudbuild Triggers and Steps
# Cloudbuild Triggers and Steps

This directory contains a terragrunt file that can be deployed using `terragrunt apply` to define the necessary triggers and steps in GCB.
These steps will:
Expand All @@ -13,7 +13,7 @@ Error: Error creating Trigger: googleapi: Error 400: Repository mapping does not

This is a manual one-time step that needs to be followed to integrate GCB and the GitHub project.

### Slack notifications
## Slack Notifications

Each cloudbuild environment sets up a Slack integration. This requires:
1. A webhook to have been created in a Slack app (https://api.slack.com/apps/A06KYD43DPE/incoming-webhooks)
Expand All @@ -28,3 +28,65 @@ terragrunt import module.cloud-build-slack-notifier.google_pubsub_topic.cloud_bu
```

This imports the resource into this configuration, and running `terragrunt apply` again after this should work.

### Slack Templating

Here's an example pub-sub message for ease of writing templates ([docs](https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#Build)):

```
{
"id": "0d97c63e-a349-4bf7-80d0-8f6e21786d87",
"status": "SUCCESS",
"source": {
"gitSource": {
"url": "https://github.com/transparency-dev/distributor.git",
"revision": "a017b5e59a1cf9fdbed5999e1a9aced5404de4cd"
}
},
"createTime": "2024-02-21T16:56:35.560619Z",
"steps": [{
"name": "gcr.io/cloud-builders/docker",
"args": ["build", "-t", "us-central1-docker.pkg.dev/checkpoint-distributor/distributor-docker-dev/distributor:latest", "-f", "./cmd/Dockerfile", "."]
}, {
"name": "gcr.io/cloud-builders/docker",
"args": ["push", "us-central1-docker.pkg.dev/checkpoint-distributor/distributor-docker-dev/distributor:latest"]
}, {
"name": "gcr.io/google.com/cloudsdktool/cloud-sdk",
"args": ["run", "deploy", "distributor-service-dev", "--image", "us-central1-docker.pkg.dev/checkpoint-distributor/distributor-docker-dev/distributor:latest", "--region", "us-central1"],
"entrypoint": "gcloud"
}],
"timeout": "600s",
"projectId": "checkpoint-distributor",
"sourceProvenance": {
"resolvedGitSource": {
"url": "https://github.com/transparency-dev/distributor.git",
"revision": "a017b5e59a1cf9fdbed5999e1a9aced5404de4cd"
}
},
"buildTriggerId": "33f60a9c-3d79-4941-bfb1-fccbdd9cf38c",
"options": {
"substitutionOption": "ALLOW_LOOSE",
"logging": "CLOUD_LOGGING_ONLY",
"dynamicSubstitutions": true,
"pool": {
}
},
"logUrl": "https://console.cloud.google.com/cloud-build/builds;region\u003dus-central1/0d97c63e-a349-4bf7-80d0-8f6e21786d87?project\u003d39300730911",
"substitutions": {
"TRIGGER_NAME": "build-distributor-docker-dev",
"COMMIT_SHA": "a017b5e59a1cf9fdbed5999e1a9aced5404de4cd",
"TRIGGER_BUILD_CONFIG_PATH": "",
"REPO_FULL_NAME": "transparency-dev/distributor",
"SHORT_SHA": "a017b5e",
"BRANCH_NAME": "main",
"REF_NAME": "main",
"REVISION_ID": "a017b5e59a1cf9fdbed5999e1a9aced5404de4cd",
"REPO_NAME": "distributor"
},
"tags": ["trigger-33f60a9c-3d79-4941-bfb1-fccbdd9cf38c"],
"queueTtl": "3600s",
"serviceAccount": "projects/checkpoint-distributor/serviceAccounts/cloudbuild-dev-sa@checkpoint-distributor.iam.gserviceaccount.com",
"name": "projects/39300730911/locations/us-central1/builds/0d97c63e-a349-4bf7-80d0-8f6e21786d87"
}
```

19 changes: 16 additions & 3 deletions deployment/live/cloudbuild/dev/slack.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
[
{
"type": "section",
"type": "header",
"text": {
"type": "mrkdwn",
"text": "Cloud Build {{.Build.ProjectId}} {{.Build.Id}} {{.Build.Status}}"
"type": "plain_text",
"text": "CloudBuild {{.Build.Status}}: {{.Build.Substitutions.REPO_NAME}} {{.Build.Substitutions.TRIGGER_NAME}}"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Branch*: {{.Build.Substitutions.BRANCH_NAME}}"
},
{
"type": "mrkdwn",
"text": "*Commit*: {{.Build.Substitutions.SHORT_SHA}}"
}
]
},
{
"type": "section",
"text": {
Expand Down