Esegui il deployment di un servizio Cloud Run utilizzando Cloud Code per Cloud Shell
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Scopri come configurare ed eseguire il deployment di un'applicazione Hello World di esempio in
Cloud Run e visualizzare lo stato delle risorse del servizio in tempo reale.
Prima di iniziare
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Dalla barra di stato di Cloud Code, seleziona Nuova applicazione.
Scegli Applicazione Cloud Run come tipo di applicazione preferito.
Dall'elenco delle applicazioni di esempio, scegli un'app Hello World. Ad esempio, se scegli
Python (Flask): Hello World, viene creata un'app
Python (Flask) Hello World iniziale.
Seleziona una cartella come percorso dell'applicazione e fai clic su
Crea nuova applicazione. L'editor di Cloud Shell carica l'applicazione in una nuova area di lavoro. Una volta caricato lo spazio di lavoro, l'app è accessibile nella vista Explorer.
Esegui il deployment in Cloud Run
Per eseguire il deployment dell'applicazione in Cloud Run:
Scegli il comando Esegui il deployment in Cloud Run utilizzando la tavolozza dei comandi (accessibile con Ctrl/Cmd+Shift+P).
Viene visualizzata la UI di Cloud Run Deploy.
Se richiesto, autorizza Cloud Code a effettuare chiamate API Google Cloud .
Configura il progetto Google Cloud .
Se richiesto, abilita l'API Cloud Run facendo clic su Abilita API.
Nella finestra di dialogo Deploy to Cloud Run (Esegui il deployment in Cloud Run), seleziona un servizio preesistente o creane uno nuovo.
Se stai creando un nuovo servizio, scegli Cloud Run (completamente gestito)
in Piattaforma di deployment.
Scegli una regione in cui eseguire il deployment.
Per l'autenticazione, seleziona Consenti chiamate non autenticate per rendere questo servizio pubblico.
Dopo aver definito le impostazioni che preferisci, fai clic su Implementa.
Cloud Code crea l'immagine, la invia al registro ed esegue il deployment dell'app su Cloud Run. Il tuo servizio è ora attivo.
Visualizza il servizio in esecuzione seguendo l'URL visualizzato nella finestra di dialogo Cloud Run: Deploy.
Modifica il tuo servizio
Per modificare la tua richiesta:
Nella visualizzazione Explorer, trova il file app.py che implementa il comportamento del servizio.
Modifica il messaggio "È in esecuzione" con un messaggio a tua scelta.
Dopo aver apportato questa modifica, scegli il comando Esegui il deployment in Cloud Run
utilizzando la tavolozza dei comandi.
Verifica che il servizio che hai creato sia selezionato in Impostazioni servizio.
Fai clic su Esegui il deployment.
Al termine della creazione e del deployment dell'applicazione, puoi aggiornare il servizio per visualizzare il messaggio aggiornato.
Visualizza i log
Puoi anche visualizzare i log dell'applicazione di cui è stato eseguito il deployment con il visualizzatore log
fornito con Cloud Code.
Per visualizzare i log:
Per aprire Explorer di Cloud Run, fai clic su
Cloud Code e poi espandi la sezione Cloud Run.
Fai clic con il tasto destro del mouse sul servizio Cloud Run e poi su Visualizza log.
Aggiorna l'app nel browser e visualizza i nuovi log generati facendo clic sul pulsante di aggiornamento dei log.
Esegui la pulizia
Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questa pagina, segui questi passaggi:
In the Google Cloud console, go to the Manage resources page.
In the project list, select the project that you
want to delete, and then click Delete.
In the dialog, type the project ID, and then click
Shut down to delete the project.
Se utilizzi un progetto preesistente e vuoi eliminare le risorse che hai creato per questa
guida rapida:
Immagine container:anche se Cloud Run non addebita costi quando un servizio non è in uso, ti potrebbero comunque essere addebitati i costi di archiviazione dell'immagine container in Artifact Registry.
Per eliminare l'immagine, apri la pagina Artifact Registry, seleziona il repository che contiene l'immagine, seleziona l'immagine, fai clic su Elimina e poi su Elimina.
Servizio Cloud Run:per eliminare un servizio Cloud Run, seleziona il servizio da eliminare nella pagina Cloud Run della consoleGoogle Cloud , fai clic su Elimina e poi su Elimina.
Apri la pagina Cloud Run
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[[["\u003cp\u003eYou can deploy a sample Hello World application to Cloud Run using the Cloud Shell Editor, selecting from a list of starter applications like Python (Flask).\u003c/p\u003e\n"],["\u003cp\u003eDeploying involves authorizing Cloud Code, setting your Google Cloud project, enabling the Cloud Run API, and choosing deployment settings like region and authentication.\u003c/p\u003e\n"],["\u003cp\u003eAfter deploying, you can easily edit your live service by modifying the source code, then redeploying with the updated changes directly from the command palette.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code's Log Viewer allows you to monitor the logs of your deployed application, aiding in real-time observation and debugging.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid charges, you have the option to delete the entire project or individual resources like container images and the Cloud Run service directly through the Google Cloud console.\u003c/p\u003e\n"]]],[],null,["Learn how to set up and deploy a sample Hello World application to\nCloud Run and view the status of your live service's resources.\n\nBefore you begin\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\nCreate an application\n\n1. [Launch the Cloud Shell Editor](https://ide.cloud.google.com).\n2. From the Cloud Code status bar, select **New Application**.\n3. Choose **Cloud Run application** as your preferred application type.\n4. From the list of sample applications, choose a Hello World app. For example, choosing `Python (Flask): Hello World` creates a starter Python (Flask) Hello World app.\n5. Select a folder as your application location and then click **Create New Application**. Cloud Shell Editor loads the application in a new workspace. After the workspace loads, your app is accessible in the explorer view.\n\nDeploy to Cloud Run\n\nTo deploy your application to Cloud Run:\n\n1. Choose the **Deploy to Cloud Run** command using the command palette (accessible with `Ctrl`/`Cmd`+`Shift`+`P`). This brings up the Cloud Run Deploy UI.\n2. If prompted, authorize Cloud Code to make Google Cloud API calls.\n3. Set your Google Cloud project.\n4. If prompted, enable the Cloud Run API by clicking **Enable APIs**.\n5. In the Deploy to Cloud Run dialog, select a pre-existing service or create a new one.\n6. If you're creating a new service, choose **Cloud Run (fully managed)** under Deployment Platform.\n7. Choose a region to deploy to.\n8. For Authentication, select **Allow unauthenticated invocations** to make this a public service.\n9. After you define your preferred settings, click **Deploy**. Cloud Code builds your image, pushes it to the registry, and deploys your app to Cloud Run. Your service is now live.\n10. View your running service by following the URL displayed in your Cloud Run: Deploy dialog.\n\nEdit your service\n\nTo edit your application:\n\n1. With the Explorer view, find the `app.py` file that implements the service behavior.\n2. Change the message \"It's running!\" to a message of your choosing.\n3. After you make this change, choose the **Deploy to Cloud Run** command using the command palette.\n4. Check that the service you created is selected in Service Settings.\n5. Click **Deploy**.\n6. After your application finishes building and deploying, you can refresh your service to see your updated message.\n\nView logs\n\nYou can also view logs from your deployed application with the Log Viewer\nthat comes with Cloud Code.\n\nTo view logs:\n\n1. To open the Cloud Run Explorer, click **Cloud Code** and then expand the **Cloud Run** section.\n2. Right-click your Cloud Run service and then click **View logs**.\n3. Refresh your app in the browser, and see the new logs generated by clicking the Logs refresh button.\n\nClean up\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps:\n\n| **Caution** : Deleting a project has the following effects:\n|\n| - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.\n| - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.\n|\n|\n| If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects\n| can help you avoid exceeding project quota limits.\n1. In the Google Cloud console, go to the **Manage resources** page.\n\n [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)\n2. In the project list, select the project that you want to delete, and then click **Delete**.\n3. In the dialog, type the project ID, and then click **Shut down** to delete the project.\n\nIf you're using a pre-existing project and want to delete the resources you created for this\nquickstart:\n\n- **Container image:** While Cloud Run doesn't charge when a service isn't in use, you might still be [charged for storing the container image in Artifact Registry](/artifact-registry/pricing). To delete your image, open the Artifact Registry page, select the repository that contains your image, select your image, click **Delete** , and then click **Delete** . \n\n [Open the Artifact Registry page](https://console.cloud.google.com/artifacts)\n- **Cloud Run service:** To delete a Cloud Run service, from the Cloud Run page in the Google Cloud console, select the service you'd like to delete, click **Delete** , and then click **Delete** .\n\n \u003cbr /\u003e\n\n [Open the Cloud Run page](https://console.cloud.google.com/run)\n\nWhat's next\n\n- Discover the features that the [Cloud Shell Editor interface](/shell/docs/editor-overview) offers.\n- Learn how to [configure Cloud Shell](/shell/docs/configuring-cloud-shell) to customize your experience."]]