This workflow uses Google Cloud Builder to build a go application's source code that lives in Google Cloud Registry into a docker container.
The go application's source code is built into a binary using Google Cloud Builder's docker step (read more about steps).
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/docker/test-go-build', '.' ]
This Binary is then imported into a container that is built and pushed to Google Container Registry.
# Build the image
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/docker/test-go', '.' ]
images:
- 'gcr.io/$PROJECT_ID/docker/test-go'
That image is then used in a deployment in GKE (Google Kubernetes Engine). The entire workflow relies on Google Cloud Builder
steps:
- name: 'gcr.io/cloud-builders/kubectl'
args:
- 'set'
- 'image'
- 'deployment'
- 'test-go-cb'
- 'test-go-cb=gcr.io/$PROJECT_ID/docker/test-go'
gcloud source repos create test-go
gcloud source repos list
git init
git config credential.helper gcloud.sh
git remote add google \
https://source.developers.google.com/p/[PROJECT_ID]/r/[CLOUD_SOURCE_REPOSITORY_NAME]
git push google master
gsutil mb gs://artifacts-[PROJECT_ID]/
gcloud iam service-accounts describe $PROJECT_ID@cloudbuild.gserviceaccount.com
PROJECT_ID="$(gcloud projects describe \
$(gcloud config get-value core/project -q) --format='get(projectNumber)')"
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:$PROJECT_ID@cloudbuild.gserviceaccount.com \
--role=roles/container.developer
alias container-build='gcloud container builds submit --config cloudbuild.yaml .'
export REPO=`pwd`
# build binary
cd $REPO/build
container-build
# build image
cd $REPO/code
container-build
# bootstrap
cd $REPO/bootstrap
container-build
# deploy
cd $REPO/deploy
container-build