/

October 30, 2023

Deploying frontend of an application using Google Cloud Run and Cloud Build from remote repository

Deploying frontend of an application using Google Cloud Run and Cloud Build from remote repository

Introduction

In this documentation, we’ll be deploying our application frontend code which is in our GitHub repository using two services of GCP (Google Cloud Platform), first is Google Cloud Run and then further we will be configuring a trigger using Google Cloud Build service so that whenever a code is pushed in the repository in the branch defined with trigger it will automatically update the application running on the internet.

s2RZ0zBAZ54 zeGgd9Z2FQqYyTyDxBcof0 DiNUZYGObnSaZTEC rCzk7C4HbFjwsHYz3QZizw6J Ye7tWGtGV BMdyqNlW nqeTbpwY C04im9wa 1r8REkCBvbSdC qk3zdz6CzTXTKYpjSQJw9nYAWim5qeyk

Google Cloud Run 

qLGEicUsqeNjD0KfjludI3N44igEW7qcCxdaPoxqRHCHfmZt9muB7d6uvuYVpnC Z7TFxMqWXuFXyKAmGbiM9 Io6lHK3ZhaV31zAsH0BeJDFWbF7mL3MTiGucxE X6LPcOGMtTGSlOYbe8gj GZ9ValIwJ9JtO

Google Cloud Run is a serverless computing platform powered by Google Cloud Platform (GCP) that allows developers to easily deploy and manage containerized applications without the need to manage servers or infrastructure. With Cloud Run, developers can package applications in Docker containers, deploy quickly, and automatically measure as they’re delivered. Key features of Google Cloud Run include auto-scaling, pay-as-you-go pricing, and support for popular programming languages and frameworks. Designed for microservices-based architectures, this software allows developers to easily build and run applications by focusing on writing code rather than managing processes. Google Cloud Run simplifies the deployment and scaling of containerized applications, making it simple and efficient for a variety of applications.

Google Cloud Build

BXGxgN99AHUD7x3 3WovLqA5rGHLoOj6h5ZxW4h0lNwLmCU6dwd9fXrVhmpFDjybAD8h9OIvKpG

Google Cloud Build is a continuous integration/continuous deployment (CI/CD) service provided by Google Cloud Platform (GCP). It automates and simplifies the software development process by allowing developers to create, test, and distribute their code consistently. Cloud Build; It is designed to work seamlessly with popular version control systems such as Git, GitHub, and Bitbucket, and supports multiple programming languages ​​and development tools. Key features include build pipelines, autoscaling for faster execution, and integration with other GCP services such as Kubernetes Engine and App Engine. Cloud Build’s development team improves performance, improves code quality, and accelerates the delivery of software applications, making a valuable contribution to everyday software development.

Steps to implement:

  1. Create a GitHub repository:

Create a Git repository and push your code for the frontend of your application there.

2OcQPeV0Giz70h qPVxW6tywqgie1RepcHlvHjXcPA8gqY0V2lbo BoUuV5
  1. Now go to GCP console by visiting https://cloud.google.com and log in into your account and select the project where you need to deploy the application.
nGYss135LB2zwHPjXTCyXHZK3CsvynMSq81sTrAhwYcWn3zbkTFhXpYta7Evlj7 HLaPlNbS5uxZiC7OmPWIgQregsGRohG03eDdsSloAH5xSsKkHG bJWN2uG7NhyqkDsD93gaW2kGZmkzVzRrM8zuTuTUXYoT
  1. Now type Cloud Run in the search box of your GCP console and click on it. It will open the cloud run service window.
ohXoZpUdhLMQ8tuu5TB9BEXxV9 9MxA1Tm93 xdwv8l6kG5OYFIXh7UOCZMgzqWqyQo
  1. The Cloud Run console will look like this:
edS RTA2Io gqlMuAEtnuITv9C OO5USVfEWWiTaL4Bzfzo4cSX CoyBEEpuk4HjC NaMZsEpCOpNCbFIfRj idEikWkbYjm97kNjJHmd4VksLLrSFTMCMqtqy4cmVEiq2n0snqj piF4SjMNOTaAsZKoBBRSATR
  1. Now click on CREATE SERVICE. This will open the service configuration window for Cloud Run.
s AlAbXsVgEf5rgNsOCH9chI7JISKbrbCl83 XwCuq9F29vDMvk1 lF ARxg390HluvwcF71fxP54XDZLjP2jgXWYzVWAuJDXeXjNCeG6vaMKo98FCgBfZpSEmltB f42QCxBA8eP
  1. Now click on TEST WITH A SAMPLE CONTAINER option for the first time so that it will automatically select the hello image which is default provided by the cloud run to test the service. After that Give a suitable Service Name for your deployment and select the region in which you want to deploy your Cloud Run deployment.
dh9bMlQV2381tckxzEo7GlUCm9fk LbdfRCitGSLaeAcVjV4jtYdPNbEEV8IDsksxAR0Osvfq68juadClxb0dc4aHh t6Jj6e mA7 TFCP9vfDnWFrAAcv1cYY7EU o9uMHwMEE8TppQxK 04Uo5dOX7nPzRQrKo
  1. Select the CPU is only allocated during request processing in the CPU allocation and pricing section.
7Ft 6Lsk56mFBQ33sXN6U1wIdHrEVCFzY EJZNwpaFKKxh UiBqeskznuGH907Jd9Oqa
  1. Under the free tier of GCP First 180,000 vCPU-seconds/month, First 360,000 GiB-seconds/month and 2 million requests/month won’t be chargeable to the user.
  1. In the AUTOSCALING section keep the keep the minimum number of instances to 0 and maximum number of instances to 100.
nkmaEmqgMyAmFXz2SoK NoRj4EkMmQaTbuN9FXd2DB4l B evJ xA79GV89wecysolCDlkiW1Yue M4CQcZM xi8BheAochNs3R hbUXlv 6n5CR G4w5TQIv
  1. In the Ingress control section select the ALL option so that your service is accessible over internet.
kPYoMpxzGWTQcTMKKwyPmLlf1KOyLnaoArwoxcZ4ESfDgle7Qoh 9kzcm8AkV0FTs zgK0fPmC0pd
  1. Now in the Authentication section select the Allow unauthenticated invocations and select this option only if you wish to make your API public or a public website
oWVXIqK7lMRwRpyvWWDDfQeX7p1xXQE2zhwzIckmJte3GV39R2zoMEigXjA
  1. Now click on the Container, Networking, Security section and here you can select the Container Port, Capacity of the container, max timeout and concurrent request per second. By default they are set as max timeout 300 seconds and 80 concurrent request per second.
5MCVQAjfFJGvET2Y7DaMiyiLiSHHSMUhcy6pYx4PSpeuEAaMyMLwXT7t8LzDYLbGqCyhmeUC3KD1DEwJ1zVAZYpATp3Z4ao3MCHdcN NsirR ccrDi5ESbFHBzycDiC ZysX52lDoiJF9NTfoADIOkfWLmtvqAmy
sv8ruLPYL4ef ci8C2JFi9C8fGAn vKTQhNWVFlGWro2Yl9qR5irD03UinlvJ0iIvcLMJHEthiS8vwzj WHuR b UcIwi2Y5mHFF1Tx8hfEOiaT2QNICPD3RnBCPXUuETnekGT3Y2oMTj 4MwZ8s3fZILf 9Nuc3
  1. Now in the Execution Environment section select the default option.
v64 YFfwQfvky Rpww6P7bHvdBgCQg uOAvYVUArW4H injQrKeYLcIy1ahQN0XS6u8FJ07 8YoVeliQb9CcrpNrd78Y6RLEGIeWid9CzwULbuV3t8aNpPiN2t0Q9HzgbsV5QtYXVDX2WJaaPEPboj2soiR9VgbD
  1. Once the service is created using the default hello container image you will see a dashboard for this cloud run service.
6MlrAUiOsZkqK4vBFE SCG5 yfLpxE3cnQk43Pd00ibbyJDfvz8mAzfzc5OAcF5hZN5pdIr FaHjgzf MNCPkWmKKIdlusT6ZvIRI
  1. Now here we can see a auto-generated url from this clous run service if we click on this URL it will redirect to the hello container and display its successful deployment message on our browser.
jQ yN oxtnnUJKA9Wd5czzp7OvYTnVEDu iJlgBf64AtBUIkK8TL3h5xHzOCc0cagYULDyZX6J5cS7q kwVgi qlTu6HJGCSkNkRrWAA2b58mAaSBMVI0oZ2bv77hkJLMXZXTQ84
  1. Now for using the Cloud Build  service click on the SETUP THE CONTINOUS DEPLOYMENT option.
JaSaVkTGEjPasqgKEz3yRav1LM8K7z3U5ELKoiUI5tnz2xxxZeMdVgTqfGKFdIh DU Hpgnkq7F1ywhFYfJTC5dla3RL3loyWfEuNv7C94vYtGYs6UKe R
  1. The SETUP with CLOUD BUILD dialog box will open where you can authenticate your GitHub account and then select your repository and the branch from which you want your deployment to be picked whenever a push is made to the code from this branch. And once created a trigger will be attached to this Cloud Run service.
FqM7pUIk1Ht07TFGYbmYJ32rii C4NJdZEC kU3FrFiVCI4tLMTc2JrTQqFjy8I4gcMygbPywihZV39Mk
  1. Now type Cloud Build in the search option of your GCP console and click on it.
6EC
  1. Once the CLOUD BUILD is open go to TRIGGERS and click on them.
O9tTpjpc68lfwtagCmmJLOVuL JhY0rZn3aSKAvxSg0YJnaTusTO 6pGJk85VPsrHX dgGXcyc6Z5nLMqpVT4OoKsDKzDUTPFiH7DgZcl8DIAy3YREEOvZvt35WmZCjsp0Yzui3hYevJaUU GrC30AboL1a9B1UT
  1. Select the trigger associated to your CLOUD RUN services and click on EDIT option.

It will open the Edit Trigger dialog box you will be able to se the short description of your trigger and from which repository it is linked.

lLyKohF87hgStukCUdSOEdblhWNiTaTn20KxwyM9rn9Y6M7200Yd L7xCly1u8tYSUh WM5B4MB O6qrxIeAKszTw4YA5bqtzx1dtT6pIDQBJxveITQJaHpwGZleswEgG gN6nPRsE1WwumnnGf4Fj etLajdnM
  1. Now create a cloudbuild.yaml which will instruct the cloudbuild while reading your repository that what instructions should be followed in order to build this code ands deploy it to cloud run.

steps:

  # Build the Docker image

  – name: ‘gcr.io/cloud-builders/docker’

    args: [

      ‘build’, 

      ‘-t’, ‘gcr.io/$PROJECT_ID/<yourcloudrunservicename>$SHORT_SHA’, 

      ‘–build-arg’, ‘GENERATE_SOURCE_MAP=${_GENERATE_SOURCE_MAP}’,

      ‘–build-arg’, ‘REACT_APP_MODULE_NAME=${_REACT_APP_MODULE_NAME}’,

      ‘–build-arg’, ‘REACT_APP_API_URL=${_REACT_APP_API_URL}’,

      ‘–build-arg’, ‘SKIP_PREFLIGHT_CHECK=${_SKIP_PREFLIGHT_CHECK}’,

      ‘.’

    ]

  # Push the Docker image to Google Container Registry

  – name: ‘gcr.io/cloud-builders/docker’

    args: [‘push’, ‘gcr.io/$PROJECT_ID/<yourcloudrunservicename>:$SHORT_SHA’]

  # Deploy to Cloud Run

  – name: ‘gcr.io/cloud-builders/gcloud’

    args: [‘run’, ‘deploy’, ‘<yourcloudrunservicename>’, ‘–image’, ‘gcr.io/$PROJECT_ID/<yourcloudrunservicename>:$SHORT_SHA’, ‘–platform’, ‘managed’, ‘–region’, ‘<your-region>’, ‘–allow-unauthenticated’, ‘–port’, ‘8080’, ‘–timeout’ , ‘900’]

And save this file as cloudbuild.yaml and push this file to your remote repository and comeback to your edit trigger option and scroll down to the Configuration option and select type as cloudbuild configuration file and Location as Repository

tQOGBgKmHq9JZOs2nZFs8wPT1iCkB gR0C3BYGHhu7qiHHkO0y6 4cvamFB GBIzyFiT9iBOD841Lx6GwuNR59aRNCYb8VOWBy61AVMrS IpSMFCM1MHRm CzmkwNqFROSsMvJjGO7aWVRhL3kcwj0HkEJvVBpdq
  1. Now scroll down to the Environment variables section and add the variables that are required for your application and click on save.
  2. Now you have successfully configured the continuous deployment setup and whenever a code will be pushed it will automatically fetch the changes the from your source repository build it and deploy it to your cloud run.
BkSK Uu4bznqr5H 8w Ydx4cEZrdmvySvNDx27sAjUmGQtvW L8zZKW ESZEnAgucRVwXdWbHrSq7LCeXEW qV U300uggpyjYb5usd
  1.  Once the build is completed you can visit your cloud run autogenerated url and now when you click on it you will be able to see your application’s frontend is deployed and accessible through your Cloud Run service URL.
EgARMBVmet wxUUM8ObPOw2PbQvFVes2qKcN6oiR SlvvyUHWst7WtwsOdJ2RQTxSSBzotYeuXJ2mDBG1J3w8aaDN1g5l4nrXghahqBsR5BWxYDY5fCLgprKkj xIDc0RKfxDSGvMqpHhyKFCperMq

So, in this documentation we deployed our application’s frontend using the Cloud Run and Cloud Build services of GCP (Google Cloud Platform).