Deploy a Cloud Run service with Cloud Code for VS Code

This document shows you how to get started with Cloud Code.

You'll create a service from a sample "Hello, world" application, deploy your service publicly with Cloud Code, and view the status of your live service's resources.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project : To create a project, you need the Project Creator role ( roles/resourcemanager.projectCreator ), which contains the resourcemanager.projects.create permission. Learn how to grant roles .

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide . If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project .

  5. Enable the Cloud Run API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin ), which contains the serviceusage.services.enable permission. Learn how to grant roles .

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project : To create a project, you need the Project Creator role ( roles/resourcemanager.projectCreator ), which contains the resourcemanager.projects.create permission. Learn how to grant roles .

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide . If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project .

  9. Enable the Cloud Run API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin ), which contains the serviceusage.services.enable permission. Learn how to grant roles .

    Enable the API

  10. Install Git . Git is required to copy samples to your machine.
  11. Install Docker . Docker is required to build the sample code. Ensure your local user account is able to build containers.
  12. Install the Cloud Code plugin if you haven't already.

Required roles

To get the permissions that you need to complete this quickstart, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, see Manage access to projects, folders, and organizations .

You might also be able to get the required permissions through custom roles or other predefined roles .

Create a service

To create a sample service application, follow these steps:

  1. In the Cloud Code status bar, click the active project name.

    Active project name in status bar

  2. In the Quick Pick menu that appears, select New Application.

  3. Select Cloud Run applicationas the application type.

  4. From the list of sample applications, select one for your preferred language.

    For example, choosing Node.js: Cloud Runcreates a "Hello, world" service application in Node.js.

  5. Confirm the file system location of your service's source code (or modify it, if necessary) and click Create New Application.

    A preview of the README.md file for your selected service opens in VS Code.

Deploy to Cloud Run

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

  1. Open the Command Palette (press Ctrl / Cmd + Shift + P or click View> Command Palette) and then run the Deploy to Cloud Runcommand.

  2. In the Deploy to Cloud Runpane, set your Google Cloud project.

  3. Accept the remaining default settings and then click Deploy.

    Cloud Code builds your image, pushes it to the registry, and deploys your service to Cloud Run.

  4. To view your running service, open the URL displayed at the top of the Deploy to Cloud Rundialog.

View resource status

You can view the status of your Cloud Run services using the Cloud Run service browser:

  1. Click Cloud Codein the VS Code Activity bar.
  2. Expand the Cloud Runsection to view your Cloud Run service.
  3. Click the service to view its properties.

View logs

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

To view logs, follow these steps:

  1. Click Cloud Codein the VS Code Activity bar.
  2. Expand the Cloud Runsection to view your Cloud Run service.
  3. Right-click your Cloud Run service and then click View logs.

Clean up

To delete your project:

  1. Go to the Projects page in the Google Cloud console:

    Go to the Projects page

  2. Select the project you created for this quickstart and then click Delete.

  3. Type the project ID to confirm and then click Shut down.

    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 doesn't charge when the service isn't in use, you might be charged for storing the container image in Artifact Registry . For steps to delete your image, see Deleting images .

  • Cloud Run service:To delete a Cloud Run service, navigate to Cloud Run in the Google Cloud console using the navigation menu. Select the service you want to delete and then click Delete.

What's next

Design a Mobile Site
View Site in Mobile | Classic
Share by: