|
2 | 2 |
|
3 | 3 | This directory contains the files needed for our GCB presubmit ("PR builds") |
4 | 4 | and postsubmit ("CI builds") builds. The `cloudbuild.yaml` file is the main |
5 | | -config file for cloud build. Cloud builds may be managed from the command line |
6 | | -with the `gcloud builds` command. To make this process easier, the `build.sh` |
7 | | -script can be used to submit builds to GCB, run builds locally in a docker |
8 | | -container, or even run builds directly in your local environment. See `build.sh |
9 | | ---help` for more details. |
| 5 | +config file for Google Cloud Build (GCB). Cloud builds may be managed from the |
| 6 | +command line with the `gcloud builds` command. To make this process easier, the |
| 7 | +`build.sh` script can be used to submit builds to GCB, run builds locally in a |
| 8 | +docker container, or even run builds directly in your local environment. See |
| 9 | +`build.sh --help` for more details. |
| 10 | + |
| 11 | +Build scripts live in the `builds/` directory. We want to keep these scripts as |
| 12 | +simple as possible. Ideally they will be just a simple listing of the commands |
| 13 | +that a human would type with minimal logic. Many of these build scripts should |
| 14 | +be only a few lines. A little duplication is even OK if the resulting build |
| 15 | +script is simpler. Sometimes there are non-trivial things we need to do |
| 16 | +repeatedly (e.g., run the quickstart builds), and these live in `builds/lib/`. |
| 17 | + |
| 18 | +Each build runs in an environment defined by a Dockerfile in the `dockerfiles/` |
| 19 | +directory. Some Dockerfiles are used by multiple builds, some only one. Build |
| 20 | +scripts and Dockerfiles are associated in a trigger file. |
10 | 21 |
|
11 | 22 | GCB triggers can be configured in the http://console.cloud.google.com/ UI, but |
12 | | -we prefer to configure them with SCM controlled YAML files that live in the |
| 23 | +we prefer to configure them with version controlled YAML files that live in the |
13 | 24 | `triggers/` directory. Managing triggers can be done with the `gcloud` command |
14 | 25 | also, but we have the local `trigger.sh` script to make this process a bit |
15 | 26 | easier. See `trigger.sh --help` for more details. |
16 | 27 |
|
| 28 | +Adding a new build is pretty simple, and can be done in a single PR. For |
| 29 | +example, see https://github.com/googleapis/google-cloud-cpp/pull/6252, which |
| 30 | +adds the `cxx17-pr` and `cxx17-ci` builds. The steps to add a new build are: |
| 31 | + |
| 32 | +1. (Optional) If your build needs to run in a unique environment, you should |
| 33 | + start by creating a new Dockerfile in `dockerfiles/`. If you don't need a |
| 34 | + specific environment, we typically use the `dockerfiles/fedora.Dockerfile` |
| 35 | + image, which is simply called the "fedora" distro. Here's an [example |
| 36 | + PR](https://github.com/googleapis/google-cloud-cpp/pull/6259) that adds a |
| 37 | + build with its own Dockerfile. |
| 38 | +2. Create the new build script in `builds/` that runs the commands you want. |
| 39 | + * You can test this script right away with `build.sh` by explicitly |
| 40 | + specifying the `--distro` you want your build to run in. For example: |
| 41 | + ``` |
| 42 | + $ build.sh --distro fedora my-new-build # or ... |
| 43 | + $ build.sh --distro fedora my-new-build --docker |
| 44 | + ``` |
| 45 | +3. Create your trigger file(s) in the `triggers/` directory. If you want both |
| 46 | + PR (presubmit) and CI (postsubmit) builds you can generate the trigger files |
| 47 | + with the command `trigger.sh --generate my-new-build`, which will write the |
| 48 | + new files in the `triggers/` directory. You may need to tweak the files at |
| 49 | + this point, for example to change the distro (fedora is the default). |
| 50 | +4. At this point, you're pretty much done. You can now test your build using |
| 51 | + the trigger name as shown here: |
| 52 | + ``` |
| 53 | + $ build.sh -t my-new-build-pr # or ... |
| 54 | + $ build.sh -t my-new-build-pr --docker # or ... |
| 55 | + $ build.sh -t my-new-build-pr --project cloud-cpp-testing-resources |
| 56 | + ``` |
| 57 | +5. Send a PR! Google Cloud Build will not know about your new trigger files yet |
| 58 | + so they will not be run for your PR. This is working as intended. Get the PR |
| 59 | + reviewed and merge it. |
| 60 | +6. FINAL STEP: Now that the code for your new build is checked in, tell GCB |
| 61 | + about the triggers so the can be run automatically for all future PRs and |
| 62 | + merges. |
| 63 | + ``` |
| 64 | + $ trigger.sh --import triggers/my-new-build-pr.yaml |
| 65 | + $ trigger.sh --import triggers/my-new-build-ci.yaml |
| 66 | + ``` |
| 67 | + |
17 | 68 | ## Testing principles |
18 | 69 |
|
19 | 70 | We want our code to work for our customers. We don't know their exact |
@@ -45,9 +96,3 @@ while achieving high likelihood of the code working for our customers. |
45 | 96 | * Sanitizer builds need to run integration tests |
46 | 97 | * We want to test our user-facing instructions (i.e., how to install and use) |
47 | 98 | as much as possible (this is difficult on macOS and Windows without docker) |
48 | | - |
49 | | -In addition to the guiding principles above, we'd like to keep the build |
50 | | -scripts in `builds/` as simple as possible; ideally just a simple listing of |
51 | | -the commands that a human would type with minimal logic. Many of these build |
52 | | -scripts should be only a few lines. A little duplication is even OK if the |
53 | | -resulting build script is simpler. |
|
0 commit comments