Automating Google Cloud with GitHub Actions using gcloud CLI
Los Angeles
Search for a command to run...
Los Angeles
No comments yet. Be the first to comment.
Overview Why would you want to run a scheduled Bash script in the cloud? Couldn’t you just run cron on your local machine? Running a bash script in the cloud rather than on a local machine offers developers a multitude of advantages that can enhance ...
Everything you need to ingest, store, and analyze billions of IPv4 & IPv6 addresses at interactive speed. Why a native IP data type? Storing every address as a plain string inflates segment size, hurts bitmap selectivity, and forces costly runtime ...
Apache Druid is a high-performance, real-time analytics database designed for large-scale data processing. Among its powerful features is the ability to handle geospatial data, enabling fast and efficient queries over latitude and longitude coordinat...
Overview Why would you want to run a scheduled Bash script in the cloud? Couldn’t you just run cron on your local machine? Running a bash script in the cloud rather than on a local machine offers developers a multitude of advantages that can enhance ...
What is Streaming Engine "By default, the Dataflow pipeline runner executes the steps of your streaming pipeline entirely on worker virtual machines, consuming worker CPU, memory, and Persistent Disk storage. Dataflow's Streaming Engine moves pipelin...
In today's DevOps landscape, automating tasks and deployments is essential for efficiency and reliability. One powerful way to achieve this is by leveraging GitHub Actions to connect with Google Cloud Platform (GCP) using the gcloud CLI. In this post, I'll walk you through setting up a GitHub Action workflow to use the gcloud CLI, allowing you to perform various tasks in GCP directly from your GitHub repository.
Google Cloud Account: You need access to GCP and sufficient permissions to perform actions, such as deploying applications or managing resources.
GitHub Repository: Ensure you have a repository where you want to set up the workflow.
gcloud CLI: Familiarity with the gcloud CLI is helpful, but not required, as we'll cover the basic commands needed.
First, create a service account in your Google Cloud project with the necessary permissions:
Navigate to the IAM & Admin section in the Google Cloud Console.
Select Service Accounts and create a new service account.
Assign the necessary roles for the actions you wish to automate. For example, you might need roles such as roles/storage.admin for Cloud Storage tasks or roles/compute.admin for Compute Engine tasks.
Generate a JSON key for the service account and download it. You'll use this key to authenticate in your GitHub Actions workflow.
Go to your GitHub repository.
Navigate to Settings > Secrets and variables > Actions.
Click on New repository secret.
Add a new secret with the name GCP_SERVICE_ACCOUNT_KEY.
Copy the content of the JSON key file and paste it as the secret value.
Create a GitHub Actions workflow file in your repository. Here’s an example configuration:
name: GCP Deployment
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
- name: 'Use gcloud CLI'
run: 'gcloud info'
auth action sets Application Default Credentials, then the setup-gcloud action references these credentials to configure gcloud credentials. The setup-gcloud action installs the Cloud SDK (gcloud).Commit and push your changes to your GitHub repository. Navigate to the Actions tab to see the workflow run and validate the output. Make sure that all steps are completed successfully and that the desired actions are performed in your GCP environment.