The process for creating a CI/CD pipeline on GCP can be difficult to navigate for inexperience developers. This post will hopefully clarify the steps to get your app running on GCP using a CI/CD process. Step 1 is to create an Express app and run it locally. Next add an app.yaml file and set the runtime to nodejs10. Create a GitHub account and push your project to the GitHub repository. If you already have a GitHub account, just create a new repository.
You’ll need to create a new GCP project. Once that’s created select your project and navigate to Cloud Source Repositories. On the Cloud Source Repository page on the top right select “Add a Repository”.
Add A Repository
When you add a repository, you’ll have to choose whether to create a new repo or add an external repo. Select “Connect external repository”.
Connect External Repository
Select the “Connect Git Provider” dropdown and then Select GitHub. Choose your repository.
Connect Git Provider
Let’s deploy the app without CI/CD configured first. While in your Cloud Source Repository select “Cloud Console” and then deploy your app to App Engine.
gcloud app deploy app.yaml
App Before CI/CD
Enable the App Engine Admin SDK and register your project.
Enable Register Admin API
Register your application for the Cloud Build API. Grant App Engine access to the Cloud Build service account. The Service Account Configuration is in IAM.
Service Account Registration
Select the pencil icon on the right of the row of the Cloud Build service account. Choose “Add another role”. Select “App Engine” and then “App Engine Admin” then save. Let’s create our cloudbuild.yaml file.
Open the Cloud Build page and click “Create trigger”.
Cloud Build Create Trigger
Set Cloud Source Repository as the source then select your repository. Set the Trigger settings:
- Set the Trigger type to “Branch”
- Under Build Configuration select “cloudbuild.yaml”
- Click “Create trigger”
Cloud Build Config
Time to Test
Make a change to your application to test the build and deployment process. Open the “Cloud Build History” page and verify the build was successful.
Cloud Build History Details
Confirm the deployment to Google App Engine was made successfully.
CI/CD To App Engine
In order not to incur additional charges, you’ll need to delete your GCP project. Many steps were involved in setting up a CI/CD pipeline from GitHub to App Engine. Comparing this process to setting up a CI/CD pipeline in Azure, you’ll see that GCP still have a ways to go. The process in Azure is much more simple and streamlined. Nevertheless, GCP is becoming more user friendly and more importantly, developer friendly. Hopefully the steps above is enough to get you to try GCP. You can find a link to the repository here.