Cheat Sheets

Here are some commonly used commands and links.

gcloud

Basics

Task

Enable an API

gcloud services enable ${API}

Current Project ID

gcloud config get-value project

Export to PROJECT_ID

PROJECT_ID=$(gcloud config get-value project)

Authentication

gcloud auth login

Application Credentials Login

gcloud auth application-default login

Default Zone

gcloud config set compute/zone us-central1-c

Default Region

gcloud config set compute/region us-central1

All Regions and Zones

Regions and Zones

Identity Access Management

Task

Create a Service Account

gcloud iam service-accounts create \

${SA_NAME}

Service Account E-Mail

${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com

Add Permission

gcloud projects add-iam-policy-binding ${PROJECT_ID} \

--member serviceAccount:${SA_EMAIL} \

--role ${ROLES}

Create a Service Account Key File

gcloud iam service-accounts keys create \

$HOME/sa-key.json \

--iam-account ${SA_EMAIL}

All Possible Roles

Understanding roles

Serverless Deployments

Task

App Engine

gcloud app deploy ${JAR_FILE}

gcloud app deploy ${JAR_FILE} --appyaml app.yaml

Maven plugin

Gradle Plugin

Cloud Run

gcloud run deploy ${NAME} \

--platform=managed \

--allow-unauthenticated \

--image=gcr.io/${PROJECT_ID}/${IMAGE_NAME}

gcloud run deploy ${NAME} \

--platform=managed \

--allow-unauthenticated \

--cpu=2 \

--memory=512M \

--set-env-vars="JAVA_TOOL_OPTIONS=-Dproperty=value"

--image=gcr.io/${PROJECT_ID}/${IMAGE_NAME}

Cloud Function

gcloud functions deploy ${NAME}

--trigger-http \

--runtime=java11 \

--allow-unauthenticated \

--entry-point=${FUNCTION_CLASS_FQN}

Maven plugin

Jib

Task

Create a remote Image

mvn jib:build

gradle jib

Create a local image

mvn jib:dockerBuild

gradle jibDockerBuild

Run Jib without

pre-configured plugin

mvn compile \

com.google.cloud.tools:jib-maven-plugin:2.4.0:build \

-Dimage=gcr.io/${PROJECT_ID}/${IMAGE_NAME}

Jib READMEs

Maven plugin

Gradle plugin

Spring Initializer

Task

Create a new app w/

Spring Cloud GCP

curl https://start.spring.io/starter.zip \

-d dependencies=web,cloud-gcp \

-d bootVersion=2.3.1.RELEASE \

-d baseDir=demo