Set-up CI/CD using Github Actions and Google Cloud Build

David Anderson
2 min readMar 13, 2023

--

I'm starting a new side project and want to document my decisions and write documentations for the steps I took so that others can have an easier time on starting a new project and want to use Cloud Native solutions.

For no better reason other than I’m familiar and like the opinions of Github and GCP, I’m choosing these 2 providers for the infrastructure of this project.

The first thing I like to set-up on any project is the CI/CD pipeline.
Having your code be integrated, tested and deployed without any manual action is a must.
Here's what you need to do:

1. Enable Google Cloud Run on your GCP Console.

2. When installing, follow the guides on GCP do not create a trigger yet. Instead of using those triggers, we'll set-up Github to trigger Cloud build instead.

3. We’ll give Github access to our GCP account. The best way to do that is by creating a Service Account with limited rights to our repo. If the key ever leaks, we shouldn’t worry about undue access, and this makes it easier to revoke as well.

Go to IAM Services Accounts and create a new one. Grant the "Cloud build editor" role.

4. On your newly created account, click on Actions and Choose "Keys". We need to create a new one to allow Github to connect to your Google Account. Download the file and store it securely. We'll need it soon.

5. Github Actions will invoke Cloud Build via its API. The last step on GCP console we need to do is enable the Cloud Build API. Go to the Cloud Build API and enable it.

With the API enabled and a Service Account Key with access to Cloud Build, we can go to Github.

1. Install the Cloud Run plugin on your Github organisation.

2. Go to your Repository Settings, and there click on Configure on the Google Cloud Build plugin. Choose the repositories that this plugin should have access to

3. Go to your Repository settings and under Secrets and variables, choose Actions

4. Name your secret and paste into the value the contents of the JSON key you got from GCP earlier.

5. Now you just need to create your own github workflow file that triggers the build in Google Cloud Build. GCP provides an example to help you get started.

That's all! Now whenever you commit to your repo, it will automatically be built using Cloud Build!

--

--

David Anderson

With a product and business mindset, focused on positive impact. I help engineers, managers and companies grow in a sustainable and productive way.