CI/CD for Google Cloud Build and Cloud Compute Engine

  1. GitHup Source code
  2. Example CloudBuild.yaml in GitHub repo.
  3. Create a trigger.
  4. Explanation of the last Cloud step inside of the CloudBuild.yaml.
  5. Create the cloud compute engine instance group.
steps:
- name: gcr.io/cloud-builders/docker
entrypoint: 'bash'
args: ['-c', 'docker build -t gcr.io/$PROJECT_ID/app-backend:$SHORT_SHA -t gcr.io/$PROJECT_ID/app-backend:latest .']
- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/app-backend"]
- name: "gcr.io/cloud-builders/gcloud"
entrypoint: "/bin/bash"
args:
['-c','for i in $(gcloud compute instances list --filter NAME~"app-backend-instance-group" --format="value(NAME)");do gcloud beta compute instances update-container $i --zone europe-west3-c --container-image=gcr.io/$PROJECT_ID/app-backend:latest;done',]
images:
- 'gcr.io/$PROJECT_ID/app-backend:$SHORT_SHA'
- 'gcr.io/$PROJECT_ID/app-backend:latest'
timeout: 3600s
options:
logging: CLOUD_LOGGING_ONLY
- name: "gcr.io/cloud-builders/gcloud"
entrypoint: "/bin/bash"
args:
['-c','for i in $(gcloud compute instances list --filter NAME~"app-backend-instance-group" --format="value(NAME)");do gcloud beta compute instances update-container $i --zone europe-west3-c --container-image=gcr.io/$PROJECT_ID/app-backend:latest;done',]
gcloud compute instances list --filter NAME~"app-backend-instance-group"
gcloud compute instances list --filter NAME~"app-backend-instance-group" | grep NAME
gcloud beta compute instances update-container app-backend-instance-group-xq3w --zone europe-west3-c --container-image=gcr.io/deployments-337523/app-backend:latest
#!/bin/bash
for i in $(gcloud compute instances list --filter NAME~"app-backend-instance-group" --format="value(NAME)");
do
gcloud beta compute instances update-container $i --zone europe-west3-c --container-image=gcr.io/deployments-337523/app-backend:latest;
done
for i in $(gcloud compute instances list --filter NAME~"app-backend-instance-group" --format="value(NAME)”);do gcloud beta compute instances update-container $i --zone europe-west3-c --container-image=gcr.io/deployments-337523/app-backend:latest;done

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Walter-Tscharf-Development

Walter-Tscharf-Development

If you like my work or have question contact me.