Skip to content

Instantly share code, notes, and snippets.

@adafycheng
Last active January 10, 2022 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adafycheng/b5fac9a538dce40c5ea73c3c5a1c26a0 to your computer and use it in GitHub Desktop.
Save adafycheng/b5fac9a538dce40c5ea73c3c5a1c26a0 to your computer and use it in GitHub Desktop.
Google Cloud Console Cheatsheet

List out the commands used for performing various tasks in Google Cloud Console.

Authentication

  1. List credentialed accounts

    gcloud auth list

  2. If the desired account is not set, set an existing account to be the current active account.

    gcloud config set core/account abc@gmail.com

  3. Set the default region.

    • Suppose the default region is europe-west1)

    gcloud config set run/region europe-west1

Create a project

  1. Create a project.

    • Suppose the project ID is portfolio-website-123456.

    gcloud projects create portfolio-website-123456

  2. Enable Billing.

Dockerize an application

Configuration

  1. Set project ID.

    • Suppose the project ID is portfolio-website-123456.

    gcloud config set project portfolio-website-123456

    The environment variable $GOOGLE_CLOUD_PROJECT is then automatically set. Print out the project ID using the following command.

    echo $GOOGLE_CLOUD_PROJECT

  2. Set Zone.

    • Suppose the desired zone is europe-west1-d.

    gcloud config set compute/zone europe-west1-d

    • View setting.

    gcloud config list

  3. Enable Cloud Run API.

    gcloud services enable run.googleapis.com

Build and Deployment

  1. Build docker image and upload to Google Container Registry.

    gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/website

  2. List docker images in Google Container Registry.

    gcloud container images list

  3. Deploy to Cloud Run.

    gcloud run deploy portfolio-website \
    --image gcr.io/$GOOGLE_CLOUD_PROJECT/website:latest \
    --platform managed \
    --region europe-west1 \
    --allow-unauthenticated
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment