Skip to content

mitchallen/cloud-run-103

Repository files navigation

cloud-run-102

A Google Cloud Run starter project

This package was created as a gloud run demo.

This is an update to my older, now outdated demos (cloud-run-101, cloud-run-102).

Installation

$ git clone https://github.com/mitchallen/cloud-run-103.git

Create a Google Cloud Platform account


Note about billing

Please note that this demo shows how to use services that Google will bill you for.
New users are given a credit and some services are offered for free, below a minimal use.

Be sure to keep an eye on billing and delete test resources when no longer needed.

See: https://console.cloud.google.com/billing


Create a GCP (Google Cloud Platform) project

Install the gcloud CLI (command line interface)

Mac OS

brew install --cask google-cloud-sdk

Initialize a project

gcloud init

Initialize components

Run this command to update the components

gcloud components update

Set the region

For example, I chose us-central1.

gcloud config set run/region us-central1

Enable some services

gcloud services enable \
    artifactregistry.googleapis.com \
    cloudbuild.googleapis.com \
    run.googleapis.com

Auth Docker

gcloud auth configure-docker YOUR_REGION-docker.pkg.dev

Create a repo to hold Docker images

gcloud artifacts repositories create demo-repo \
    --repository-format=docker \
    --location=YOUR_REGION \
    --description="Docker repo'

Create the Docker image in GCP

Substitute PROJECT-ID with your current gcloud project id:

gcloud builds submit --tag YOUR_REGION-docker.pkg.dev/PROJECT-ID/demo-repo/hello

For the region of us-central1:

gcloud builds submit --tag us-central1-docker.pkg.dev/PROJECT-ID/demo-repo/hello

If you forgot your project ID:

gcloud projects list

You can also check the state of things with:

gcloud info

To see and manage the container image, browse to:


Deploy to Cloud Run

Substitute PROJECT-ID with your current gcloud project id:

gcloud run deploy hello-web --image REGION-docker.pkg.dev/PROJECT-ID/demo-repo/hello

Assuming you don't care if anyone runs your app (as in making it public):

Allow unauthenticated invocations to [hello-web] (y/N)?

If you are concerned about billing, no one will know the URL address if you don't publicly post it anywhere. And you can immediately kill the service when done testing to avoid any unauthorized access or billing.

The command line will then give you the URL of your app, with a message like this (with your own unique URL):

Service [hello-web] revision [hello-web-abcd] has been deployed and is serving 100 percent of traffic at https://hello-web-SOME-RANDOM-ID.a.run.app

Copy the URL and paste the address into a browser or use curl.

See the service in the console

To see and manage the service in the Google Cloud Platform console, browse to:


Cleanup

To save money you should consider taking down private and test resources when not in use. To use them again, be sure to document how to recreate them.

Visit the following console pages to delete test resources:

To delete the service using the command line, run this command:

gcloud run services delete hello-web

To delete the image using the command line (substitute PROJECT-ID with your Google cloud Project ID):

gcloud artifacts docker images delete REGION-docker.pkg.dev/PROJECT-ID/demo-repo/hello

To delete the repo:

gcloud artifacts repositories delete demo-repo

To monitor billing:


References

About

Cloud Run demo updated for Artifacts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published