Getting Started with Google Container Builder – Part 5

November 20, 2017

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


 

Create a custom builder and add a build step to run the tests

In this part we will create a custom builder and use it to add a build step to test the application. For this purpose we will create a custom build step to run npm using the jasmine module.

 

• Open the Cloud Shell and create a folder to store the custom builder source code

mkdir ~/npm-jasmine-node
cd ~/npm-jasmine-node

Image

 

• Create a Dockerfile to use the npm builder as the base image, install the jasmine-node module in it and set npm as entrypoint.

FROM gcr.io/cloud-builders/npm
RUN npm install -g jasmine-node
ENTRYPOINT ["npm"]

I will use VIM to create the file (for more info: How to use the VIM tool?)

Image

Image

 

• Create a cloudbuild.yaml file to build and deploy the image to container registry

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/npm-jasmine-node', '.' ]
images:
- 'gcr.io/$PROJECT_ID/npm-jasmine-node'
tags:
- 'builder'

Image

Image

 

• Trigger the build manually running the following command in the Cloud Shell

gcloud container builds submit --config cloudbuild.yaml .

Image

Image

 

• Verify that the image was successfully triggered

Image

 

• Check that the image was pushed to container registry

Image

 

• Add a step to the cloudbuild.yaml of the demo application to use the custom builder to run the tests

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'gcr.io/$PROJECT_ID/npm-jasmine-node'
  args: ['test']
- 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 and push the changes, then open the build log and check that the tests run

Image

Note: If you already created a custom builder, why not share it with the community?

 
 

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

 

Add comment
facebook linkedin twitter email

Leave a Reply