App Engine Google Cloud

Automated CI/CD Deployment to App Engine with Cloud Build

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.

Best Hosting for your Business

PlatformReviewsPricing
Cloudways★★★★★$10
Kinsta – Google Cloud★★★★★$30

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.

Add a 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.

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: nodejs12

handlers:
  - 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 builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.