# Deploy a service to Cloud Run in Cloud Code for IntelliJ

Now that you're all set up, you can deploy your service to
Cloud Run and view your service live.

## Defining your run configuration

Before you deploy your service, you must create your run configuration:

1. Navigate to Run/Debug configurations selector in the Navigation bar and click **Edit Configurations**.
2. In the left pane, click **Cloud Run: Deploy**.
3. Set your Google Cloud project ID.
4. Choose your platform preferences under **Deployment Platform** ,
   either **Cloud Run** or **Knative serving** . For
   a detailed description of each option, see the
   [Cloud Run platform guide](https://docs.cloud.google.com/run/docs/choosing-a-platform).

   - If **Cloud Run** is selected, choose a region to deploy to.
   - If **Knative serving** is selected, configure the Kubernetes
     cluster information.

5. If your service is a public API or website, choose **Allow unauthenticated
   invocations** in the Authentication section. Otherwise, select
   **Require authentication**.

6. Under Revision Settings, Cloud Code automatically populates the
   container image URL field with the storage location of your container
   image (where it stores your service, once it builds and containerizes it).
   This value is based on your Google Cloud project and service name.

   If you need to, you can override this value:
   - For both Cloud Run and Knative serving, you can store your images on either:
     - [Artifact Registry](https://docs.cloud.google.com/artifact-registry/docs), using the format **<var class="readonly" translate="no">REGION</var>-docker.pkg.dev/<var class="readonly" translate="no">PROJECT_ID</var>/<var class="readonly" translate="no">REPO_NAME</var>/<var class="readonly" translate="no">IMAGE_PATH</var>**
       - <var class="readonly" translate="no">REGION</var> is the repository's supported region
       - <var class="readonly" translate="no">PROJECT_ID</var> is the ID of your Google Cloud project containing your cluster
       - <var class="readonly" translate="no">REPO_NAME</var> is the name of your repository where your image is stored
       - <var class="readonly" translate="no">IMAGE_PATH</var> is the path to your image

   > [!NOTE]
   > **Note:** Consider [transitioning from Container Registry](https://docs.cloud.google.com/artifact-registry/docs/transition/transition-from-gcr) since Artifact Registry is the recommended service for managing container images. [Container Registry](https://docs.cloud.google.com/container-registry/docs) is still supported but will only receive critical security fixes.

   - Container Registry, using the format **gcr.io/<var class="readonly" translate="no">PROJECT_ID</var>/<var class="readonly" translate="no">IMAGE_NAME</var>**
     - <var class="readonly" translate="no">PROJECT_ID</var> is the ID of your Google Cloud project
     - <var class="readonly" translate="no">IMAGE_NAME</var> refers to the container image repository
   - If you're using Knative serving, you can store
     your images on Docker Hub using the format,
     **docker.io/<var class="readonly" translate="no">ACCOUNT</var>** , where <var class="readonly" translate="no">ACCOUNT</var> is the name of your Docker Hub
     account. Make sure that you're
     [properly authenticated](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry)
     if you're using a private Docker Hub repository.

7. Under Build settings, choose whether to build locally or on
   Cloud Build.

8. Choose a builder and plugin.

   Cloud Code supports Docker, Jib, and Buildpacks
   [artifact types](https://skaffold.dev/docs/builders/).
9. Click **OK**.

### Optional: Customizing your configuration

When deploying your service, you can specify additional settings such as
a service account, environment variables, and, when using
Cloud Run, a VPC Connector and SQL connections. Specify
the additional settings in the **Advanced revision settings** section when you
choose **Edit Configurations**.

**Environment variables:**

The following environment variables are automatically added to the running
containers:

| Name | Description | Example |
|---|---|---|
| PORT | The port your HTTP server should listen on. | 8080 |
| K_SERVICE | The name of the Cloud Run service being run. | hello-world |
| K_REVISION | The name of the Cloud Run revision being run. | hello-world.1 |
| K_CONFIGURATION | The name of the Cloud Run configuration that created the revision. | hello-world |

## Deploying your service

To deploy your service, follow these steps:

1. Choose your run target from the Run/Debug configurations dialog on the top taskbar.
2. Click **Run**.
3. View your running service by following the URL displayed in the **output window**.
4. You can also view the status of your service (metrics, revision details,
   and more) by following the logs URL displayed in the output window.

## Get support

To submit feedback or report an issue in your IntelliJ IDE, go to **Tools** \> **Cloud Code** \> **Help / About** \> **Submit
feedback or report an issue** to report an issue on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-intellij/issues).