Deploy - Google Cloud
Deploy a containerized application to Cloud Run using Cloud Build
Before you begin
- If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers 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.
Enable the Cloud Build, Cloud Run, Artifact Registry, and Compute Engine APIs.
- Install the Google Cloud CLI.
To initialize the gcloud CLI, run the following command:
Grant permissions
Cloud Build requires Cloud Run Admin and IAM Service Account User permissions before it can deploy an image to Cloud Run.
Open a terminal window.
Set environment variables to store your project ID and project number:
Grant the Cloud Run Admin role to the Cloud Build service account:
Grant the IAM Service Account User role to the Cloud Build service account for the Cloud Run runtime service account:
Deploy a prebuilt image
You can configure Cloud Build to deploy a prebuilt image that is stored in Artifact Registry to Cloud Run.
To deploy a prebuilt image:
Open a terminal window (if not already open).
Create a new directory named
helloworld
and navigate into it:Create a file named
cloudbuild.yaml
with the following contents. This file is the Cloud Build config file. It contains instructions for Cloud Build to deploy the image namedus-docker.pkg.dev/cloudrun/container/hello
on the Cloud Run service namedcloudrunservice
.Deploy the image by running the following command:
When the build is complete, you will see an output similar to the following:
You've just deployed the image hello
to Cloud Run.
Run the deployed image
Open the Cloud Run page in the Google Cloud console:
Select your project and click Open.
You will see the Cloud Run Services page.
In the table, locate the row with the name cloudrunservice, and click cloudrunservice.
The Service details page for cloudrunservice is displayed.
To run the image that you deployed on cloudrunservice, click the URL:
Comments
Post a Comment