UNPKG

2.66 kBMarkdownView Raw
1# cloudbuild-github
2
3cloudbuild-github allows integrating Google Container Builder (Cloudbuild) and GitHub. It sets up a
4webhook and status / comment notifications using Google Cloud Functions.
5
6## Setup
7
8### Curiostack users
9
10Create a new project with the `org.curioswitch.gradle-curio-cloudbuild-github-plugin` applied and
11run the `:deploy` task, e.g.,
12
13```bash
14$ ./gradlew :tools:cloudbuild-github-functions:deploy
15```
16
17### Normal usage
18
19The `gcloud` must be present on the path (see https://cloud.google.com/sdk/downloads) for how to
20install. In addition, the `GCLOUD_PROJECT` environment variable may need to be set to your GCP
21project ID.
22
23Start by creating a new project with a dependency on the library.
24
25```bash
26$ yarn init # main: index.tsx, private: true
27$ yarn add @curiostack/cloudbuild-github
28$ yarn
29```
30
31This will download the library, including a CLI to help setup. To create the configured cloud function
32and deploy it, run
33
34```bash
35$ yarn run cloudbuild-cli setup
36$ # Customize config.yml (e.g., replacing build step)
37$ yarn run cloudbuild-cli deploy
38```
39
40This will prompt you for information about your repository, including an access token for working with
41your GitHub repository (see details about tokens [here](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)).
42It will then write out an `index.tsx` and `config.yml` file that will be used by the webhook, deploy
43the cloud functions, and set up the repository webhook. That's it.
44
45If you update the configuration, just run deploy again.
46
47```bash
48$ yarn run cloudbuild-cli deploy
49```
50
51If you have trouble getting redeployed functions to update, add the `--delete` option when deploying.
52This will delete the function before deploying, so there will be some downtime. Hopefully as cloud
53functions matures, redeploys will work reliably and this option will go away.
54
55```bash
56$ yarn run cloudbuild-cli deploy --delete
57```
58
59## Details
60
61This package includes two cloud functions, a GitHub webhook and a pubsub subscriber to cloudbuild events.
62In response to an incoming webhook request, the first function will use the cloudbuild REST API to
63start a new build, which is configured to fetch the source from GitHub and then run a build command.
64The subscriber function is notified of all build events, and appropriately sets the GitHub status and
65comments on success or failure for change.
66
67The webhook only supports pull requests, it does not implement support for repository push events.
68It is trivial to set up a triggered cloudbuild within GCP itself and is recommended to do so. The
69subscriber will properly run on events for triggered builds too.