This project has a number of examples of using Github Actions with Google Cloud, namely:
- Invoking Cloud Build to build our container ...
First we need to set up our GitHub environment to work with Google Cloud.
Setting up GitHub Actions for automated deployments with Terraform requires the Google Cloud administrator to create a fork of this repository, to personalize variable settings for your unique cloud environment.
-
Create a fork of this repository on the GitHub site. Instructions here.
-
Clone your new fork:
git clone https://github.com/<your-github-username>/gke-github-deployment.git
To setup GitHub Actions securely with our Google Cloud environment we will need to do a one time setup for Workload Identity federation through a Google Cloud service account. More info here.
Run this script:
bash ./scripts/enable-ghactions.shMake note of the returned output from running this script. It will look like this:
----- GITHUB ACTIONS ENV KEY/VALUE -----
GCP_SA_GITHUB_ACTIONS: sa-tf-gh-actions
GCP_PROJECT_ID: <your-project-id>
GCP_CUSTOMER_ID: <your-customer-id>
GCP_LOCATION: <gcp-region>
GCP_WI_PROVIDER_ID: <workload-id-provider-id>
----------------------------------------
You will need these values to finish setting up GitHub Actions.
Note: If using the GitHub CLI (
gh) these values will be populated for you in declared repo.
Run this script:
bash ./scripts/enable-iam.shWith the key/value pairs outputted from the script in the previous step, follow these steps:
- In the Settings tab on the GitHub page for your fork, go to: Secrets and Variables > Actions
- Click on the Variables tab
- Click the New repository variable green button
- Enter in your key value pairs
You should see the entries here if using gh cli. If not enter them manually.
You can use the CloudBuild CI GitHub action to build and push containers to Artifact Registry, where they will later be used to deploy to a container runtime environment like Cloud Run or GKE.