Deploy a Cloud Run app by using Cloud Shell
Learn how to set up and deploy a sample Hello World application to Cloud Run and view the status of your live service's resources.
To follow step-by-step guidance for this task directly in the Cloud Shell Editor, click Guide me:
Before you begin
- 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.
-
Make sure that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
Create an application
- Launch the Cloud Shell Editor.
- From the Cloud Code status bar, select New Application.
- Choose Cloud Run application as your preferred application type.
From the list of sample applications (Node.js, Python with Flask and Django frameworks, Java, Go), choose a Hello World app.
For example, choosing
Python (Flask): Hello World
creates a starter Python (Flask) Hello World app.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.
Deploy to Cloud Run
To deploy your application to Cloud Run, follow these steps:
- Open the command palette (press
Ctrl
/Cmd
+Shift
+P
or click View > Command Palette) and then run the Deploy to Cloud Run command. This brings up the Cloud Run Deploy UI. - If prompted, authorize Cloud Code to make Google Cloud API calls.
- Set your Google Cloud project.
- If prompted, enable the Cloud Run API by clicking Enable APIs.
- In the Deploy to Cloud Run dialog, select a pre-existing service or create a new one.
- If you're creating a new service, choose Cloud Run (fully managed) under Deployment Platform.
- Choose a region to deploy to.
- For Authentication, select Allow unauthenticated invocations to make this a public service.
After you define your preferred settings, you can click Deploy.
Cloud Code builds your image, pushes it to the registry, and deploys your app to Cloud Run. Your service is now live!
View your running service by following the URL displayed in your Cloud Run: Deploy dialog.
Edit your service
To edit your application, follow these steps:
- With the Explorer view, find the
app.py
file that implements the service behavior. - Change the message "It's running!" to a message of your choosing.
- After you make this change, choose the Deploy to Cloud Run command using the Command Palette.
- Check that the service you just created is selected in Service Settings.
- Click Deploy.
- After your application finishes building and deploying, you can refresh your service to see your updated message.
View logs
You can also view logs from your deployed application with the Log Viewer that comes with Cloud Code.
To view logs, follow these steps:
- Click Cloud Code and then expand the Cloud Run section.
Right-click your Cloud Run service and then click View logs.
Refresh your app in the browser, and see the new logs generated by clicking the Logs refresh button.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
To delete your project:
Go to the Projects page in the Google Cloud console:
Select the project you created for this quickstart and then click Delete.
This shuts down the project and schedules it for deletion.
If you're using a pre-existing project and would like to delete resources you created for this quickstart:
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 Container Registry. To delete your image, open the Container Registry page, expand the repository that contain s your image, select your image, click Delete, and then click Delete.
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.
What's next
- Discover the variety of features that the Cloud Shell Editor interface has to offer.
- Learn how to configure Cloud Shell to customize your experience.