gcloud CLI

Notas.


Introducción

Para el interesado, estas notas son un recuento (por el momento) sin mayor orden o estructura. Están siendo acumuladas por el momento en espera de que, llegado el momento en que se acumula «cierta masa crítica», se organicen de una mejor forma.

Como alguna vez tuitee:

Aprendizaje

Como toda nube de cómputo (o entorno nuboso de computación) GCP incluye una herramienta para interactuar con servicios e infraestructura desde la línea de comandos. Un buen punto de inicio es la página de presentación del producto1 y los videos en ella.

Instalación

El primer paso es hacerse del SDK y hay varias formas de instalar. La página de instalación es bastante explícita en ello.

Autenticación

La documentación de Google2 pareciera indicar que el uso de asistentes de credenciales (credential helpers) debe efectuarse en dos pasos (uno usando credenciales de usuario y otro configurando una cuenta de servicio) pero parece ser que se trata de dos alternativas más que una secuencia de pasos. La verdad no me queda claro el asunto.

Mi experiencia, por el momento, se reduce a la autenticación para poder hacer uso del CLI

$ gcloud auth login

y a una autenticación básica o por defecto para poder hacer uso de llamados a las funciones de nube, que se logra con:

$ gcloud auth application-default login

y que deja un archivo application_default_credentials.json en $HOME/.config/gcloud.

Cloud Shell

Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to eng-genai-pilot.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
avilaeduardo@cloudshell:~ (eng-genai-pilot)$ gcloud auth login

You are already authenticated with gcloud when running
inside the Cloud Shell and so do not need to run this
command. Do you wish to proceed anyway?

Do you want to continue (Y/n)? Y

Go to the following link in your browser, and complete the sign-in prompts:

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=9TJ4dgtAnp5J5nXgM0XwSnRYhT0zgY&prompt=consent&token_usage=remote&access_type=offline&code_challenge=gxMLYfFUGsgR3toeaNd_l9N83ezvCYkThEqphHb22YA&code_challenge_method=S256

Once finished, enter the verification code provided in your browser: 4/0AcvDMrBkLVdAJ3VpceuSNcmm2_IhHUH1yl-zH20ufJMGm0lqYKQymkVCVhvJe58vAfNg4w

You are now logged in as [avilaeduardo@google.com].
Your current project is [eng-genai-pilot]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
avilaeduardo@cloudshell:~ (eng-genai-pilot)$
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to eng-genai-pilot.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
avilaeduardo@cloudshell:~ (eng-genai-pilot)$ gcloud config set project ra-crs-tf-3
Updated property [core/project].
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$ gcloud auth login

You are already authenticated with gcloud when running
inside the Cloud Shell and so do not need to run this
command. Do you wish to proceed anyway?

Do you want to continue (Y/n)? Y

Go to the following link in your browser, and complete the sign-in prompts:

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=zR9fe3zhfBvwWUNbEHla5hMpLlJrg9&prompt=consent&token_usage=remote&access_type=offline&code_challenge=cwtfck57z0Esw0yPdhjN-w0lSg0gx-tdlDx7km4AAv0&code_challenge_method=S256

Once finished, enter the verification code provided in your browser: 4/0AcvDMrCcQLldxygg1lyrZgiT-XhURLq8sVH7G3l1XiLf3o8cLiravgV4r4WutpVYD5CtQg

You are now logged in as [avilaeduardo@google.com].
Your current project is [ra-crs-tf-3]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$ git config --global user.email "avilaeduardo@google.com"
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$ git config --global credential.'https://..sourcemanager.dev'.helper gcloud.sh
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$ pwd
/home/avilaeduardo
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$ ls
backconf.sh cluster-backup Liveramp README-cloudshell.txt
avilaeduardo@cloudshell:~ (ra-crs-tf-3)$ cd L*
avilaeduardo@cloudshell:~/Liveramp (ra-crs-tf-3)$ ls
SSH
avilaeduardo@cloudshell:~/Liveramp (ra-crs-tf-3)$ git clone https://liveramp-567794993156-git.us-central1.sourcemanager.dev/cloud-professional-services/liveramp-sre-agent.git Code
Cloning into 'Code'...
remote: Enumerating objects: 277, done.
remote: Counting objects: 100% (277/277), done.
remote: Compressing objects: 100% (270/270), done.
remote: Total 277 (delta 162), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (277/277), 131.73 KiB | 8.23 MiB/s, done.
Resolving deltas: 100% (162/162), done.
avilaeduardo@cloudshell:~/Liveramp (ra-crs-tf-3)$ ls
Code SSH
avilaeduardo@cloudshell:~/Liveramp (ra-crs-tf-3)$ cd Code
avilaeduardo@cloudshell:~/Liveramp/Code (ra-crs-tf-3)$ ls
agent functions README.md terraform
avilaeduardo@cloudshell:~/Liveramp/Code (ra-crs-tf-3)$ cd agent
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ ls
agent_builer agent_creation.py examples_creation.py test_cases_creation.py tools_creation.py
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ mv agent_builer "Agent Builder"
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ ls
'Agent Builder' agent_creation.py examples_creation.py test_cases_creation.py tools_creation.py
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ mv 'Agent Builder' Agent_Builder
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ ls
Agent_Builder agent_creation.py examples_creation.py test_cases_creation.py tools_creation.py
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: agent_builer/ReadMe.md
deleted: agent_builer/Uniagent_0.1.zip
deleted: agent_builer/test.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)
Agent_Builder/

no changes added to commit (use "git add" and/or "git commit -a")
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git pull
Already up to date.
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git add Agent_Builder/
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git commit -m 'Directory renamed'
Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <avilaeduardo@google.com>) not allowed
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git config --global user.email "avilaeduardo@google.com"
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git config --global user.name "Eduardo Rodriguez Avila"
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git commit -m 'Directory renamed'
[main fd5ceed] Directory renamed
3 files changed, 4 insertions(+)
create mode 100644 agent/Agent_Builder/ReadMe.md
create mode 100644 agent/Agent_Builder/Uniagent_0.1.zip
create mode 100644 agent/Agent_Builder/test.txt
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 325 bytes | 162.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To https://liveramp-567794993156-git.us-central1.sourcemanager.dev/cloud-professional-services/liveramp-sre-agent.git
da2a303..fd5ceed main -> main
avilaeduardo@cloudshell:~/Liveramp/Code/agent (ra-crs-tf-3)$
gcloud auth login
git config --global user.email "your google mail"
git config --global credential.'https://..sourcemanager.dev'.helper gcloud.sh

Docker

El acceso al repositorio de imágenes de Docker debe ser autorizado primero para poder interactuar con éste2.

$ gcloud auth configure-docker

Referencias

  1. «Cloud SDK», Google, Inc., web. Visited: 2022.07.20. URL: https://cloud.google.com/sdk.
  2. «Authentication methods«, Google, Inc., web. Visited: 2022.07.21. URL: https://cloud.google.com/container-registry/docs/advanced-authentication.
  3. «gcloud auth application-default login«, Google, Inc. in «gcloud Reference«, web. Visited: 2022.08.03. URL: https://cloud.google.com/sdk/gcloud/reference.

Twitter Wordpress eMail
© Todos los derechos reservados.
Dr. Eduardo René Rodríguez Avila
Creación: 2022.07.20
Última actualización: 2024.08.14
El contenido de este sitio puede ser copiado y reproducido libremente mientras no sea alterado y se cite su origen. Marcas y productos registrados son citados por referencia y sin fines de lucro o dolo. Todas las opiniones son a título personal del o los autores de éstas y, salvo sea expresado de otro modo, deben considerarse como registro y expresión de la experiencia de uso de aquello que es tratado. Para conocer más sobre la posición de privacidad y responsabilidad de lo que se presenta en este sitio web y como ha sido obtenido, consulte la declaración al respecto.