Google Cloud Build is a service that performs builds in the Google Cloud infrastructure according to specifications. It is a fully managed continuous integration and continuous delivery (CI/CD) platform provided by the Google Cloud ecosystem. Let’s take a look into what it enables and how to use it.
What is Cloud Build?
Containerisation allows to maximise managed cloud infrastructures to build, test and deploy applications quickly. Google Cloud Build is responsible for creating artefacts such as Docker containers or Java archives. In Cloud Build, source code can be imported from various sources. Here are the key features of Google Cloud Build.
Source repository integration
Cloud Build integrates seamlessly with popular source code repositories like Google Cloud Source Repositories, Cloud Storage, GitHub, and Bitbucket. This means you can trigger builds and deployments directly from your source control system.
Cloud Build configuration
Builds are configured using a file called cloudbuild.yaml. This file defines the steps and actions you need to take during the build process. It allows you to specify build triggers, build steps, substitutions, and other parameters essential for your build process.
Docker image building
Cloud Build is particularly powerful for building Docker images. It can automatically detect changes in your source code and trigger Docker image builds. This is essential for containerised applications, where building a Docker image is a critical step in the deployment process.
Build triggers
Cloud Build can be triggered automatically whenever changes are pushed to your repository. You can set up triggers based on branch patterns, tags, or specific files. This automation ensures that your application is built and tested whenever there are changes in your source code repository.
Scalability and speed
Cloud Build can handle large-scale builds and can scale horizontally to accommodate your build needs. It provides fast and efficient build and test processes, helping you shorten your development cycles.
Security and permissions
Cloud Build ensures secure build environments by running builds in isolated, sandboxed containers. It also integrates with Google Cloud Identity and Access Management (IAM), allowing you to control who can trigger and manage builds.
Configuring builds
Builds can be configured to follow instructions on what to do. These builds can be set up to fetch necessary dependencies, run unit and integration tests, or create artefacts using compilation tools like Docker, Gradle, Maven, Bazel, and Gulp.
Compilation occurs as a series of steps. Each of these steps operates in a Docker container and can perform anything possible in containers, regardless of the environment.
Cloud Build lifecycle
The lifecycle looks as follows:
- Prepare your application code and any necessary resources.
- Provide a YAML or JSON build configuration file containing Cloud Build instructions.
- Submit the build to Cloud Build.
- Based on the provided build configuration, Cloud Build executes the build.
- The built artefacts can then be uploaded to Artifact Registry.
Cloud Build can be accessed through the Google Cloud Console, the gcloud command-line tool, or the Cloud Build REST API.
The Google Cloud Console allows browsing build results or automating builds, while the gcloud command-line interface enables executing commands performing tasks such as creating, submitting, viewing, or cancelling builds.
Build steps
Cloud Build supports a wide range of build steps, including running custom scripts, executing Docker builds, running tests, and deploying applications. Each step is executed in a fresh, isolated container, ensuring reproducibility and consistency in your build process.
There are three ways you can use build steps:
- Provided by Cloud Build,
- Community-contributed build steps,
- Custom build steps that you write yourself.
Each build step runs with its own container attached to the local Docker network named “cloudbuild.” This allows the build steps to communicate and share data.
Custom build steps
Besides built-in steps, you can define custom build steps in your cloudbuild.yaml file. These steps can include running unit tests, linting code, or any other custom operation required for your application.
Default and private pools
By default, Cloud Build runs builds in a secure, isolated environment with access to the public internet. In the default pool, you can adjust machine size or allocate more disk space. However, there might be limitations regarding customising the environment, especially in terms of accessing private networks. The solution in this case is to use a private pool.
Private pools, like defaults, are hosted and fully managed by Cloud Build. You can scale them up and down to zero. Since these are customer-specific resources, they offer more configuration options.
Integration with Google Cloud services
Cloud Build runs on multiple environments and integrates with other Google Cloud services like Google Container Registry, allowing you to store your Docker images securely. It also integrates with Google Kubernetes Engine, enabling you to deploy containerised applications seamlessly.
Cloud Build and Cloud Run
Cloud Run allows you to run stateless containers in a fully serverless platform. With Cloud Build, you can deploy container images from Container Repository and Artifact Registry directly to Cloud Run. This includes an existing image, or you can build and deploy one, as well as automate the deployment.
How to use Cloud Build?
Google Cloud Build simplifies and automates the process of building, testing, and deploying applications in a scalable, secure, and reproducible manner on the Google Cloud Platform infrastructure. It’s a powerful tool for developers practising continuous integration and continuous delivery (Ci/CD), allowing them to focus on writing code while automated processes handle the rest of the development lifecycle.
It can help improve the speed and reliability of software delivery processes and significantly simplify infrastructure management. If you want to learn more about Cloud Build’s capabilities, contact FOTC experts who can explain in detail how it works and answer your other cloud-related questions.