Deploying Google Cloud Run from GitHub Release using GitHub Actions

Bashayr Alabdullah
3 min readNov 6, 2021

In my project I have to deploy it on Google Run, but…in such automated way 😎. Fortunately, GitHub Actions automatically execute whenever some event occurs to my repository, so I can implement CI/CD pipeline 🥳. This post shows how to build and deploy your project to Google Run from GitHub.

Technologies

  • Google Run, to deploy my project.
  • GitHub, to create my repository and manage releases.
  • GitHub Actions, to write CI/CD pipeline (workflow).
  • Commitizen: a cli to create commit messages following the Conventional Commits specs (you can install plugin of Conventional Commits, if you’re using Jetbrains or VSCode.).

Note: I want to use only one branch and create the release manually, also I’m using Go language!

I assume:

  • You know what is a continuous integration and continuous delivery (CI/CD).
  • You’re familiar with git commands and know what is GitHub Actions.
  • You know what is Google Run!

Hands-on

Google Cloud Platform (GCP)

You need first to create service account in GCP and give it limited permissions because we’re going to upload all this information on GitHub:

Click Menu → IAM & Admin→ Service Accounts → Create service account and give it these rules:

Then create a key.json to be authenticated with GitHub and allow the Github Action to deploy the project to Cloud Run:

GitHub

Add secret environment variables:

Your repo → Secrets → New repository secret, and add name GCP_PROJECT with your project-id on GCP and GCP_SA_KEY with copying the value of key.json that downloaded before.

GitHub Actions

Now let’s create our workflow! first, we must store workflow files in the .github/workflows directory of the repository:

My project structure

The main.yml holds workflow of deploying my project (staging) to Google Run and release.yml workflow will start when a release published (production in my case).

main.yml
release.yml

Commitizen

To install:

brew install commitizen

Now let’s create some changes on code to test the workflow, and commit the changes using cz commit

Go to Actions in the repo to see the jobs:

I have only one workflow, when I go to the gohibeesh-staging service URL:

but it’s still doesn’t deploy to production, when hit gohibeesh-production service URL:

Let’s publish a release:

The workflow of release is finished! going now to gohibeesh-productio:

I hope you find this helpful, enjoy!

References:

--

--

Bashayr Alabdullah

Salam, I'm Tech Engineer 🚀. I blend technology insights, inspiration, and fun in my feed. #innovation #discovery #ibmer 🥑🎶🎯🌻