This workshop is brought to you by DoiT. DoiT provides intelligent technology to simplify and automate public cloud use, alongside expert consultancy and unlimited technical support for digitally savvy companies. An award-winning strategic partner of Google Cloud and AWS, DoiT operates in more than 70 countries worldwide. For more information, visit doit.com.

πŸ“‹ Cloud Run Workshop Agenda

To give you a sense of what to expect during the workshop and help you prepare and plan your time accordingly, the topics covered in this workshop include:

πŸ“…Topics covered:

During the next two hours, we may not be able to complete all of the tasks, but try our best to get the most.

Feel free to ask questions πŸ€” and seek help from the workshop mentor πŸ§‘β€πŸ« or others in the workshop πŸ‘₯. Remember to have fun πŸŽ‰ and learn as much as possible πŸ€“.

Collaborative learning 🀝 can help ensure that you get the most out of the workshop πŸ“ˆ.

πŸ’ͺLet’s get moving!

It’s time to put on your running shoes and explore Cloud Run!. You’ll be sprinting through the guides and examples to gain a better understanding of how Cloud Run works and what it can do. By the end of this workshop, you’ll be ready to start deploying your own applications to the platform.

πŸ› οΈGoogle Cloud Setup & Introduction

❓ What is Cloud Run?

πŸ’ΌGoogle Cloud Run is a serverless platform that lets users run their applications in a fully managed environment without worrying about infrastructure. Cloud Run is built on top of Knative, an open-source project that provides middleware components for building modern, event-driven, cloud-native applications. Knative enables Cloud Run to offer features such as automatic scaling and traffic routing, making it easy for developers to focus on building their applications without worrying about the underlying infrastructure.

πŸ”₯Highlights:
πŸ™‹β€β™€οΈWant to learn more?

πŸ’² Free Trial & Pricing

Google Cloud Free Trial offers free usage of Google Cloud services for a limited amount.

πŸ“Cloud Run features in the Google Cloud Free Trial:
πŸ™‹Want to learn more?

πŸ†• Task 1: Create a Google Cloud Project

πŸ‘‹Hey!

Before you can start using Google Cloud Run, you need to have a Google Cloud account and be logged in to the Google Cloud Console. You can follow the step-by-step instructions below to create a Google Cloud account and log in to the console, so that you are ready to get started.

πŸ’‘Smart!

It is often best to use a dedicated Google Cloud project for a workshop to avoid potential conflicts or issues. You can create a new project specifically for the workshop by following the instructions below.

πŸ‘©β€πŸ’ΌSteps
πŸ†Congratulations!

In this task, you visited the Google Cloud Console and created a new project with a unique name.

πŸ™‹Want to learn more?

πŸ’» Task 2: Set up Cloud Shell

πŸ‘‹Hey!

In this task, you will learn how to open the Google Cloud Shell and use it to manage your Google Cloud project.

πŸ’‘Smart!

The πŸ’» Cloud Shell is a powerful tool that allows you to run commands and manage your Google Cloud resources directly from your web browser. It is pre-installed with the gcloud command-line tool, so you can use it to run commands and manage your project without having to install the gcloud tool on your local machine.

πŸ§‘β€πŸ’ΌSteps
πŸ“ŒCongratulations!

You can now proceed to the next task in the workshop.

πŸ™‹β€β™€οΈWant to learn more?

πŸ“ Task 3: Cloud Shell Editor

πŸ‘‹Hey! Time to hype the type!

The πŸ“ Cloud Shell Editor is a built-in code editor that you can use to create and edit files directly from your browser. This can be useful when working with Cloud Run, as you can use the editor to create and modify your application code and configuration files without having to switch to a separate code editor on your local machine.

πŸ‘¨β€πŸ’ΌSteps to Coding Mastery:
πŸ«…Congratulations!

You can now proceed to the next task in the workshop.

πŸ™‹Want to learn more?

πŸ“š Task 4: Cloud Run Documentation

πŸŽ“οΈHey!

During this workshop, spend some time exploring the Cloud Run documentation and reading through the guides and examples. This will help you to understand how Cloud Run works, and will give you the knowledge you need to start deploying your applications to the platform. During this workshop, we will be using the quickstart guides to deploy our application to Cloud Run. It includes a reference section that provides detailed descriptions of the Cloud Run API and other technical details.

πŸ§‘β€πŸŽ“You now possess the knowledge

…and ready to proceed to the next task in the workshop.!

Now that you’ve explored the Cloud Run documentation, you’re ready to take on the next challenge in the workshop. Let’s go!

πŸ–₯️Cloud Run - Deploying using Cloud Console

⭐️This is the fun part!

Now that you have set up your Google Cloud project and enabled the necessary APIs, it’s time to start deploying applications to Cloud Run.

In this section of the workshop, you will learn how to use Cloud Run to deploy and run your applications in a fully managed environment. You will learn how to build and package your applications, how to configure and manage your deployments, and how to get your applications up and running on Cloud Run.

πŸ’ͺLets go!

By the end of this section, you should have a good understanding of how to use Cloud Run to deploy and manage your applications, and you will be ready to start building and deploying your own applications on the platform. Let’s get started!

πŸ–₯️ Task 5: Explore the Cloud Run console

πŸ‘‹Let’s take a look around!

In this task, we’ll be exploring the Google Cloud Console, the primary interface for managing and interacting with Google Cloud resources. By familiarizing yourself with the console, you’ll be better equipped to use it during the workshop.

πŸ‘©β€πŸ’ΌSteps
πŸ₯‡Congratulations!

You have successfully deployed your first Google Cloud Run service!

πŸ™‹Want to learn more?

🧹Task 6: Cleanup using Cloud Console

πŸ‘‹Hey there!

In this task, we’ll be cleaning up deployed services in Cloud Run using the Google Cloud Console.

πŸ§‘β€πŸ’ΌSteps
πŸ”₯Be careful!

When deploying the Cloud Run service with the local deployment option of Cloud Code in the Cloud Shell Editor, several additional resources are created in your project. Let’s find them and clean them up as well.

πŸ‘©β€πŸ’ΌSteps
πŸ™‹β€β™€οΈWant to learn more?

πŸ€–Cloud Run - Deploying using the Command Line

⭐️Take your deployment skill to the next level

In this section, you’ll learn how to use the Cloud Shell command line to deploy applications to Cloud Run.

Deploy and run your applications in a fully managed environment. You will learn how to build and package your applications, how to configure and manage your deployments, and how to get your applications up and running on Cloud Run.

πŸ‘¨β€πŸ’»Become a command line pro

By the end of this section, you will be a pro at using the Cloud Shell command line to deploy and manage your applications on Cloud Run. Let’s get started! πŸ’ͺ

πŸ’»Task 7: Deployment using the CLI

⭐️Deploy to Cloud Run with the CLI

In this task, you will use the command-line interface (CLI) to deploy your application to Cloud Run. This allows you to quickly and easily deploy your application without building and managing container images.

πŸ‘¨β€πŸ’ΌSteps
πŸŽ‰Congratulations!

Congratulations! You have successfully deployed an application to Google Cloud Run using the CLI.

πŸ™‹Want to learn more?

πŸ—οΈTask 8: Exploring Cloud Build

πŸ‘‹Hey!

In this task, you will learn how to inspect the build job logs to see the details about where Cloud Build stores the source files, the image, and the output of the build process.

πŸ§‘β€πŸ’ΌSteps
πŸ“ŒCongratulations!

You have successfully explored the Cloud Build job that was used by Cloud Run to create a container from the source files in your project. You have learned how to list, describe, and view the logs for Cloud Build jobs, and you have gained a deeper understanding of the build process, and how Cloud Run and Cloud Build work together to deploy your application to the cloud.

πŸ“Note

You can continue to use the gcloud builds command to list, describe, and view the logs for Cloud Build jobs, as needed. You can also use the gcloud run command to monitor and manage your Cloud Run services, and to explore other features and capabilities of Cloud Run.

πŸ™‹β€β™€οΈWant to learn more?

πŸ“ˆTask 9: Deploy a new version of the application

πŸ‘‹Hey!

In this task, you will learn how to deploy new versions of your Cloud Run service, and how to manage and roll back to previous revisions if necessary.

πŸ‘©β€πŸ’ΌSteps
🚦Congratulations!

In this task, you learned how to deploy new revisions of your Cloud Run service, and how to manage and roll back to previous revisions if necessary. You can use these skills to deploy updates to your Cloud Run services and manage the different versions of your service. πŸ™Œ

πŸ™‹Want to learn more?

πŸ“ˆTask 10: Scaling Services in Cloud Run

πŸ‘‹Hey!

In this task, we will learn how to scale our applications in Cloud Run. Scaling refers to the process of increasing or decreasing the number of instances of a service in response to changes in traffic. This can help us ensure that our applications can handle varying levels of traffic and remain performant and reliable.

We will cover how to scale services manually using the Cloud Run command-line interface (CLI) and the Cloud Run console, as well as how to set up automatic scaling based on predefined criteria.

πŸ§‘β€πŸ’ΌSteps
πŸ“ŒCongratulations!

In this task, you learned how to scale Cloud Run services manually using the command-line interface and the Cloud Run console, as well as how to set up automatic scaling based on predefined criteria. This is an important skill, as it allows you to manage the performance and reliability of your applications in Cloud Run.

πŸ™‹Want to learn more?

🧹Task 11: Clean up deployed services

πŸ‘‹Hey!

In this task, you will learn how to remove the created resources from your Google Cloud project. It is useful if you want to clean up your project and avoid incurring any unnecessary costs or charges.

πŸ“Note

Even after you deleted the Cloud Run service, your project may include resources such as Cloud Build, Artifact Registry, Cloud Storage buckets with assets, Pub/Sub topics, IAM roles, and other types created during the process.

πŸ‘¨β€πŸ’ΌSteps
🚨Important

As a last resort, removing the whole project will also remove all of the resources located in that project.

🧼Congratulations!

In this task, you learned how to remove Cloud Run services, source files from your Artifact Registry, and Cloud Storage buckets from your Google Cloud project. This is an optional step, but it is useful for cleaning up your project and avoiding unnecessary costs or charges. πŸ’Ό

πŸ™‹β€β™€οΈWant to learn more?

πŸ”§Task 13: Cloud Run Scheduled Jobs & custom containers

πŸ‘‹Hey!

In this task, we will learn how to schedule jobs in Cloud Run. Scheduled jobs allow us to run a Cloud Run service on a regular basis, according to a schedule that we define. This can be useful for tasks such as data processing, backups, and other types of periodic work. We will cover how to schedule jobs using the Cloud Run command-line interface (CLI) and the Cloud Run console, as well as how to view and modify the schedule for a job.

πŸ§‘β€πŸ’ΌSteps
🧹Cleanup

In previous sections we covered required commands for cleanup of resources. In this section, in addition to cleaning up the Cloud Run service it is also recommended to remove the IAM Service Account and Cloud Scheduler job.

πŸ₯‡Congratulations!

In this task, you learned how to use Cloud Scheduler to schedule jobs in Cloud Run using the command-line interface.

πŸ™‹β€β™€οΈWant to learn more?

πŸ’Reference material:

πŸ™‹β€β™€οΈWant to learn more?
πŸ•΅οΈEven more!?

If this introductory workshop was not enough, you can practice your skills with even more in-depth and diverse workshops:

πŸŽ‰Congratulations!

You are now a Cloud Run expert! The world anxiously awaits your next big thing. Good luck!

πŸ’Ύ Extras & unfinished tasks that need some polish

πŸ” Task XXX: Monitoring, Observability & Troubleshooting Cloud Run Services

🫢 Task XXX: Integrating with Cloud APIs and Databases

πŸ‘‹In this task, we will learn how to integrate our Cloud Run services with databases and APIs. This can be useful for building applications that need to store and retrieve data, or communicate with other services. We will use a free-tier API that is available in Google Cloud as our target for integration, and we will cover the necessary steps and commands to set up and test the integration."

πŸ§‘β€πŸ’ΌSteps

  • For this example, we will use the Cloud Natural Language API, which is a free-tier API in Google Cloud. To enable the API, run the following command:

    gcloud services enable language.googleapis.com
  • Once you have enabled the Natural Language API, you can use the gcloud alpha run command to grant the Cloud Run internal Service Account access to the API. This will allow your Cloud Run service to access the API without the need for an API key.

    gcloud alpha run services update [SERVICE_NAME] \
      --add-service-account [PROJECT_NUMBER]@cloudservices.gserviceaccount.com
  • Next, ensure that your Cloud Run service has the necessary dependencies and configuration to access the API. Update the Flask server dependencies by using the pip freeze command to generate a new requirements.txt file that includes the google-cloud-language library. To do this, run the following commands:

    pip install google-cloud-language
    pip freeze > requirements.txt
  • With the Natural Language API enabled and the Cloud Run internal Service Account granted access, you can update our simple Python Flask web application to use the Natural Language API to process requests. Update the Flask server route that you want to use the API (e.g.Β /) to call the API using the google-cloud-language library. For example, to analyze the sentiment of a piece of text using the API, you can use the following code in your Flask route:

    from google.cloud import language
    from google.cloud.language import enums
    from google.cloud.language import types
    from flask import Flask
    from flask import request
    
    app = Flask(__name__)
    
    @app.route('/')
    def analyze_text():
        # Extract the query string from the request
        text = request.args.get('text')
    
        # Create a client for the Natural Language API
        client = language.LanguageServiceClient()
    
        # Set the type of analysis to perform (sentiment analysis)
        type_ = enums.Document.Type.PLAIN_TEXT
    
        # Set the language of the text to analyze
        language = "en"
    
        # Create a document object with the text to analyze
        document = types.Document(
            content=text,
            type=type_,
            language=language
        )
    
        # Perform sentiment analysis on the text
        sentiment = client.analyze_sentiment(document=document).document_sentiment
    
        # Return the sentiment score and magnitude to the user's browser
        return "Sentiment score: {}\nSentiment magnitude: {}".format(
            sentiment.score,
            sentiment.magnitude
        )
    
    if __name__ == '__main__':
        app.run()

    With this Python Flask web application, you can deploy your Cloud Run service and make requests to it with a query string. The service will use the Natural Language API to analyze the query string and return the sentiment score and magnitude to the user’s browser.

  • Finally, deploy the updated Flask server to Cloud Run using the gcloud run deploy command. This will make the updated server available to users, allowing them to access the API through the Flask server. For example, to deploy the updated server, you can run the following command:

    gcloud run deploy [SERVICE_NAME] \
      --image gcr.io/my-project/my-server:latest \
      --requirements requirements.txt
  • After the service is deployed, you can test it by sending a request to the service’s URL. The URL can be found in the output of the gcloud run deploy command, or by using the gcloud run services describe command. For example, if the service’s URL is https://my-service-abcdefg-uc.a.run.app, you can test the service by sending a request to that URL, using the appropriate method for the service (e.g.Β GET for a HTTP GET request).

πŸŽ‰In this task, you learned how to integrate your Cloud Run service with databases and APIs. This can be useful for building applications that need to store and retrieve data, or communicate with other services. You learned how to enable and grant access to an API, how to add the necessary dependencies and configuration to your service, and how to use the API in your server code.

πŸ™‹Want to learn more?