Ishaan
Jan 21, 2023
# **Setting-up GCP Cloud Run Deployment Using Action**
**Step 1:** Create GCP project and enable services for Cloud Run
1. Cloud Build API
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gcp-cr-servuce.png)
2\. Cloud Run API
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gcp-rr-servuce.png)
**Step 2:** Create service account on the GCP project
* Create Account from **IAM & Admin** > **Service Account**
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/service%20account%20email.png)
* Grant Permissions
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/service%20account%20permissions.png)
* Generate KEY
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/generate%20key.png)
* Download Key as json file
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/downlad%20key.png)
**Step 3:** Update workflow of GitHub action
* Add Action Secret in the repo
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gh%20secrests.png)
1. GCP\_PROJECT
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/action%20secret%20project%20name.png)
2\. GCP\_APPLICATION - Name of the service you want
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/action%20secret%20application%20name.png)
3\. GCP\_EMAIL
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/action%20secret%20email.png)
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"
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/vs%20join%20lines.png)
Add to GitHub action secret as
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gh%20secrests%20credentials.png)
* Create custom workflow in GitHub action
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gh-custome%20workflow.png)
* Set the Scripts according branch you want to configure deployment for
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gh-workflow%20script.png)
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
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/commit%20gh.png)
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.
![](https://assets.tina.io/46ec08cf-0f02-4b2b-9ab7-081512548481/gr%20service.png)
You can now use the URL to call the service