image

Ishaan

Setting-up GCP Cloud Run deployment using action

Step 1: Create GCP project and enable services for Cloud Run

  1. Cloud Build API

2. Cloud Run API

Step 2: create service account on the GCP project

  • Create Account from IAM & Admin > Service Account

  • Grant Permissions

  • Generate KEY

  • Download Key as json file

Step 3: Update workflow of GitHub action

  • Add Action Secret in the repo

  1. GCP_PROJECT

2. GCP_APPLICATION - Name of the service you want

3. GCP_EMAIL

4. GCP_CREDENTIALS

a. Open the Service Account JSON key in VS code

b. select - all (ctrl +a / cmd + a)

c. Execute Global Command (ctrl + shift + p / cmd + shift + p) -> "Join Lines"

Add to GitHub action secret as

  • Create custom workflow in GitHub action

  • Set the Scripts according branch you want to configure deployment for



name: cloudrun-deploy

on:

push:

branches:

- main

jobs:

setup-build-publish-deploy:

name: Setup, Build, Publish, and Deploy

runs-on: ubuntu-latest

steps:

- name: Checkout

uses: actions/checkout@master


# Setup gcloud CLI

- uses: google-github-actions/setup-gcloud@v0.6.0

with:

service_account_email: ${{ secrets.GCP_EMAIL }}

service_account_key: ${{ secrets.GCP_CREDENTIALS }}

export_default_credentials: true


# Configure Docker with Credentials

- name: Configure Docker

run: |

gcloud auth configure-docker


# Build the Docker image

- name: Build & Publish

run: |

gcloud config set project ${{ secrets.GCP_PROJECT }}

gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_APPLICATION }}

gcloud config set run/region us-central1


# Deploy the Docker image to the GKE cluster

- name: Deploy

run: |

gcloud run deploy ${{ secrets.GCP_APPLICATION }} --image gcr.io/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_APPLICATION }} \

--platform managed \

--allow-unauthenticated \

--memory=1Gi \

--region asia-south2


Commit the file

Push changes and wait for few sconds.

You can navigate to actions and observe action is in progress. take a look at the execution to make sure it won't break.

on successful completion you can see your service is running on GCP cloud run.

You can now use the URL to call the service

image

Ishaan

Architect
ishaan@fabbuilder.com

I love finding patterns and concluding insights out of it. After working as Employee, a Consultant, a Freelancer I figured out mostly we start our project or a module or microservice either by copying an existing code or base repositories from GitHub lets say. And then spend a lot of time on customising it, analysing pitfalls, making it work so that I can start wrinting business logic for the work. So, I started POC-ing FAB Builder so that I get a trailered project targetted to my requirements and on which I can start wrinting business logic within few mins. This makes my life easy and my clients get a better quality products which are easy to modify and easy to maintain.