Jika Anda tidak memiliki file .vscode/launch.json yang ditentukan, dialog
Run/Debug on Cloud Run Emulator memungkinkan Anda mengonfigurasi peluncuran, lalu
menyimpan setelan ke .vscode/launch.json. Jika telah mengonfigurasi
file .vscode/launch.json, Anda dapat mengedit file tersebut secara langsung.
Untuk menjalankan layanan secara lokal, tentukan konfigurasi Anda:
Buka palet perintah (tekan Ctrl/Cmd+Shift+P atau klik View >
Command Palette), lalu jalankan perintah Run on Cloud Run Emulator.
Pada dialog Run/Debug on Cloud Run Emulator, tetapkan spesifikasi untuk konfigurasi Anda:
Hanya alat build yang diinstal secara lokal yang tersedia untuk Emulator Cloud Run
Pilih Docker atau Buildpacks sebagai builder, lalu tentukan
sumber
(Opsional) Untuk menentukan variabel lingkungan yang akan diteruskan ke penampung
yang sedang berjalan, luaskan Advanced Build Settings, lalu klik untuk menentukan
pasangan nilai kunci.
Nama
Deskripsi
Contoh
PORT
Port yang akan diproses oleh server HTTP.
8080
K_SERVICE
Nama layanan Cloud Run yang sedang dijalankan.
hello-world
K_REVISION
Nama revisi Cloud Run yang sedang dijalankan.
hello-world.1
K_CONFIGURATION
Nama konfigurasi Cloud Run yang membuat revisi.
hello-world
(Opsional) Untuk menentukan koneksi Cloud SQL, luaskan
Advanced Service Settings, klik Connections, lalu tentukan satu
koneksi Cloud SQL per baris.
(Opsional) Centang opsi
Buat layanan dapat diakses dari perangkat lain di jaringan lokal.
(Opsional) Jika Anda hanya ingin mem-build ulang dan menjalankan layanan secara manual,
bukan otomatis saat Anda membuat perubahan, hapus
opsi Mem-build ulang dan menjalankan ulang secara otomatis saat ada perubahan.
Menjalankan layanan secara lokal
Setelah menentukan setelan yang diinginkan, jalankan layanan dengan mengklik
Run.
Setelah deployment selesai, Anda dapat melihat layanan yang sedang berjalan dengan membuka
URL yang ditampilkan di jendela output.
Untuk melihat log panjang, beralihlah ke tampilan Cloud Run mendetail di jendela output.
Setelah sesi selesai, klik kanan untuk menggunakan perintah berikut:
Lihat Log: Membuka log aplikasi dari deployment tertentu dengan
Logs Explorer Cloud Code.
Buka URL: Buka 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.
Untuk menghentikan deployment, Anda dapat mengklik tombol Stop di panel tindakan untuk deployment saat ini.
Menyimpan rahasia
Jika kode Anda menyertakan data yang berpotensi sensitif seperti kunci API, sandi, dan sertifikat, menyimpannya sebagai secret dapat membantu mengamankannya. Integrasi Cloud Code Secret Manager memungkinkan Anda menyimpan secret ini dengan aman dan mengambilnya secara terprogram. Untuk melihat cara mendetail tentang
cara membuat dan mengelola secret dengan Cloud Code, lihat
panduan Secret Manager.
Menyesuaikan konfigurasi launch.json yang ada
Plugin Cloud Code akan otomatis memperbarui file konfigurasi launch.json saat Anda memilih tindakan run. Untuk menyesuaikan lebih lanjut cara layanan Anda dijalankan, Anda dapat menentukan kolom berikut dalam file .vscode/launch.json:
watch: Memantau perubahan di ruang kerja dan menjalankan ulang
layanan. Benar secara default.
Contoh berikut menunjukkan smartwatch yang disetel ke true:
"watch":true,
build: Tentukan builder
(Docker,
jibMaven, jibGradle, atau
buildpack)
untuk mem-build image Anda.
[[["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-08-11 UTC."],[[["\u003cp\u003eYou can develop services locally using a Cloud Run emulator before deploying them to Cloud Run, with configuration settings being stored in a \u003ccode\u003e.vscode/launch.json\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eThe Run/Debug on Cloud Run Emulator dialog or the command palette can be used to configure your service, allowing you to choose between Docker or Buildpacks, specify environment variables, and set Cloud SQL connections.\u003c/p\u003e\n"],["\u003cp\u003eOnce configured, you can run your service locally, monitor its deployment status in the output window, and view logs or access the service URL.\u003c/p\u003e\n"],["\u003cp\u003eSecrets like API keys can be securely managed using the Cloud Code Secret Manager integration, with details available in the Secret Manager guide.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize your service's launch settings further by editing the \u003ccode\u003e.vscode/launch.json\u003c/code\u003e file, which allows for configuring options such as watching for changes, specifying the builder, setting the image and service, and defining debug settings.\u003c/p\u003e\n"]]],[],null,["# Develop a Cloud Run service locally in Cloud Code for VS Code\n\nBefore you\n[deploy a service to Cloud Run](/code/docs/vscode/deploy-service),\nyou can develop it locally using a Cloud Run emulator.\n\nConfiguring your service for development\n----------------------------------------\n\nIf you don't have a `.vscode/launch.json` file defined, the\n**Run/Debug on Cloud Run Emulator** dialog lets you configure your launch and\nthen saves your settings to `.vscode/launch.json`. If you have a\n`.vscode/launch.json` file configured, you can edit the file directly.\n\nTo run your service locally, specify your configuration:\n\n1. Open the command palette (press `Ctrl`/`Cmd`+`Shift`+`P` or click **View** \\\u003e **Command Palette** ) and then run the **Run on Cloud Run Emulator** command.\n2. In the Run/Debug on Cloud Run Emulator dialog, set the\n specifications for your configuration:\n\n - Only locally-installed build tools are available for Cloud Run Emulator\n - Choose **Docker** or **Buildpacks** as your builder and then specify the source\n - (Optional) To specify any environment variables to pass to the running containers, expand **Advanced Build Settings** and then click to specify key-value pairs.\n\n - (Optional) To specify Cloud SQL connections, expand **Advanced Service Settings** , click **Connections**, and then specify one Cloud SQL connection per line.\n - (Optional) Check the **Make the service accessible from other devices on the local network** option.\n - (Optional) If you only want to rebuild and run your service manually, instead of automatically when you make a change, clear the **Automatically re-build and re-run on changes** option.\n\nRunning your service locally\n----------------------------\n\n1. After you define your preferred settings, run your service by clicking\n **Run**.\n\n2. If prompted, [authenticate your credentials to run and debug an\n application locally](/code/docs/vscode/install#authenticate_credentials_for_debugging_applications_locally).\n\n3. Monitor the status of your deployment in the **output window**.\n\n After deployment is complete, you can view your running service by opening\n the URL displayed in the output window.\n4. To view verbose logs, switch to the detailed Cloud Run view\n in the output window.\n\n5. 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.\n6. 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\n7. To stop your deployment, you can click the **Stop** button in the action bar\n for your current deployment.\n\nStoring secrets\n---------------\n\nIf your code includes potentially sensitive data like API keys, passwords, and\ncertificates, storing them as secrets can help secure them. The\nCloud Code Secret Manager integration lets you securely\nstore these secrets and fetch them programmatically. For a detailed look at how\nyou can create and manage secrets with Cloud Code, see\n\nthe [Secret Manager guide](/code/docs/vscode/secret-manager).\n\n\nCustomizing an existing launch.json configuration\n-------------------------------------------------\n\nThe Cloud Code plugin updates the `launch.json` configuration file\nautomatically when you choose a run action. To further customize how your\nservice is run, you can specify the following fields in your\n`.vscode/launch.json` file:\n\n- **watch**: Watches for changes in the workspace and reruns\n the service. True by default.\n\n The following sample shows watch set to `true`: \n\n \"watch\": true,\n\n- **build** : Specify the builder\n ([Docker](https://skaffold.dev/docs/pipeline-stages/builders/docker/),\n jibMaven, jibGradle, or\n [buildpacks](https://skaffold.dev/docs/pipeline-stages/builders/buildpacks/))\n to build your images with.\n\n The following sample shows a Docker builder: \n\n \"build\": {\n \"docker\": {\n \"path\": \"Dockerfile\"\n }\n },\n\n The following sample shows a buildpack builder: \n\n \"build\": {\n \"buildpacks\": {\n \"path\": \"src/requirements.txt\",\n \"builder\": \"gcr.io/buildpacks/builder:v1\"\n }\n },\n\n- **image**: Specify the name of the image to use.\n\n The following sample shows how to specify an image name: \n\n \"image\": \"hello-world\",\n\n- **service**: Specify the Cloud Run service to use.\n\n The following sample shows how to specify a service name, port, and resource\n limits: \n\n \"service\": {\n \"name\": \"hello-world\",\n \"containerPort\": 8080,\n \"resources\": {\n \"limits\": {\n \"memory\": \"256Mi\"\n }\n }\n },\n\n- **debug**: Specify debug settings such as remote path mapping to map a local\n path to a path on the remote container.\n\n The following sample shows a debug section that indicates the source files'\n location: \n\n \"debug\": {\n \"sourceFileMap\": {\n \"${workspaceFolder}\": \"/app\"\n }\n }\n\nGet Support\n-----------\n\nTo send feedback, report issues on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues), or ask a question on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=cloud-code-vscode)."]]