UCONN

UCONN
UCONN

Google Cloud Run

                                     Google Cloud Run


Google Cloud Run is a managed compute platform. 

Allows running of front-end and back-end services, batch jobs and websites.

Cloud run is based on containers. You need to package your code and the dependencies for that code in a Docker container.

You first need to create a container image of your app.

Next you need to push the image to the Artifact Registry which stores and  manages these images.

A URL is built allowing the users to run the code.

No infrastructure is needed. Cloud run provides that.

Only pay when traffic occurs, not when idle.

Can run concurrently meaning can handle many requests at the same time.

It supports automatic scaling which will provide computing resources as traffic occurs.

It simplifies running workloads and provides fully managed compute to run containers that can scale up and down depending on traffic.

Also, secure endpoints are delivered using TLS.

API’s

Google Cloud APIs & Services allow cloud developers to access Google's  infrastructure.

Service is a product you will need to build various types of projects.

API (Application Programming Interface) allows you to access key functionality needed for those projects. In order to use key Google functionality the developer must enable the specific API needed for the projects.


Note: You may need to turn on 2FA

Go to settings

Then Turn on 2-Step Verification

Then click Done


For Cloud run we need to enable the  Cloud Run Admin API 

To do this we need to search for APIs & Services


And click the APIs & Services link

Then click Enable APIs and services link



Search for Cloud Run Admin API


Click Enable


Next we need to enable the Artifact Registry API

This is needed to store container images

Then enable Cloud Build API which lets Google build code into a Container.





Hello world cloud run


Create a directory for your hello world application


john_iacovacci1@cloudshell:~ (cloud-project-examples)$ mkdir hellocloud

john_iacovacci1@cloudshell:~ (cloud-project-examples)$ cd hellocloud

john_iacovacci1@cloudshell:~/hellocloud (cloud-project-examples)$ 


Create a main.py file in that directory


====================================================

import os

from flask import Flask

app = Flask(__name__)

@app.route("/")

def hello_world():

   return f"Hello Google World!"

if __name__ == "__main__":

    port = int(os.environ.get("PORT", 8080))

    app.run(debug=True, host="0.0.0.0", port=port)

====================================================

Next we need to create a requirements.txt file for the application

====================================================

Flask==3.0.0

gunicorn==21.2.0

====================================================

We are now ready to deploy this application


john_iacovacci1@cloudshell:~/hellocloud (cloud-project-examples)$ gcloud run deploy python-hello-world --source . --allow-unauthenticated --region us-central1

Deploying from source requires an Artifact Registry Docker repository to store built containers. A repository named [cloud-run-source-deploy] in region 

[us-central1] will be created.


Do you want to continue (Y/n)?  Y


Building using Buildpacks and deploying container to Cloud Run service [python-hello-world] in project [cloud-project-examples] region [us-central1]

Building and deploying...                                                                                                      

  Validating Service...done                                                                                                    

  Uploading sources...done                                                                                                     

  Building Container... Logs are available at [https://console.cloud.google.com/cloud-build/builds;region=us-central1/191656d0-

  738d-4248-a4f3-726747439ba0?project=517129368909]....done                                                                    

  Setting IAM Policy...done                                                                                                    

  Creating Revision...done                                                                                                     

  Routing traffic...done                                                                                                       

Done.                                                                                                                          

Service [python-hello-world] revision [python-hello-world-00004-466] has been deployed and is serving 100 percent of traffic.

Service URL: https://python-hello-world-517129368909.us-central1.run.app

john_iacovacci1@cloudshell:~/hellocloud (cloud-project-examples)$ 

Click on link brings message up in browser



No comments:

Post a Comment

Assignment #2 due 2/13/26

Create a web site with  main page of index.html and 2 other linked original content  html pages (join.html, about.html) At least 2 links to ...