# 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. Install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). Git is required to copy samples to your machine.
2. Install [Docker](https://docs.docker.com/get-docker/). Docker is required to build the sample code. Ensure your local user account is able to build containers.
3. Install the [Cloud Code plugin](https://docs.cloud.google.com/code/docs/vscode/install#installing) if you haven't already.

<br />

### 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:

- [Cloud Run Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/run#run.admin) (`roles/run.admin`)
- [Cloud Run Builder](https://docs.cloud.google.com/iam/docs/roles-permissions/run#run.builder) (`roles/run.builder`)
- [Logs Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/logging#logging.viewer) (`roles/logging.viewer`)
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## 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](https://docs.cloud.google.com/static/code/docs/vscode/images/cloudcode-status-bar.png)
2. In the Quick Pick menu that appears, select **New Application**.

3. Select **Cloud Run application** as the application type.

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

   For example, choosing **Node.js: Cloud Run** creates 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 Run** command.

2. In the **Deploy to Cloud Run** pane, 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 Run** dialog.

## View resource status

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

1. Click ![](https://docs.cloud.google.com/static/code/images/cloud-code-icon.svg) **Cloud Code** in the VS Code Activity bar.
2. Expand the **Cloud Run** section 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 ![](https://docs.cloud.google.com/static/code/images/cloud-code-icon.svg) **Cloud Code** in the VS Code Activity bar.
2. Expand the **Cloud Run** section 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](https://console.cloud.google.com/project)
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](https://cloud.google.com/artifact-registry/pricing).
  For steps to delete your image, see
  [Deleting images](https://docs.cloud.google.com/artifact-registry/docs/docker/manage-images#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

- Discover the language-specific [debugging support](https://docs.cloud.google.com/code/docs/vscode/debug) that Cloud Code provides.
- Customize your Cloud Code experience by configuring [relevant settings](https://docs.cloud.google.com/code/docs/vscode/configuring-settings).
- Try creating and [running a Kubernetes application with Cloud Code](https://docs.cloud.google.com/code/docs/vscode/quickstart-local-dev).