Cloud Code lets you easily debug an application deployed to
Cloud Run. You don't need to complete manual setup like setting up
port forwarding or injecting language-specific debug arguments. You simply need
a Cloud Code-ready Cloud Run application that
includes a skaffold.yaml configuration file and a launch.json file of type
Debugging your Cloud Run service
To debug your service, follow these steps:
To run your service and attach a debugger session to it, select Debug on Cloud Run Emulator using the Command Palette (accessible with Ctrl/Cmd+Shift+P).
In the Run/Debug on Cloud Run Emulator dialog, set the specifications for your configuration:
- Choose Docker or Buildpacks as your builder and then specify your Dockerfile or Buildpack.
- If you want to specify a Dockerfile target or build arguments, click Show Advanced Build Settings and then specify the target or arguments.
- If you want to specify a custom service name, container image URL, container port, identity for the service to use, number of dedicated CPUs, or amount of memory to allocate to each container instance, click Show Advanced Service Settings and then specify the values.
- If you want to specify any environment variables, click Show Advanced Service Settings, click Environment Variables, and then specify the values.
- If you want to specify Cloud SQL connections, click Connections and then specify one connection per line.
If you want to further customize how your service is run, you can edit your launch.json file directly.
To begin debugging your service, click Debug.
For each debuggable container in your service, confirm or enter the directory in the remote container where the program you'd like to debug is found.
Alternatively, you can press ESC to skip debugging the container.
Cloud Code attaches a debug session for each debuggable container in the service.
To add a breakpoint, click in the editor margin of the file you're debugging.
Red filled circles signify active breakpoints and gray hollow circles signify disabled breakpoints.
When you send a new request to your service, it pauses at the line you specified.
After your session completes, additional contextual menu options are available to monitor your application and its resources using the Cloud Code status bar, including:
- Open Deployment Logs: Open the application logs of a specific deployment with the Cloud Code Logs Viewer
- Open Service URL: Open the application service URL of a specific service in a web browser
Turn on/off watch mode: Toggle watch mode for the current session. By default, Cloud Code continuously watches the file system for changes to your files, such as Kubernetes config or code, rebuilds the container(s), and redeploys the application to the cluster so that your edits are reflected in near real time.
To stop your deployment, click the Stop button in the action bar for your current deployment.