Build a Docker image automatically with Cloud Build in Google Cloud Platform

Learn basic CI/CD with GCP

Lynn G. Kwong
7 min readMar 30, 2021

In modern software development practice, it is common to dockerize our applications. Therefore, it will be convenient if a docker image can be automatically built when we push some code to the repository. This is part of the continuous integration/continuous deployment (CI/CD) practice. For example, if we want to schedule some jobs in Airflow, we can use the KubernetesPodOperator to run the docker image of our application. With Cloud Build, the docker image can be automatically built for us whenever we push some new code.

Photo by Nikin on Pixabay.

Cloud Build is a service that executes your builds on Google Cloud Platform’s infrastructure. Cloud Build can import source code from a variety of repositories or cloud storage spaces, execute a build to your specifications, and produce artifacts such as Docker containers.

With cloud build, you can write a build config file to provide instructions to Cloud Build on what tasks to perform. Cloud Build executes your build as a series of build steps, where each build step is run in a Docker container.

To build your Docker image using a build config file, we need to create a file named cloudbuild.yaml in the same directory that contains your application source code.

--

--

Lynn G. Kwong

I’m a Software Developer (https://medium.com/@lynn-kwong) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.