CI/CD Pipeline on GCP using Cloud Source Repositories, Cloud Build, Artifact Registry and App Engine

CI/CD Pipeline on GCP Architecture example

In this article, I will show you a CI/CD pipleline configuration focusing Cloud Build(cloudbuild.yaml) on GCP. In this example, Cloud Source Repositories, Cloud Build, Artifact Registry and App Engine are used.

I will show you command based in case you would like to check build and deployment with command base as an appendix.

Cloud Source Repositories

A single place for your team to store, manage, and track code.

Cloud Source Repositories is a source code management tool on GCP. Generally, as other service, Github is known well.

Cloud Build

Build, test, and deploy on our serverless CI/CD platform.

Cloud build helps you build the image such as a Docker image, push the image to a repository then deploy the application on a platform.

Artifact Registry

The next generation of Container Registry. Store, manage, and secure your build artifacts.

This seems an upper compatibility of the previous service, Container Registry.

App Engine

Build highly scalable applications on a fully managed serverless platform.

App Engine is a serverless platform on GCP as written.

For instance, we develop an application like a Frontend server or an API server running as a Docker container on our local PC. When we provide a service for your customers, we probably deploy these applications on cloud service. App Engine is one of the solutions to deploy these application servers.

As other serverless platform, there is Cloud Run which is the latest serverless service on GCP. I do not refer to it here.

Prerequisites

  • Your source code is push into Cloud Source Repositories (or it is fine into other services such as Github etc but the configuration on Cloud Build is slightly different).
  • The application is developed as it runs as Docker Container.
  • The repository for docker images is created on Artifact Repository. (I have not checked Container Registry is also fine yet.)
  • Application is running on App Engine.

Configure CI/CD Pipeline — Cloud Build

In order to deploy the applications automatically, three points must be done before pushing the source code.

  • Cloud Build trigger configuration
  • Define cloudbuild.yaml file
  • Define app.yaml file

Step1: Trigger

Let's open the Cloud Build page and create new trigger.

Name is trigger unique name in the project, Tags is just for arranging the triggers you will create in the project.

In the Event filed, select "Push to a branch". This means when you push the source code to one branch then the trigger is invoked.

In the Source filed, you can choose the repository you want Cloud Build to watch. For instance, the repository on Cloud Source Repositories or if you want to use Github repository, choose "CONNECT NEW REPOSITORY" and select what you want to use. The Authentication will run.

Branch input box, you indicate what exactly branch with a regular expression. For example, in my case I want the trigger to run when I push the source code to main branch so I wrote "^main$" in the input box. If you just write "main"(only main), when you push a code to even "maintenance" branch, the trigger will run.

In the Configuration filed, select "cloud Build configuration file (YAML or JSON)" to use cloudbuild.yaml in your git repository. "cloudbuild.yaml" will be defined automatically in "Cloud Build configuration file location" box.

Finally, you create!!

Step2: Build & Push an image

The next is defining cloudbuild.yaml file. The bellow is the example.

steps is for the jobs. In this case, after a trigger invoked, the jobs run from the top in order. Firstly, the build step runs(this seems almost same as usual docker build) then push the built image to the artifact repository you created before, then finally deploy the application by using gcloud app deploy command and app.yaml file which I explain from now.

Step3: Deploy an application

Deployment itself is invoked in Cloud Build trigger but the environment where the application is deployed must be defined.

In this case, the configuration is defined in app.yaml file because App Engine is used.

The documentation about app.yaml for App Engine is here.

When you deploy the image on Cloud Run instead of App Engine, gcloud run deploy command should be defined in cloudbuild.yaml.

Building and deploying a container

This is the CI/CD Pipeline on GCP using Cloud Source Repositories, Cloud Build, Artifact Registry and App Engine. When you check the CI/CD pipeline running status, open the Build History page from the History tab on Cloud Build page.

Well done.

Appendix

Command base build and deployment

Build an image using a build config file

Follow the instruction on the above then execute gcloud app deploy(or gclou run deploy) command on your terminal as it is defined in cloudbuild.yaml.

Thank you.

--

--

--

I’m Taka, Japanese and living in Japan. I'm planning to emigrate to New Zealand in the near future with my partner.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

CS371p Spring 2021: Luca Chaves Rodrigues Noronha dos Santos

Data Processing with SMACK: Spark, Mesos, Akka, Cassandra, and Kafka

Using EKS in order to deploy SQL & WordPress

Failure Is Not An Option

Which number will replace the question make (?) in the following serie

Journaling as an IoT service architecture

{UPDATE} ピアノの音から音階を答える!絶対音感相対音感を鍛えて競うゲームアプリ Hack Free Resources Generator

Stream Inversion & Topology

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Taka

Taka

I’m Taka, Japanese and living in Japan. I'm planning to emigrate to New Zealand in the near future with my partner.

More from Medium

GCP Service Accounts

SFTP using CyberDuck via IAP Tunnel in Google Cloud Platform

Tutorial: Bucket Replication for Google Cloud Platform (GCP) Cloud Storage

Workload Identity Federation — Authenticate GitHub actions to Google Cloud