Automated CI/CD Deployment to App Engine with Cloud Build

Cloudbooklet
3 min readNov 24, 2020

Automated CI/CD Deployment to App Engine with Cloud Build. In this guide you are going to learn how to setup a CI/CD deployment which deploys the code to App Engine when a push is made to a specific branch in GitHub using Google Cloud Build.

Prerequisites

  • A Git repository with your source code. Learn more about Git workflow.
  • A Google Cloud account with billing activated.
  • App Engine application created.

Setup Source Repository in Google Cloud

Go to your Google Cloud console and navigate to Tools >> Source Repository and click on Add repository.

You can create a new repository or you can connect to an existing repository.

If you need to connect to an existing repository you need to choose Connect external repository.

Choose your project id and your git provider for example GitHub.

Click Connect to GitHub.

Click Authorize Google Cloud Platform.

Now you will see all your repositories in your GCP project page.

Click Connect selected repository.

Now you will see your repository added to the Source Repositories in Google cloud.

Configure Cloud Build for Automated Deployment

Go to your Google Cloud console and navigate to Tools >> Cloud Build >> Triggers. If you haven’t enabled this API you will be prompted to enable this API.

Click Create Trigger.

Enter Name of trigger.

In Event choose Push to Branch.

In the Source choose the repository you added earlier.

In the Branch enter the branch name for which you wish to trigger the build.

In the Build Configuration choose Cloud Build configuration file.

Enter cloudbuild.yaml.

Configure Cloud Build and App YAML files

Create a new cloudbuild.yaml file in your repository root.

Add the following contents triggering the gcloud app deploy.

steps:
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: 'bash'
args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']
timeout: '1600s'

Create a new app.yaml file in your repository root.

Add the following contents for deployment.

This is an example of deploying a static HTML site.

runtime: nodejs12handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(www/.*)$
static_files: www/\1.html
upload: www/.*\.html$

Now your configurations are in place. You can try making changes to your repository. Once a push is made to the specific branch your repository will get synced to Source Repositories and deployed to App Engine.

Conclusion

Now you have learned how to setup automated deployments to App Engine with Cloud Build and GitHub.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

--

--

Cloudbooklet

Discover the power of AI, data science, and cloud technology with our insightful blog. Stay ahead of the curve with the latest trends and strategies.