Men-debug layanan Cloud Run di Cloud Code untuk Cloud Shell
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Cloud Code for Cloud Shell memungkinkan Anda men-debug aplikasi yang di-deploy ke Cloud Run dengan mudah dengan memanfaatkan skaffold debug. Untuk mengetahui informasi
mendetail tentang proses debug Skaffold, lihat
Melakukan proses debug dengan Skaffold.
Anda tidak perlu menyelesaikan penyiapan manual seperti menyiapkan penerusan port atau
memasukkan argumen debug khusus bahasa. Proses debug memerlukan
aplikasi Cloud Run yang siap digunakan Cloud Code
yang menyertakan file konfigurasi skaffold.yaml dan file launch.json
berjenis cloudcode.cloudrun.
Men-debug layanan Cloud Run
Untuk men-debug layanan, ikuti langkah-langkah berikut:
Untuk menjalankan layanan dan melampirkan sesi debugger ke layanan tersebut, buka
palette perintah (tekan Ctrl/Cmd+Shift+P atau klik View >
Command Palette),
lalu jalankan perintah Debug on Cloud Run Emulator.
Pada dialog Run/Debug on Cloud Run Emulator, tetapkan spesifikasi untuk konfigurasi Anda:
Pilih Docker atau Buildpack sebagai builder, lalu tentukan Dockerfile atau Buildpack Anda.
(Opsional) Untuk menentukan target Dockerfile atau argumen build,
klik Tampilkan Setelan Build Lanjutan, lalu tentukan target atau
argumen.
(Opsional) Untuk menentukan nama layanan kustom, URL image container,
port container, identitas yang akan digunakan layanan, jumlah CPU khusus,
atau jumlah memori yang akan dialokasikan ke setiap instance container, klik
Tampilkan Setelan Layanan Lanjutan, lalu tentukan nilainya.
(Opsional) Untuk menentukan
variabel lingkungan,
klik Tampilkan Setelan Layanan Lanjutan, klik Variabel Lingkungan,
lalu tentukan nilainya.
(Opsional) Untuk menentukan koneksi Cloud SQL, klik Koneksi, lalu tentukan satu koneksi per baris.
Jika ingin menyesuaikan lebih lanjut cara layanan dijalankan, Anda dapat mengedit
file launch.json
secara langsung.
Untuk mulai men-debug layanan, klik Debug.
Untuk setiap penampung yang dapat di-debug di layanan Anda, konfirmasi atau masukkan direktori
di penampung jarak jauh tempat program yang ingin Anda debug ditemukan.
Atau, Anda dapat menekan ESC untuk melewati proses proses debug penampung.
Cloud Code melampirkan sesi debug untuk setiap penampung yang dapat di-debug dalam layanan.
Secara default, saat perubahan pada aplikasi Anda disimpan secara otomatis, Cloud Code akan men-deploy ulang aplikasi Anda dan menyiapkan sesi debug baru. Anda dapat mengaktifkan/menonaktifkan fitur ini dengan flag watch di konfigurasi
peluncuran project.
Untuk menambahkan titik henti sementara, klik di margin editor file yang Anda debug.
Lingkaran isi merah menandakan titik henti sementara aktif dan lingkaran kosong abu-abu
menandakan titik henti sementara yang dinonaktifkan.
Saat Anda mengirim permintaan baru ke layanan, permintaan akan dijeda di baris yang Anda
tentukan.
Setelah sesi selesai, klik kanan untuk menggunakan perintah berikut:
Lihat Log: Membuka log aplikasi deployment tertentu dengan Cloud Code Logs Explorer
Buka URL: Membuka URL layanan aplikasi dari layanan
tertentu di browser web
Jika Anda telah menonaktifkan mode lihat di konfigurasi peluncuran dan ingin membuat perubahan pada aplikasi, serta mem-build ulang dan men-deploy ulang aplikasi, klik status bar Cloud Code, lalu klik Aktifkan mode lihat.
Jika Anda ingin memeriksa variabel dan info stack, gunakan
Sidebar Debug.
Untuk berinteraksi dengan sesi proses debug, gunakan
Debug Console
di debugger panel bawah.
Untuk menghentikan deployment, klik tombol Stop di panel tindakan untuk deployment saat ini.
Memecahkan masalah pembuatan penampung
Jika Anda mendapatkan kode error BUILD_DOCKER_UNKNOWN, ini menunjukkan
masalah pada Docker. Untuk mengatasi masalah ini, lakukan satu atau beberapa tugas
berikut:
Mulai ulang Docker dan coba build container lagi.
Jika Anda masih mendapatkan error yang sama setelah memulai ulang, Docker mungkin
kehabisan ruang disk. Untuk mempelajari lebih lanjut cara membersihkan objek yang tidak digunakan di Docker, lihat Memangkas objek Docker yang tidak digunakan.
Coba ekstensi Penggunaan Disk Docker untuk membantu mengklaim kembali ruang.
Detail konfigurasi
Cloud Code menangani detail konfigurasi khusus bahasa berikut:
Node.js
Menulis ulang titik entri untuk memanggil:
node --inspect=localhost:9229
Python
Menginstal modul ptvsd menggunakan Penampung Init dan menulis ulang
titik entri untuk memanggil:
python -m ptvsd --host localhost --port 5678
Go
Menginstal
debugger dlv
menggunakan Penampung Init dan menulis ulang titik entri sehingga sesi debug
yang diluncurkan hanya berjalan dengan server debug (dalam mode headless), melanjutkan
proses yang di-debug saat memulai, menerima beberapa koneksi klien, dan memproses di
localhost:56268:
Menambahkan lingkungan JAVA_TOOLS_OPTIONS dengan konfigurasi Java Debug Wire Protocol (JDWP) yang sesuai sehingga agen proses debug JDWP memproses koneksi soket di port 5005 dan memungkinkan VM mulai dieksekusi sebelum debugger dilampirkan:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-01 UTC."],[[["\u003cp\u003eCloud Code for Cloud Shell simplifies debugging Cloud Run applications by utilizing \u003ccode\u003eskaffold debug\u003c/code\u003e, eliminating the need for manual port forwarding or language-specific debug argument setups.\u003c/p\u003e\n"],["\u003cp\u003eDebugging a Cloud Run service involves using the "Debug on Cloud Run Emulator" command, configuring build and service settings, and then initiating the debug process.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code automatically redeploys the application and establishes a new debug session whenever changes are autosaved, which can be toggled via the 'watch' flag.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code manages language-specific debugging configurations, such as entry point rewrites and debugger installations, for Node.js, Python, Go, Java, and .NET Core applications.\u003c/p\u003e\n"],["\u003cp\u003eIf you get the 'BUILD_DOCKER_UNKNOWN' error, it is an issue with Docker that can be solved by restarting docker, pruning unused objects, or by using the disk usage extension.\u003c/p\u003e\n"]]],[],null,["# Debug a Cloud Run service in Cloud Code for Cloud Shell\n\nCloud Code for Cloud Shell lets you easily debug an application deployed to\nCloud Run by leveraging\n[`skaffold debug`](https://skaffold.dev/docs/workflows/debug). For detailed\ninformation about Skaffold debugging, see\n[Debugging with Skaffold](https://skaffold.dev/docs/workflows/debug/).\n\nYou don't need to complete manual setup like setting up port forwarding or\ninjecting language-specific debug arguments. Debugging requires a\nCloud Code-ready Cloud Run application\nthat includes a `skaffold.yaml` configuration file and a `launch.json` file of\ntype `cloudcode.cloudrun`.\n\nDebug your Cloud Run service\n----------------------------\n\nTo debug your service, follow these steps:\n\n1. To run your service and attach a debugger session to it, open the\n command palette (press `Ctrl`/`Cmd`+`Shift`+`P` or click **View** \\\u003e\n **Command Palette** )\n and then run the **Debug on Cloud Run Emulator** command.\n\n2. In the Run/Debug on Cloud Run Emulator dialog, set the\n specifications for your configuration:\n\n - Choose Docker or Buildpacks as your builder and then specify your Dockerfile or Buildpack.\n - (Optional) To specify a Dockerfile target or build arguments, click **Show Advanced Build Settings** and then specify the target or arguments.\n - (Optional) 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.\n - (Optional) To specify any [environment variables](/code/docs/shell/develop-service#optional_customizing_your_configuration), click **Show Advanced Service Settings** , click **Environment Variables**, and then specify the values.\n - (Optional) To specify Cloud SQL connections, click **Connections** and then specify one connection per line.\n\n If you want to further customize how your service is run, you can edit\n [your `launch.json` file](/code/docs/shell/develop-service#customizing_an_existing_launchjson_configuration)\n directly.\n3. To begin debugging your service, click **Debug**.\n\n4. For each debuggable container in your service, confirm or enter the directory\n in the remote container where the program you'd like to debug is found.\n\n Alternatively, you can press `ESC` to skip debugging a container.\n\n Cloud Code attaches a debug session for each debuggable\n container in the service.\n\n\n By default, when a change to your application is autosaved,\n Cloud Code redeploys your application and sets up a new debug\n session. You can toggle this feature with the `watch` flag in your project's\n launch configuration.\n5. To add a breakpoint, click in the editor margin of the file you're debugging.\n\n Red filled circles signify active breakpoints and gray hollow circles\n signify disabled breakpoints.\n\n When you send a new request to your service, it pauses at the line you\n specified.\n6. After your session completes, right-click to use the following commands:\n\n - **View Logs:** Open the application logs of a specific deployment with the Cloud Code Logs Explorer\n - **Open URL:** Open the application service URL of a specific service in a web browser\n7. If you've turned off watch mode in your launch configuration and you want to\n make changes to your application and rebuild and redeploy the application,\n click the Cloud Code status bar and then click\n **Turn on watch mode**.\n\n8. If you want to inspect variables and stack info, use the\n [Debug Sidebar](https://code.visualstudio.com/Docs/editor/debugging).\n To interact with the debugging session, use the\n [Debug Console](https://code.visualstudio.com/Docs/editor/debugging#_debug-console-repl)\n in the bottom pane debugger.\n\n9. To stop your deployment, click the **Stop** button in the action bar for your\n current deployment.\n\n### Troubleshoot container-building issues\n\nIf you're getting the `BUILD_DOCKER_UNKNOWN` error code, this indicates a\nproblem with Docker. To resolve this issue, perform one or more of the following\ntasks:\n\n- Restart Docker and try building the container again.\n\n- If you're still getting the same error after restarting, Docker could be\n running out of disk space. To learn more about cleaning up unused objects in\n Docker, see [Prune unused Docker objects](https://docs.docker.com/config/pruning/#prune-unused-docker-objects).\n\n- Try Docker's [Disk Usage](https://hub.docker.com/extensions/docker/disk-usage-extension)\n extension to help reclaim space.\n\nConfiguration details\n---------------------\n\nCloud Code handles the following language-specific configuration\ndetails: \n\n### Node.js\n\nRewriting the entrypoint to invoke:\n\n`node --inspect=localhost:9229`\n\n### Python\n\nInstalling the `ptvsd` module using an Init Container and rewriting the\nentrypoint to invoke:\n\n`python -m ptvsd --host localhost --port 5678`\n\n### Go\n\nInstalling the\n[`dlv` debugger](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv.md)\nusing an Init Container and rewriting the entrypoint such that the launched\ndebug session runs with a debug server only (in headless mode), continues the\ndebugged process on start, accepts multiple client connections, and listens at\n`localhost:56268`:\n\n`dlv exec --headless --continue --accept-multiclient --listen=localhost:56268 --api-version=2, \u003capp\u003e --`\n\n### Java\n\nAdding an environment `JAVA_TOOLS_OPTIONS` with the appropriate Java Debug\nWire Protocol (JDWP) configuration such that the JDWP debugging agent listens\nfor a socket connection on port 5005 and allows the VM to begin executing\nbefore the debugger is attached:\n\n`jdwp=transport=dt_socket,server=y,suspend=n,address=5005,quiet=y`\n\n### .NET\n\n.NET Core applications are configured to be deployed along with `vsdbg` for VS\nCode.\n\nIf you encounter problems with the automatic configuration, see\n[Detailed debugger configuration and setup](https://skaffold.dev/docs/workflows/debug/#detailed-debugger-configuration-and-setup)\nfor help troubleshooting."]]