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