Ir a Google Cloud Console y crear un nuevo proyecto
Luego es necesario habilitar Cloud Run API
y Cloud Build API
desde "APIs & Services > Enable APIs & Services" (este paso va a solicitar habilitar el billing para el proyecto).
Una vez configurado nuestro proyecto, vamos a automatizar el proceso de build & deploy.
Cada vez que pusheemos código a la rama master
de nuestro repositorio en GitHub, Cloud Build va a buildear la imagen de Docker, subir el nuevo código a Cloud Container Registry y deployarlo a Cloud Run
-
Abrir IAM & admin > IAM
-
Editar (✏️) la cuenta
[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com
-
Click en
Add another role
-
Seleccionar
Cloud Run > Cloud Run Admin
-
Guardar
-
Seleccionar
[PROJECT_NUMBER]@developer.gserviceaccount.com
-
Agregar el rol
Service Account User
yCloud Build Service Agent
- Abrir Cloud Build > Triggers
- Connect Repository
- Elegir GitHub (Cloud Build GitHub App)
- Marcar el checkbox del repositorio deseado y aceptar TOS
- Create Push Trigger y editarlo para que sólo afecte la rama
master
Para correr en local, ejecutar lo siguiente:
docker build --tag project-cloud:latest .
docker run -p 8080:8080 --name project_cloud project-cloud:latest
Se sugiere instalar Captain
It is possible to run the exact same build process which runs in Cloud Build on your local machine. Please keep in mind Docker is required.
cloud-build-local
--config=cloud-build/cloudbuild.yaml
--dryrun=false
--push .
Prerequisitos:
- Instalar el gcloud CLI
- El usuario Owner debe habilitar App Engine
- Comprobar que tu usuario tenga los privilegios necesarios
$ gcloud builds submit --tag gcr.io/{PROJECT_ID}/{IMAGE_NAME}:latest .
$ gcloud config set project myProject
$ gcloud app deploy app.yaml
$ gcloud app deploy ./app.flexible.yaml --image-url gcr.io/{PROJECT_ID}/{IMAGE_NAME}
gcloud app describe # overview de una app
gcloud app services list # obtener listado de servicios
gcloud app services describe default # describir un servicio
The gcloud app versions list command gives the percent traffic split and serving status.
gcloud app versions list
SERVICE VERSION TRAFFIC_SPLIT LAST_DEPLOYED SERVING_STATUS
default 20181119t152033 0.00 2018–11–19T15:22:04–08:00 SERVING
default 20181119t154106 1.00 2018–11–19T15:42:05–08:00 SERVING
The gcloud app versions describe command can be used to identify the application runtime:
gcloud app versions describe --service default 20181010t161719
…
env: standard
…
servingStatus: SERVING
…
Checking Traffic You can check if your app is receiving traffic by reading the logs with the command
gcloud app logs read
Cleaning Up To delete the earlier version of the app not serving any traffic execute
VERSION=20181119t152033
gcloud app versions delete $VERSION
Check that the version has been deleted
gcloud app versions list
SERVICE VERSION TRAFFIC_SPLIT LAST_DEPLOYED SERVING_STATUS
default 20181119t154106 1.00 2018–11–19T15:42:05–08:00 SERVING
Al deployar nuevas versiones, las anteriores no se eliminan automáticamente, lo cual puede generar gastos no deseados y poco visibles.