Image

GCP Cloud Shell

In Cloud Shell, the DEVSHELL_PROJECT_ID environment variable contains your project ID. Alternatively: $GOOGLE_CLOUD_PROJECT.

Some Typical Shell Commands

To LIST all container images associated with a project:

gcloud container images list

To DEPLOY a container to cloud run from shell (location must be specified as a variable beforehand):

gcloud run deploy --image gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld --allow-unauthenticated --region=$LOCATION

To DELETE CONTAINER image within project:

gcloud container images delete gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld

To DELETE CLOUD RUN SERVICE (change underlined as necessary):

gcloud run services delete helloworld --region=us-central1

To PING one VM instance from another via internal IP:

ping -c 3 <ip address>

To CREATE A VARIABLE, simply do (these disappear when closing the terminal shell):

VARIABLE_NAME=value

To verify variable:

echo $INFRACLASS_REGION

To PERSISTENTLY STORE A VARIABLE, type in:

echo VARIABLE_NAME=$VARIABLE_NAME >> ~/folder/file

Use source to SET ENV VARIABLES and then echo to verify (must use source each time a new terminal is opened):

source folder/file
echo $VARIABLE_NAME

To CREATE PERSISTENCE IN TERMINAL BY PROFILE:

nano .profile

Add the following to the end of that file:

source infraclass/config

Hit Ctrl+O, Enter to save and Ctrl+X to exit

In case of SHELL ENV CORRUPTION, follow here to reset it
https://cloud.google.com/shell/docs/resetting-cloud-shell

To switch between projects in the shell, use:

glcoud config set project <project_ID>

© Filip Niklas 2024. All poetry rights reserved. Permission is hereby granted to freely copy and use notes about programming and any code.