LogoLogo
HomeBlogGitHubGet Started FreeLogin
Earthly 0.8
Earthly 0.8
  • 👋Introduction
  • 💻Install Earthly
  • 🎓Learn the basics
    • Part 1: A simple Earthfile
    • Part 2: Outputs
    • Part 3: Adding dependencies With Caching
    • Part 4: Args
    • Part 5: Importing
    • Part 6: Using Docker In Earthly
    • Part 7: Using remote runners
    • Part 8a: Using Earthly in your current CI
    • Final words
  • ⭐Featured guides
    • Rust
  • 📖Docs
    • Guides
      • Importing
      • Build arguments and variables
      • Secrets
      • Functions
      • Using Docker in Earthly
      • Multi-platform builds
      • Authenticating Git and image registries
      • Integration Testing
      • Debugging techniques
      • Podman
      • Configuring registries
        • AWS ECR
        • GCP Artifact Registry
        • Azure ACR
        • Self-signed certificates
      • Using the Earthly Docker Images
        • earthly/earthly
        • earthly/buildkitd
      • ✅Best practices
    • Caching
      • Caching in Earthfiles
      • Managing cache
      • Caching via remote runners
    • Remote runners
    • Earthfile reference
      • Builtin args
      • Excluding patterns
      • Version-specific features
    • The earthly command
    • Earthly lib
    • Configuration reference
    • Examples
    • Misc
      • Alternative installation
      • Data collection
      • Definitions
      • Public key authentication
  • 🔧CI Integration
    • Overview
    • Use the Earthly CI Image
    • Build your own Earthly CI Image
    • Pull-Through Cache
    • Remote BuildKit
    • Vendor-Specific Guides
      • GitHub Actions
      • Circle CI
      • GitLab CI/CD
      • Jenkins
      • AWS CodeBuild
      • Google Cloud Build
      • Bitbucket Pipelines
      • Woodpecker CI
      • Kubernetes
  • ☁️Earthly Cloud
    • Overview
    • Managing permissions
    • Cloud secrets
    • Earthly Satellites
      • Managing Satellites
      • Using Satellites
      • Self-Hosted Satellites
      • GitHub runners
      • Best Practices
      • Bring Your Own Cloud (BYOC)
        • AWS
          • Requirements
          • CloudFormation
          • Terraform
          • Manual
        • VPN
          • Tailscale
Powered by GitBook
On this page
  • Overview
  • Compatibility
  • Resources
  • Setup
  • Dependencies
  • Configuration
  • Additional Notes
  • Example

Was this helpful?

Edit on GitHub
  1. CI Integration
  2. Vendor-Specific Guides

Google Cloud Build

Overview

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.yaml spec (though it should be easily ported over to the json format if desired).

Compatibility

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 gcloud or gsutil commands within your Earthfile will require additional manual configuration via a service account.

Resources

  • Getting Started With Cloud Build

  • Authenticating As A Service Account

  • cloudbuild.yaml Specification

  • Creating and Managing build triggers

Setup

Depending on your needs and existing infrastructure, there may be additional configuration needed in your Google Cloud environment.

Dependencies

Ensure that your repositories are connected to Cloud Build. Google has a fantastic walkthrough for this.

Configuration

Note

If you do not intend to use any Google Cloud utilities or capabilities within your build, this service account configuration is optional.

Begin by following Google's instructions to create a service account. These instructions are partially duplicated below, with some screenshots for completeness.

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".

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.

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.

Then select "Keys" from the top navigation.

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.

Stash the key in your secret management utility of choice. You'll need to make this key available to your build at runtime. For the rest of our example, we will be using Earthly's Cloud Secrets.

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_TOKEN in Googles Secret Manager for ease of use.

Note

It is also possible to perform these steps via the CLI; the steps are also detailed in Googles instructions. It can also be automated using much of the same steps.

Additional Notes

earthly misinterprets the Cloud Build environment as a terminal. To hide the ANSI color codes, set NO_COLOR to 1.

Example

Note

This example is not production ready, and is intended to showcase configuration needed to get Earthly off the ground. If you run into any issues, or need help, don't hesitate to reach out!

You can find our cloudbuild.yaml and the Earthfile used on GitHub.

Start by adding a new Trigger. Triggers are the things that link changes in your source code with new instances of builds in Cloud Build. Start by clicking on "Create Trigger".

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.

Configure your source repository. If you do not see your desired repository in the drop down list, follow Google's instructions to add it.

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 cloudbuild.yaml.

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:

Running this build will use the cloudbuild.yaml file in our sample repository. This file is also a key part of the build, so lets break this down as well.

The first step simply uses the all-in-one Earthly image to do a simple build.

  - id: 'build'
    name: 'earthly/earthly:v0.8.13'
    args:
      - --ci
      - --push
      - +build

The second step runs a sample, Google Cloud Build only example to show how you would use an external service account to do things that normally requires credentials.

  - id: 'gcp-test'
    name: 'earthly/earthly:v0.8.13'
    args:
      - +gcp-cloudbuild
    secretEnv:
      - 'EARTHLY_TOKEN'

The secret environment variable bootstraps the Earthly secret store, and we can load it from Google's Secret Store like this:

availableSecrets:
  secretManager:
  - versionName: projects/earthly-jupyterlab/secrets/EARTHLY_TOKEN/versions/2
    env: 'EARTHLY_TOKEN'
PreviousAWS CodeBuildNextBitbucket Pipelines

Last updated 1 year ago

Was this helpful?

🔧
Step One of configuring a new Google Cloud Service account, with account name and description fields
Step two of configuring a new Google Cloud Service account, with a chosen role selected
The Google Cloud list view of service accounts, with our new account highlighted
The top nav of the service account drilldown, with the keys tab highlighted
The list view of available keys for a Google Cloud service account
The triggers page for a project, with "Create Trigger" highlighted.
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
Creating a trigger for Google Cloud Build, specifying the configuration, including cloudbuild location and configuration type
Google Cloud Build Trigger list, with the manual run button highlighted