Deploying a Cloud Run service with Cloud Code

This page shows you how to get started quickly with Cloud Code.

You'll set up a Hello World application that runs on Cloud Run using a starter template, deploy your app to Cloud Run, and view the status of your live service's resources.

Interactive tutorial

If you'd prefer to work through this quickstart interactively, launch the Cloud Shell walkthrough with the button below.

Launch interactive tutorial.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

Creating an application

  1. Directly launch the Cloud Shell Editor.
  2. From the Cloud Code status bar, select New Application. Clicking on the Cloud Code status bar and choosing New Application
  3. Choose 'Cloud Run application' as your preferred application type.
  4. From the list of templates (Node.js, Python (Flask and Django frameworks), Java, Go), choose a Hello World app in a language of your choosing.

    For example, choosing Python (Flask): Hello World will create a starter Python (Flask) Hello World app.

  5. Select a folder as your application location to proceed and click 'Create New Application'.

    Cloud Shell Editor loads the application in a new workspace. Once reloaded, your app is accessible in the explorer view.

Deploy to Cloud Run

To deploy your application to Cloud Run, follow these steps:

  1. Choose the Cloud Run: Deploy command using the Cloud Code status bar.

    This brings up the Cloud Run: Deploy UI. Cloud Run: Run/Debug Locally UI with pre-existing service selected

  2. If prompted, authorize Cloud Shell to make Google Cloud API calls.

  3. Set your Google Cloud project.

  4. If prompted, enable your Cloud Run API by clicking 'Enable APIs'.

  5. Within the Deploy to Cloud Run dialog, select a pre-existing service or create a new one.

  6. If you're creating a new service, choose 'Cloud Run (fully managed)' under 'Deployment Platform'.

  7. Choose a region to deploy to.

  8. For Authentication, select 'Allow unauthenticated invocations' to make this a public service.

  9. After you define your preferred settings, you can click 'Deploy'.

    Cloud Code then builds your image, pushes it to the registry, and deploys your app to Cloud Run. Your service is now live!

  10. View your running service by following the URL displayed in your Cloud Run: Deploy dialog.

    Cloud Run: Run/Debug Locally UI with pre-existing service selected

Editing your service

To edit your application, follow these steps:

  1. With the Explorer view, find the app.py file which implements the service behavior.
  2. Modify the message "It's running!" to a message of your choosing.
  3. Once you make this change, choose the Cloud Run: Deploy command using the Cloud Code status bar.
  4. Check that the service you just created is selected in Service Settings.
  5. Click 'Deploy'.
  6. Once your application finishes building and deploying, you can refresh your service to see your updated message.

Viewing logs

You can also view logs from your deployed application with the Log Viewer that comes with Cloud Code.

To view logs, follow these steps:

  1. Navigate to the Cloud Run explorer by clicking on its icon in the VS Code Activity bar on the left Cloud Run explorer icon.
  2. Right-click on your Cloud Run service and choose 'View logs'.

    Viewing logs for a non-Cloud Logging cluster by setting the deployment field within the Log Viewer search box to 'node-guestbook'

  3. Refresh your app in the browser, and see the new logs generated by clicking the Logs refresh button.

Cleaning up

To delete your project:

  • Go to the Projects page in the Cloud Console:

    Go to the Projects page

  • Select the project you created for this Quickstart and click on the trash can icon next to delete it.

    This shuts down the project and schedules it for deletion.

If you're using a pre-existing project and would like to delete resources you created for this quickstart:

  • Container image: While Cloud Run does not charge when the service is not in use, you might still be charged for storing the container image in Container Registry. To delete your image, follow this guide.

  • Cloud Run service: To delete a Cloud Run service, navigate to Cloud Run in the Console using the navigation menu. Select the service you'd like to delete and click on the 'Delete' trash can icon.

What's next