Getting Started with Google Container Builder – Part 2

November 20, 2017

Note: This is the second part in a series of posts Getting Started with Google Container Builder


 

Configure basic CI to create Docker images and store them in Google Container Registry

In this part we will create the most basic build possible, just create a docker image and store it in Google Container Registry to use it later.

 

• Create a new file in the repository root: cloudbuild.yaml

Image

 

• Add the below to the file to use the npm builder to run npm install and the docker builder to build the docker image:

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/sdp-demo-app:$SHORT_SHA', '.' ]

 

• Add the image section below to configure container builder to push the created image to the container registry:

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/sdp-demo-app:$SHORT_SHA', '.' ]
images:
- 'gcr.io/$PROJECT_ID/sdp-demo-app'

 

• Finally add a tags section and within it add tag(s) to be able to filter the builds later:

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/sdp-demo-app:$SHORT_SHA', '.' ]
images:
- 'gcr.io/$PROJECT_ID/sdp-demo-app'
tags:
- 'demo'
- 'nodejs'

 

• Commit, push the changes and go to the build triggers section under container registry and click Add Trigger to configure the build to run after each commit

Image

 

• Select Cloud source Repository and click Continue

Image

 

• Select the repository and click Continue

Image

 

• Configure the trigger with the information below and click Create Trigger:

Trigger Name: sdp-demo-build
Trigger Type: Branch
Branch (regex): .*
Build Configuration: cloudbuild.yaml
cloudbuild.yaml location: /cloudbuild.yaml

Image

 

• Trigger the created build by click Run Trigger -> master

Image

 

• Ensure the build was triggered (in the build history section under container registry) and click the build Id to see the build log

Image

 

• Ensure the docker image was pushed to container registry (in the images section under container registry)

Image

 

Optional: Commit and push new changes to see how the build is triggered automatically

 
 

Continue with: Getting Started with Google Container Builder – Part 3

 

Add comment
facebook linkedin twitter email

Leave a Reply