Comment on page
Google Cloud Build
Google's Cloud Build is a popular, hosted build platform with deep integrations into the Google Cloud ecosystem. It includes native support for containerized builds, as well as other build scenarios. This guide will cover the use of Earthly within the
cloudbuild.yamlspec (though it should be easily ported over to the
jsonformat if desired).
Earthly itself is able to run as expected within Cloud Build, including privileged mode features like
WITH DOCKER. However, Application Default Credentials are not available, so any
gsutilcommands within your
Earthfilewill require additional manual configuration via a service account.
Depending on your needs and existing infrastructure, there may be additional configuration needed in your Google Cloud environment.
If you do not intend to use any Google Cloud utilities or capabilities within your build, this service account configuration is optional.
Start by creating a build service account. Go to the "Create service account" page in the "IAM & Admin" API section, choose the appropriate project, and fill out the step 1 "Service account details". When you are done, click "Create and Continue".
Step One of configuring a new Google Cloud Service account, with account name and description fields
The creation steps should now ask you for a role to use in your build. The needs for each build are different; so examine your needs, and take care to grant the least privilege needed for your build. One reasonable starting point might be the default Cloud Build service account permissions.
Step two of configuring a new Google Cloud Service account, with a chosen role selected
Click "Done". The console should navigate you to a list of service accounts within the project. At this point, the account should be created, but we still need to create an account key. To do this, click on the email address for this service account in the list.
The Google Cloud list view of service accounts, with our new account highlighted
Then select "Keys" from the top navigation.
The top nav of the service account drilldown, with the keys tab highlighted
Click "Add Key", and then "Create New Key". Choose "JSON" as the key format, and click create. This will download the key to your computer, and you should see it in the list of keys.
The list view of available keys for a Google Cloud service account
Often, external secrets management requires some kind of bootstrapping secret (or additional integration) to allow you to access the rest of the secrets in your store. Earthly is no different. We will keep our
EARTHLY_TOKENin Googles Secret Manager for ease of use.
earthlymisinterprets the Cloud Build environment as a terminal. To hide the ANSI color codes, set
The triggers page for a project, with "Create Trigger" highlighted.
Fill out the "Name", "Description", and "Event" sections for this trigger, as they make sense for your project. For our example (and for ease of testing) we will be using the "Manual Invocation" trigger here.
Creating a trigger for Google Cloud Build, specifying a name, description, and trigger event
Creating a trigger for Google Cloud Build, specifying a repository and branch name
Finally, fill in the "Configuration" section. For Earthly, you can only use the "Cloud Build configuration file", as Earthly itself will also be running containers. Our example will also be using an embedded
Creating a trigger for Google Cloud Build, specifying the configuration, including cloudbuild location and configuration type
Click "Done" and you will be navigated back to the Triggers list view. To test the build, click "Run" since we chose a manual trigger only:
Google Cloud Build Trigger list, with the manual run button highlighted
- id: 'build'
- id: 'gcp-test'
The secret environment variable bootstraps the Earthly secret store, and we can load it from Google's Secret Store like this:
- versionName: projects/earthly-jupyterlab/secrets/EARTHLY_TOKEN/versions/2