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:
- Navigate to Run/Debug configurations selector in the Navigation bar and click Edit Configurations.
- In the left pane, click Cloud Run: Deploy.
- Set your Google Cloud project ID.
Choose your platform preferences under Deployment Platform, either Cloud Run or Cloud Run for Anthos. For a detailed description of each option, see the Cloud Run platform guide.
- If Cloud Run is selected, choose a region to deploy to.
If Cloud Run for Anthos is selected, configure the Kubernetes cluster information.
If your service is a public API or website, choose Allow unauthenticated invocations in the Authentication section. Otherwise, select Require authentication.
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
Cloud Run for Anthos, you can store your images on either:
- Artifact Registry, using the format
- REGION is the repository's supported region
- PROJECT_ID is the ID of your Google Cloud project containing your cluster
- REPO_NAME is the name of your repository where your image is stored
- IMAGE_PATH is the path to your image
- Artifact Registry, using the format REGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/IMAGE_PATH
- Container Registry, using the format
- PROJECT_ID is the ID of your Google Cloud project
- IMAGE_NAME refers to the container image repository
If you're using Cloud Run for Anthos, you can store your images on Docker Hub using the format, docker.io/ACCOUNT, where ACCOUNT is the name of your Docker Hub account. Make sure that you're properly authenticated if you're using a private Docker Hub repository.
- For both Cloud Run and Cloud Run for Anthos, you can store your images on either:
Under Build settings, choose whether to build locally or on Cloud Build.
If you're using an Apple machine that uses M-Series silicon, you must use Cloud Build to deploy to Cloud Run which only supports x86 images (this can incur charges). Cloud Code helps you build x86 images using Cloud Build. For more information, see Cloud Code support for Apple M series silicon.
Choose a builder and plugin.
Cloud Code supports Docker, Jib, and Buildpacks artifact types.
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.
The following environment variables are automatically added to the running containers:
|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:
- Choose your run target from the Run/Debug configurations dialog on the top taskbar.
- Click Run.
- View your running service by following the URL displayed in the output window.
You can also view the status of your service (metrics, revision details, and more) by following the logs URL displayed in the output window.