With Cloud Code, you can develop your Cloud Run applications locally in a Cloud Run-like environment. Cloud Code will watch for changes in your source and quickly update the running application to reflect these changes.
Defining your run configuration
Before you run your application, you must create your run configuration:
- Navigate to Run/Debug configurations dialog on the top taskbar and click 'Edit Configurations'.
- Choose 'Cloud Run: Run Locally' under Cloud Code: Cloud Run.
Specify your builder option and its relevant settings.
Cloud Code supports Docker, Jib, and Buildpacks artifact types.
Optional: Customizing your configuration
When developing locally, you can specify additional settings like a service account, environment variables, and SQL connections (when using Cloud Run (fully managed)), using 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|
If your code includes potentially sensitive data like API keys, passwords, and certificates, it is recommended you store them as secrets. With Cloud Code, you can securely store these secrets in Secret Manager and programmatically fetch them when you need them. For a detailed look at how you can create and manage secrets with Cloud Code, refer to the Secret Manager guide.
Running your application
To run your application, follow these steps:
- Choose the Cloud Run: Run Locally run target from the Run/Debug configurations dialog on the top taskbar.
- Click 'Cloud Run: Run Locally' .
- View the logs from your running app, streamed directly to the output window.
Once deployment is complete, you can view your running app by following the URL displayed in your Event Log panel. In the example below, this URL is http://localhost:8080.