Google Cloud Container Builder

From XennisWiki
Jump to: navigation, search

Service of the Google Cloud Platform to execute builds.

Usage

Docker

Build and push image

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '--tag=gcr.io/$PROJECT_ID/${_SERVICE_NAME}', '--tag=gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$SHORT_SHA', '.']
  dir: advertiser-api
images: ['gcr.io/$PROJECT_ID/${_SERVICE_NAME}']
tags: ['$SHORT_SHA']
substitutions:
  _SERVICE_NAME: my-service

Push manual in a setp

- name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'eu.gcr.io/$PROJECT_ID/${_SERVICE_NAME}']

kubectl

The Google APIs service account of the Cloud Builder (name is xxxxxxxxxxxx@cloudbuild.gserviceaccount.com) requires the roles Cloud Container Builder, and Kubernetes Engine Developer. New roles can be added under IAM & admin > IAM.

steps:
- name: 'gcr.io/cloud-builders/kubectl'
  args: ['--namespace', '${_NAMESPACE}', 'set', 'image', 'deployment/${_SERVICE_NAME}-deployment', '${_SERVICE_NAME}-container=gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$SHORT_SHA']
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=${_COMPUTE_ZONE}'
  - 'CLOUDSDK_CONTAINER_CLUSTER=${_CONTAINER_CLUSTER}'
  dir: advertiser-api
- name: 'gcr.io/cloud-builders/kubectl'
  args: ['--namespace', '${_NAMESPACE}', 'rollout', 'status', 'deployment', '${_SERVICE_NAME}-deployment']
  env:
  - 'CLOUDSDK_CONTAINER_CLUSTER=${_CONTAINER_CLUSTER}'
  - 'CLOUDSDK_COMPUTE_ZONE=${_COMPUTE_ZONE}'
timeout: 300s
tags: ['$SHORT_SHA']
substitutions:
  _COMPUTE_ZONE: europe-west1-c
  _CONTAINER_CLUSTER: my-cluster
  _NAMESPACE: default
  _SERVICE_NAME: my-service

Commands

List all builds

gcloud container builds list

Submit a build

gcloud container builds submit --config cloudbuild.yaml --substitutions SHORT_SHA=my-sha .

See also

External links