CI/CD with Cloud Build

Tram Ho

One of the things I like most about Cloud Providers is that I just need to declare a few remaining lines of command, I don’t have to care

Cloud Build – the serverless CI / CD product of Google Cloud is one of the best. Simply because it is easy to apply, smart but effective

Are you ready. Let’s start

What is Google Cloud Build?

This is a product of GCP that aims to build the source code of all programming languages.

  • Increase build speed with VMs on Cloud and do not consume individual machine resources.
  • Source code located in Local, Github, Cloud Source Repositories or Bitbucket can be used Cloud Build
  • Cloud Build supports many options to build source code: Docker container, Maven, Gradle, webpack, Go or Bazel.
  • The results after performing the build will be pushed to Docker Hub or Container Registry.
  • You can customize the build processing flow to your liking.
  • Free build time is 120 minutes / day.

The trigger functionality of Cloud Build

1. Prepare

2. Decentralize and enable Cloud Build API

2.1 Search IAM & Admin and give the user [email protected] these rights:

2.2 Enable cloud build api. You go to this link and select project

https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com&redirect=https:%2F%2Fcloud.google.com%2Fcloud-build%2Fdocs%2Fquickstart-docker&_ga=2.170700775.-618198222.1566810450

2.3 Activate Cloud KMS API https://console.cloud.google.com/flows/enableapi?apiid=cloudkms.googleapis.com&redirect=https:%2F%2Fconsole.cloud.google.com&_ga=2.143835250.-618198222.1566810450

2.4 Activate Service Account User permissions and Cloud KMS CryptoKey Decrypter https://console.cloud.google.com/cloud-build/settings?project= {Your project id}

3. Create file cloud-build.yaml

I needed to create a cloud-build.yaml file and push up slightly in this file its source will write the cloud build step that should be taken to deploy nhé you can refer here writing https://cloud.google.com/ cloud-build / docs / build-config

4. Connect repository and create Build Trigger

Note: To be able to connect to a private repo, you need to add configs in the cloudbuild.yaml file. See detailed instructions at the link below: https://cloud.google.com/cloud-build/docs/access-private-github-repos

Next, go to the link https://console.cloud.google.com/cloud-build/triggers?orgonly=true&project= {project id you} select Connect repository. Here I choose to be GitHub (Cloud Build GitHub App) offline

Next you need to choose git to connect, for example below:

Note that to choose git, you must have owner rights

After I complete the steps I will have a trigger like this

Next, you select this edit trigger. In the build configuration section, choose Cloud Build configuration file (yaml or json) and enter the name of the .yaml file I created above here.

In the Event and Source section you can choose different options. Here I configure that if I push to the branch master, it will trigger cloud build

At this point, I have completed the installation. Also you can also run manually with the branch of your choice.

Good luck

Share the news now

Source : Viblo