Cloud Code allows you to quickly apply changes to your application during a development or debug session for a faster feedback loop. This lets you run your Kubernetes and emulated Cloud Run sessions in watch mode.
Settings for Kubernetes and Cloud Run configurations
You can configure watch mode in the Cloud Code Kubernetes and Cloud Run configurations at Run > Edit configurations on the Run tab:
Watch mode | Description |
---|---|
On demand |
|
On file save |
|
Customizing the Trigger Build and Deploy keymap
The default key bindings for Trigger Build and Deploy are:
- Mac OS:
Option+Cmd+Comma
- Windows:
Ctrl+Alt+Comma
To change the default key bindings:
- Navigate to Preferences > Keymap.
- In the Keymap search bar, enter "trigger build and deploy".
- Right-click the Trigger Build and Deploy search result and select Add Keyboard Shortcut.
- Enter shortcut combination you prefer (for example,
Shift+R
) and click OK, then click OK in the Preferences window. This adds your new key binding to the Trigger Build and Deploy function, so that both the default and your new key binding will work. - You can also remove the default key binding by right-clicking the Trigger Build and Deploy search result and selecting the Remove option.
Applying changes while debugging
With Cloud Code, you can debug an application while making changes to, and iterating on, source code. This is available for Kubernetes development and Cloud Run local development.
To apply changes to your code while debugging, perform the following:
- Ensure On-demand mode is enabled in Run > Edit Configurations (the default option).
- Launch the run configuration in debug mode by clicking Debug.
Common use case
This section outlines a common scenario of how you can debug with watch mode enabled in your IDE.
Debugging a Kubernetes application with watch mode enabled
You're a developer building an application that runs on Kubernetes, and use Cloud Code to iterate on your app. You discovered a bug in your code.
- You launch the Develop on Kubernetes run configuration, and:
- Select On demand to rebuild and redeploy the app.
- Launch the run configuration in debug mode by clicking Debug.
- You set a breakpoint near the expected bug, launch the app, and use the debugger to figure out what the bug is.
- You fix the bug while the development session is still running (the debugger is still attached). You now want to confirm that the issue is fixed.
- You trigger On-demand mode which tells Cloud Code and Skaffold to rebuild and redeploy the application, by clicking Trigger Build and Deploy or pressing
Option+Cmd+Comma
on Mac OS orCtrl+Alt+Comma
on Windows (the default key bindings). - A notification appears and asks you to confirm: "Redeploying your changes will cause the debugger to be stopped and reattached, potentially losing your current debug state". You have the option to either cancel, continue, or to never be notified again.
- After clicking continue:
- The debugger is terminated
- The application is rebuilt and redeployed
- The debugger is reattached
- You can now verify the changes and debug again as needed.