© 2014 IBM Corporation
Create Docker Image
with Bluemix DevOps
Joseph Chang
Senior IT Specialist
IBM Cloud Group
© 2014 IBM Corporation2
Take me to Bluemix
Click Here
If you are new to Bluemix Docker Container, please start with the links:
https://www.ng.bluemix.net/docs/containers/container_index.html
https://www.ng.bluemix.net/docs/containers/container_optional.html
© 2014 IBM Corporation3
Lifecycle of DevOps with Bluemix Docker
Create
Dockerfile
Commit
change
Build
Docker Image
Publish To
Docker
Registry
Run
Docker
Container
Edit
Application
Source code
Web Editor Web Editor Web Git Auto Build
Bluemix
Catalog
Manual Deploy
Create
Dockerfile
Commit
change
Build
Docker Image
Publish To
Docker
Registry
Run
Docker
Container
© 2014 IBM Corporation
Edit Application Source Code
In order to get a sample web application with source code in JazzHub, I decide to
“borrow” the sample from Bluemix Node.js (Cloud Foundry) Runtime. So….
4
Let’s start from create a .js runtime.
Create a
Node.js
runtime.
© 2014 IBM Corporation
Edit Application Source Code
 We no longer this runtime . We just need the source code of this
sample to build new Docker Image. Let’s go to the Web IDE to see the
source code.
5
Create the GIT
project.
© 2014 IBM Corporation
Edit Application Source Code
 Now we get the sample application in Git.
6
© 2014 IBM Corporation
Edit Application Source Code
 To move out of CF, the app.js need to be modified.
7
Line 13: remove it
Line 22: replaced with hardcode port number, url
© 2014 IBM Corporation
Edit Application Source Code
8
 Here is the app.js after modified..
© 2014 IBM Corporation
Create Dockerfile
9
Right click here to get
popup menu. Click on
the New->File, name it
as Dockerfile
© 2014 IBM Corporation
Create Dockerfile
10
You should see the
Dockerfile in the list.
Let’s start edit the content.
© 2014 IBM Corporation
Create Dockerfile
11
 Here is the sample docker file for running Node.js on port 80 in the container.
Line 2: We user the ibmnode image as base image
Line 6- Line 7: Move the package.json to docker image then run npm install
Line 8- Line 9: Copy app.js and all files in /public to image
Line 10-Line 11: expose port 80
Line 14: start app.js
© 2014 IBM Corporation
Modify Build & Deploy Configuration
12
That’s all the code need to be
modified.
Now we need to modify the Build &
Deploy Configuration for build & run
Docker image. Click Build and Deploy
Button on up right side.
© 2014 IBM Corporation
Modify Build Configuration
13
 Click on the up right icon of Build Stage. Then click Configure Stage.
Click here to
continue.
© 2014 IBM Corporation
Modify Build Configuration
14
 Let’s change the Build type..
Select IBM
Container Service
as Build Type.
© 2014 IBM Corporation
Modify Build Configuration
15
Fill in Organization,
Space, and Image
name
Here is the Dockimage
build script. Normally
you don’t need to modify
it.
Uncheck this
The image name
must be in
Lower Case
Re-Select
the space.
© 2014 IBM Corporation
Modify Build Configuration
16
Let’s take look at the build script.
#!/bin/bash
# The following colors have been defined to help with presentation of logs: green, red, label_color, no_color.
log_and_echo "$LABEL" "Starting build script"
# The IBM Container Service CLI (ice), Git client (git), IDS Inventory CLI (ids-inv) and Python 2.7.3 (python) have been installed.
# Based on the organization and space selected in the Job credentials are in place for both IBM Container Service and IBM Bluemix
#####################
# Run unit tests #
#####################
log_and_echo "$LABEL" "No unit tests cases have been checked in"
######################################
# Build Container via Dockerfile #
######################################
# REGISTRY_URL=${CCS_REGISTRY_HOST}/${NAMESPACE}
# FULL_REPOSITORY_NAME=${REGISTRY_URL}/${IMAGE_NAME}:${APPLICATION_VERSION}
# If you wish to receive slack notifications, set SLACK_WEBHOOK_PATH as a property on the stage.
if [ -f Dockerfile ]; then
log_and_echo "$LABEL" "Building ${FULL_REPOSITORY_NAME}"
${EXT_DIR}/utilities/sendMessage.sh -l info -m "New container build requested for ${FULL_REPOSITORY_NAME}"
# build image
BUILD_COMMAND=""
if [ "${USE_CACHED_LAYERS}" == "true" ]; then
BUILD_COMMAND="build --pull --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}"
ice_retry ${BUILD_COMMAND}
RESULT=$?
else
BUILD_COMMAND="build --no-cache --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}"
ice_retry ${BUILD_COMMAND}
RESULT=$?
fi
© 2014 IBM Corporation
Modify Build Configuration
17
Let’s take look at the build script. (Continue)
if [ $RESULT -ne 0 ]; then
log_and_echo "$ERROR" "Error building image"
ice info
ice images
${EXT_DIR}/print_help.sh
${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Container build of ${FULL_REPOSITORY_NAME} failed. $(get_error_info)"
exit 1
else
log_and_echo "$SUCCESSFUL" "Container build of ${FULL_REPOSITORY_NAME} was successful"
${EXT_DIR}/utilities/sendMessage.sh -l good -m "Container build of ${FULL_REPOSITORY_NAME} was successful"
fi
else
log_and_echo "$ERROR" "Dockerfile not found in project"
${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Failed to get Dockerfile. $(get_error_info)"
exit 1
fi
######################################################################################
# Copy any artifacts that will be needed for deployment and testing to $WORKSPACE #
######################################################################################
echo "IMAGE_NAME=${FULL_REPOSITORY_NAME}" >> $ARCHIVE_DIR/build.properties
© 2014 IBM Corporation
Modify Build Configuration
18
Click Save to Continue
© 2014 IBM Corporation
Modify Deploy Configuration
19
Click here to modify the
Configuration of Deploy
Stage.
© 2014 IBM Corporation
Modify Deploy Configuration
20
Select IBM
Containers on
Bluemix as Deployer
Type
© 2014 IBM Corporation
Modify Deploy Configuration
21
Select the Organization,
Space….
© 2014 IBM Corporation
Modify Deploy Configuration
22
Let’s take look at the deploy script.
#!/bin/bash
# The following are some example deployment scripts. Use these as is or fork them and include your updates here:
echo -e "${label_color}Starting deployment script${no_color}"
# To view/fork this script goto: https://github.com/Osthanes/deployscripts
# git_retry will retry git calls to prevent pipeline failure on temporary github problems
# the code can be found in git_util.sh at https://github.com/Osthanes/container_deployer
git_retry clone https://github.com/Osthanes/deployscripts.git deployscripts
# You can deploy your Image as either a single Container or as a Container
# Group. A Container Group deploys a number of containers to enhance
# scalability or reliability. By default we will deploy as a single
# container. To switch to a group deploy, comment out the line below
# containing deploycontainer.sh and uncomment the line for deploygroup.sh
# Deploy with containers:
# Optional environment properties (can be set directly in this script, or defined as environment properties):
# NAME Value Description
# ============= ========= ==============
# BIND_TO String Specify a Bluemix application name that whose bound services you wish to make available to the
container. By default this is not set.
# CONTAINER_SIZE String Specify container size: pico (64), nano (128), micro (256), tiny (512), small (1024), medium
(2048),
# large (4096), x-large (8192), 2x-large (16384).
# Default is micro (256).
# CONCURRENT_VERSIONS Number Number of versions of this container to leave active.
# Default is 1
#
/bin/bash deployscripts/deploycontainer.sh
© 2014 IBM Corporation
Modify Deploy Configuration
23
Let’s take look at the deploy script. (Continue)
# Deploy Container Group:
# Optional environment properties (can be set directly in this script, or defined as environment properties):
# NAME Value Description
# ============= ========= ==============
# ROUTE_HOSTNAME String Specify the Hostname for the Cloud Foundry Route you wish to assign to this container group. By
default this is not set.
# ROUTE_DOMAIN String Specify domain name for the Cloud Foundry Route you wish to assign to this container group. By
default this is not set.
# BIND_TO String Specify a Bluemix application name that whose bound services you wish to make available to the
container. By default this is not set.
# DESIRED_INSTANCES: Number Specify the number of instances in the group. Default value is 1.
# AUTO_RECOVERY: Boolean Set auto-recovery to true/false. Default value is false.
# Default is false.
# CONTAINER_SIZE String Specify container size: pico (64), nano (128), micro (256), tiny (512), small (1024), medium
(2048),
# large (4096), x-large (8192), 2x-large (16384).
# Default is micro (256).
# CONCURRENT_VERSIONS Number Number of versions of this group to leave active.
# Default is 1
# IF YOU WANT CONTAINER GROUPS .. uncomment the next line, and comment out the previous deployment line (/bin/bash
deployscripts/deploygroup.sh)
#/bin/bash deployscripts/deploygroup.sh
RESULT=$?
# source the deploy property file
if [ -f "${DEPLOY_PROPERTY_FILE}" ]; then
source "$DEPLOY_PROPERTY_FILE"
fi
#########################
# Environment DETAILS #
#########################
# The environment has been setup.
# The Cloud Foundry CLI (cf), IBM Container Service CLI (ice), Git client (git), IDS Inventory CLI (ids-inv) and Python 2.7.3
(python) have been installed.
# Based on the organization and space selected in the Job credentials are in place for both IBM Container Service and IBM Bluemix
# The following colors have been defined to help with presentation of logs: green, red, label_color, no_color.
if [ $RESULT -ne 0 ]; then
echo -e "${red}Executed failed or had warnings ${no_color}"
${EXT_DIR}/print_help.sh
exit $RESULT
fi
echo -e "${green}Execution complete${no_label}"
If you want to deploy
Container Group, you
need to uncomment this line.
© 2014 IBM Corporation
Modify Deploy Configuration
24
Fill in the Name of the
instance then click
Save.
© 2014 IBM Corporation
Commit Change
25
Go back to EDIT CODE
page then click GIT
respository
Let’s back to EDIT CODE perspective.EDIT CODE
© 2014 IBM Corporation
Commit Change
26
1. Select all
of the
changes.
2. Give a
comment.
3. Click
Confirm
.4. Push the
changes to
build pipeline
© 2014 IBM Corporation
Build Docker Image
27
Switch to EDIT CODE perspective to see the result.Build & Deploy
The docker image
have been created.
© 2014 IBM Corporation
Build Docker Image
28
Let’s have a look at what happens during the build.
 Started by user joseph
 Building remotely on jenkins-build-slave-b9d10a965120 (.*Build) in workspace /home/jenkins/workspace/e6059a87-3337-a67b-64ea-4bf1b5df961f/7dc9942f-7e3b-47bb-9cdd-
665e50e37d55
 Cloning the remote Git repository
 Cloning repository https://hub.jazz.net/git/joseph/helloWebApp
 Fetching upstream changes from https://hub.jazz.net/git/joseph/helloWebApp
 using .gitcredentials to set credentials
 Checking out Revision 918917ba36eb1bff5eee958e86cb14d6c1eee850 (detached)
 [7dc9942f-7e3b-47bb-9cdd-665e50e37d55] $ /bin/bash /tmp/hudson1082149903417757598.sh
 + cat /etc/lsb-release /etc/os-release
 DISTRIB_ID=Ubuntu
 DISTRIB_RELEASE=14.04
 DISTRIB_CODENAME=trusty
 DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"
 NAME="Ubuntu"
 VERSION="14.04.2 LTS, Trusty Tahr"
 ID=ubuntu
 ID_LIKE=debian
 PRETTY_NAME="Ubuntu 14.04.2 LTS"
 VERSION_ID="14.04"
 HOME_URL="http://www.ubuntu.com/"
 SUPPORT_URL="http://help.ubuntu.com/"
 BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
 + source _script.sh
© 2014 IBM Corporation
Build Docker Image
29
 ++ set +x
 git clone https://github.com/Osthanes/utilities.git utilities
 Cloning into 'utilities'...
 APPLICATION_VERSION: 6
 Archiving to /home/jenkins/workspace/e6059a87-3337-a67b-64ea-4bf1b5df961f/7dc9942f-7e3b-47bb-9cdd-665e50e37d55/.cs_archive
 Installing IBM Container Service CLI
 Installing Python 2.7
 Python 2.7.6
 Successfully installed IBM Container Service CLI
 Installing Cloud Foundry CLI
 Successfully installed Cloud Foundry CLI
 Bluemix host is 'api.ng.bluemix.net'
 Bluemix target is 'prod'
 Date/Time : 2015-08-14 03:41:20.476922
 Debug mode : False
 CCS host/url : https://containers-api.ng.bluemix.net/v3/containers
 Registry host : registry.ng.bluemix.net
 Bluemix api host/url : api.ng.bluemix.net
 Bluemix Org : changhs@tw.ibm.com (1f6d3957-c6c6-4804-a8c2-5c7b5d382387)
 Bluemix Space : 0-sandbox (3fb3e792-dfb1-4fc2-83ab-62435218d59a)
 ICE CLI Version : 2.0 646 2015-07-20T18:51:33
 CCS API Version : 3.0 1306 2015-08-11T15:41:15
 Repository namespace : jjregistry
 Containers limit : Unlimited
© 2014 IBM Corporation
Build Docker Image
30
 Containers usage : 1
 Containers running : 1
 CPU limit (cores) : Unlimited
 CPU usage (cores) : 4
 Memory limit (MB) : 2048
 Memory usage (MB) : 256
 Floating IPs limit : 2
 Floating IPs allocated : 1
 Floating IPs bound : 1
 Image Id Created Image Name
 97513e56aaa70b9daf1627734f18efcd7023 Aug 14 02:03:35 2015 registry.ng.bluemix.net/ibm-mobilefirst-starter:latest
 97513e56aaa70b9daf1627734f18efcd7023 Aug 14 02:02:14 2015 registry.ng.bluemix.net/ibm-mobilefirst-starter:7.1.0
 68e01b620447d7468f6b098ea0e6023257f6 Aug 6 03:31:53 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:10
 777c0f64f1215d45272c9c301721e19689ee Aug 4 17:19:45 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:9
 c0ace5c9ec7cd7f7c18a85fa841af99a79f9 Aug 1 16:31:19 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:8
 de3ab2d47694b8482d1ca10d68e802d5ccd5 Aug 1 13:11:06 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:7
 9a00bc0f-fbbf-4b48-9831-6271db8b8603 Aug 1 12:52:14 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:6
 2209a9732f35a906491005f87c130bb73e26 Jul 23 15:08:49 2015 registry.ng.bluemix.net/ibmliberty:latest
 8f962f6afc9a30b646b9347ecb7f458bf75b Jul 23 15:05:40 2015 registry.ng.bluemix.net/ibmnode:latest
 17cd72f2667163c517253c0127425677d20d Jul 9 03:54:37 2015 registry.ng.bluemix.net/jjregistry/etherpad_bluemix:latest
 Successfully accessed into IBM Container Service using credentials passed from IBM DevOps Services
© 2014 IBM Corporation
Build Docker Image
31
 Successfully accessed into IBM Containers Service
 Date/Time : 2015-08-14 03:41:26.812804
 Debug mode : False
 CCS host/url : https://containers-api.ng.bluemix.net/v3/containers
 Registry host : registry.ng.bluemix.net
 Bluemix api host/url : api.ng.bluemix.net
 Bluemix Org : changhs@tw.ibm.com (1f6d3957-c6c6-4804-a8c2-5c7b5d382387)
 Bluemix Space : 0-sandbox (3fb3e792-dfb1-4fc2-83ab-62435218d59a)
 ICE CLI Version : 2.0 646 2015-07-20T18:51:33
 CCS API Version : 3.0 1306 2015-08-11T15:41:15
 Repository namespace : jjregistry
 Containers limit : Unlimited
 Containers usage : 1
 Containers running : 1
 CPU limit (cores) : Unlimited
 CPU usage (cores) : 4
 Memory limit (MB) : 2048
 Memory usage (MB) : 256
 Floating IPs limit : 2
 Floating IPs allocated : 1
 Floating IPs bound : 1
 LOGMET setup failed with return code 2
 Users namespace is jjregistry
 The desired image repository name will be registry.ng.bluemix.net/jjregistry/tle_nodejs:6
© 2014 IBM Corporation
Build Docker Image
32
 Initialization complete
 Number of images: 0 and Image limit: 5
 The number of images are less than the image limit
 Init runtime of 0m 47s
 Starting build script
 No unit tests cases have been checked in
 Building registry.ng.bluemix.net/jjregistry/tle_nodejs:6
 zipped tar size: 1221307
 Posting 1221307 bytes... It may take a while...
 Step 0 : FROM registry.ng.bluemix.net/ibmnode
 ---> 8f962f6afc9a
 Step 1 : MAINTAINER Joseph Chang "changhs@tw.ibm.com"
 ---> Running in de6d557e0124
 ---> 3617945c3b59
 Removing intermediate container de6d557e0124
 Step 2 : ADD package.json /app/package.json
 ---> c4561d03bc9c
 Removing intermediate container 47dc78795a53
 Step 3 : RUN cd /app && npm install
 ---> Running in 6c3d1d3313e6
 npm WARN package.json NodejsStarterApp@0.0.1 No README data
 cfenv@1.0.0 node_modules/cfenv
 express@4.12.4 node_modules/express
© 2014 IBM Corporation
Build Docker Image
33
 ---> 260391a99b7c
 Removing intermediate container 6c3d1d3313e6
 Step 4 : ADD app.js /app/app.js
 ---> e35785ccf97d
 Removing intermediate container 0dc0dbe21815
 Step 5 : COPY public /app/public
 ---> fd9c9f0aa7f1
 Removing intermediate container da63175d18d2
 Step 6 : ENV WEB_PORT 80
 ---> Running in 95c7d5e28cf8
 ---> a99c74aedc13
 Removing intermediate container 95c7d5e28cf8
 Step 7 : EXPOSE 80
 ---> Running in f8fe1b423788
 ---> f68b44c65390
 Removing intermediate container f8fe1b423788
 Step 8 : CMD node /app/app.js
 ---> Running in 2990e0f0b613
 ---> e83417fad8ff
 Removing intermediate container 2990e0f0b613
 Successfully built e83417fad8ff
 The push refers to a repository [registry.ng.bluemix.net/jjregistry/tle_nodejs] (len: 1)
 Sending image list
 Pushing repository registry.ng.bluemix.net/jjregistry/tle_nodejs (1 tags)
© 2014 IBM Corporation
Build Docker Image
34
 Image 83e4dde6b9cf already pushed, skipping
 Image b670fb0c7ecd already pushed, skipping
 Image 29460ac93442 already pushed, skipping
 Image d2a0ecffe6fa already pushed, skipping
 Image 770bd0523a4b already pushed, skipping
 Image bfad8ba883e4 already pushed, skipping
 Image 5ed9589ea02f already pushed, skipping
 Image 416009f52495 already pushed, skipping
 Image 21676a84c1cc already pushed, skipping
 Image 5c1479ef231c already pushed, skipping
 Image 85e53b6dde50 already pushed, skipping
 Image 5caa6af8b7bc already pushed, skipping
 Image 4b9233194516 already pushed, skipping
 Image eda651c947e4 already pushed, skipping
 Image 8f962f6afc9a already pushed, skipping
 Container build of registry.ng.bluemix.net/jjregistry/tle_nodejs:6 was successful
 To send notifications, please set SLACK_WEBHOOK_PATH or HIP_CHAT_TOKEN in the environment
 Uploading artifacts ...
 UPLOAD SUCCESSFUL
 Total time: 1 seconds
 Finished: SUCCESS
© 2014 IBM Corporation
Trouble shooting
35
If the build quickly finish,
but the image is not
created. And the “Deploy
to” is no space…
Try ….Change the
space, Uncheck the
“Use cached
layers”.
© 2014 IBM Corporation
View Docker Image in Bluemix Catagory
36
Login in to Bluemix and Switch to Catalog.
Surprise!!
Your docker image is
shown in the Catalog
now.
© 2014 IBM Corporation
Run Container
37
The container is
successfully
deployed.
© 2014 IBM Corporation
Manually create container from image
38
By clicking the tle_nodejs icon in the catalog, you can launch this
form to create a new container
© 2014 IBM Corporation
Run Container
39
The application is
running on Bluemix
Docker Container
now.
© 2014 IBM Corporation40
You can also build Docker Image from local then push it to Bluemix Catalog
Bluemix
Desktop
Edit
Application
Source Code
Create
Dockerfile
Build
Docker Image
Run
Docker
Container
vi app.js
vi Dockerfile docker build docker run
Create
Dockerfile
Commit
change
Build
Docker Image
Publish To
Docker
Registry
Run
Docker
Container
Edit
Application
Source Code
Web Editor Web Editor Web Git Auto Build
Bluemix
Catalog
Manual Deploy
Create
Dockerfile
Commit
change
Build
Docker Image
Publish To
Docker
Registry
Run
Docker
Container
docker push
docker pull
© 2014 IBM Corporation
Thank you
41
Take me to Bluemix
Click Here

Create docker image with bluemix dev ops

  • 1.
    © 2014 IBMCorporation Create Docker Image with Bluemix DevOps Joseph Chang Senior IT Specialist IBM Cloud Group
  • 2.
    © 2014 IBMCorporation2 Take me to Bluemix Click Here If you are new to Bluemix Docker Container, please start with the links: https://www.ng.bluemix.net/docs/containers/container_index.html https://www.ng.bluemix.net/docs/containers/container_optional.html
  • 3.
    © 2014 IBMCorporation3 Lifecycle of DevOps with Bluemix Docker Create Dockerfile Commit change Build Docker Image Publish To Docker Registry Run Docker Container Edit Application Source code Web Editor Web Editor Web Git Auto Build Bluemix Catalog Manual Deploy Create Dockerfile Commit change Build Docker Image Publish To Docker Registry Run Docker Container
  • 4.
    © 2014 IBMCorporation Edit Application Source Code In order to get a sample web application with source code in JazzHub, I decide to “borrow” the sample from Bluemix Node.js (Cloud Foundry) Runtime. So…. 4 Let’s start from create a .js runtime. Create a Node.js runtime.
  • 5.
    © 2014 IBMCorporation Edit Application Source Code  We no longer this runtime . We just need the source code of this sample to build new Docker Image. Let’s go to the Web IDE to see the source code. 5 Create the GIT project.
  • 6.
    © 2014 IBMCorporation Edit Application Source Code  Now we get the sample application in Git. 6
  • 7.
    © 2014 IBMCorporation Edit Application Source Code  To move out of CF, the app.js need to be modified. 7 Line 13: remove it Line 22: replaced with hardcode port number, url
  • 8.
    © 2014 IBMCorporation Edit Application Source Code 8  Here is the app.js after modified..
  • 9.
    © 2014 IBMCorporation Create Dockerfile 9 Right click here to get popup menu. Click on the New->File, name it as Dockerfile
  • 10.
    © 2014 IBMCorporation Create Dockerfile 10 You should see the Dockerfile in the list. Let’s start edit the content.
  • 11.
    © 2014 IBMCorporation Create Dockerfile 11  Here is the sample docker file for running Node.js on port 80 in the container. Line 2: We user the ibmnode image as base image Line 6- Line 7: Move the package.json to docker image then run npm install Line 8- Line 9: Copy app.js and all files in /public to image Line 10-Line 11: expose port 80 Line 14: start app.js
  • 12.
    © 2014 IBMCorporation Modify Build & Deploy Configuration 12 That’s all the code need to be modified. Now we need to modify the Build & Deploy Configuration for build & run Docker image. Click Build and Deploy Button on up right side.
  • 13.
    © 2014 IBMCorporation Modify Build Configuration 13  Click on the up right icon of Build Stage. Then click Configure Stage. Click here to continue.
  • 14.
    © 2014 IBMCorporation Modify Build Configuration 14  Let’s change the Build type.. Select IBM Container Service as Build Type.
  • 15.
    © 2014 IBMCorporation Modify Build Configuration 15 Fill in Organization, Space, and Image name Here is the Dockimage build script. Normally you don’t need to modify it. Uncheck this The image name must be in Lower Case Re-Select the space.
  • 16.
    © 2014 IBMCorporation Modify Build Configuration 16 Let’s take look at the build script. #!/bin/bash # The following colors have been defined to help with presentation of logs: green, red, label_color, no_color. log_and_echo "$LABEL" "Starting build script" # The IBM Container Service CLI (ice), Git client (git), IDS Inventory CLI (ids-inv) and Python 2.7.3 (python) have been installed. # Based on the organization and space selected in the Job credentials are in place for both IBM Container Service and IBM Bluemix ##################### # Run unit tests # ##################### log_and_echo "$LABEL" "No unit tests cases have been checked in" ###################################### # Build Container via Dockerfile # ###################################### # REGISTRY_URL=${CCS_REGISTRY_HOST}/${NAMESPACE} # FULL_REPOSITORY_NAME=${REGISTRY_URL}/${IMAGE_NAME}:${APPLICATION_VERSION} # If you wish to receive slack notifications, set SLACK_WEBHOOK_PATH as a property on the stage. if [ -f Dockerfile ]; then log_and_echo "$LABEL" "Building ${FULL_REPOSITORY_NAME}" ${EXT_DIR}/utilities/sendMessage.sh -l info -m "New container build requested for ${FULL_REPOSITORY_NAME}" # build image BUILD_COMMAND="" if [ "${USE_CACHED_LAYERS}" == "true" ]; then BUILD_COMMAND="build --pull --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}" ice_retry ${BUILD_COMMAND} RESULT=$? else BUILD_COMMAND="build --no-cache --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}" ice_retry ${BUILD_COMMAND} RESULT=$? fi
  • 17.
    © 2014 IBMCorporation Modify Build Configuration 17 Let’s take look at the build script. (Continue) if [ $RESULT -ne 0 ]; then log_and_echo "$ERROR" "Error building image" ice info ice images ${EXT_DIR}/print_help.sh ${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Container build of ${FULL_REPOSITORY_NAME} failed. $(get_error_info)" exit 1 else log_and_echo "$SUCCESSFUL" "Container build of ${FULL_REPOSITORY_NAME} was successful" ${EXT_DIR}/utilities/sendMessage.sh -l good -m "Container build of ${FULL_REPOSITORY_NAME} was successful" fi else log_and_echo "$ERROR" "Dockerfile not found in project" ${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Failed to get Dockerfile. $(get_error_info)" exit 1 fi ###################################################################################### # Copy any artifacts that will be needed for deployment and testing to $WORKSPACE # ###################################################################################### echo "IMAGE_NAME=${FULL_REPOSITORY_NAME}" >> $ARCHIVE_DIR/build.properties
  • 18.
    © 2014 IBMCorporation Modify Build Configuration 18 Click Save to Continue
  • 19.
    © 2014 IBMCorporation Modify Deploy Configuration 19 Click here to modify the Configuration of Deploy Stage.
  • 20.
    © 2014 IBMCorporation Modify Deploy Configuration 20 Select IBM Containers on Bluemix as Deployer Type
  • 21.
    © 2014 IBMCorporation Modify Deploy Configuration 21 Select the Organization, Space….
  • 22.
    © 2014 IBMCorporation Modify Deploy Configuration 22 Let’s take look at the deploy script. #!/bin/bash # The following are some example deployment scripts. Use these as is or fork them and include your updates here: echo -e "${label_color}Starting deployment script${no_color}" # To view/fork this script goto: https://github.com/Osthanes/deployscripts # git_retry will retry git calls to prevent pipeline failure on temporary github problems # the code can be found in git_util.sh at https://github.com/Osthanes/container_deployer git_retry clone https://github.com/Osthanes/deployscripts.git deployscripts # You can deploy your Image as either a single Container or as a Container # Group. A Container Group deploys a number of containers to enhance # scalability or reliability. By default we will deploy as a single # container. To switch to a group deploy, comment out the line below # containing deploycontainer.sh and uncomment the line for deploygroup.sh # Deploy with containers: # Optional environment properties (can be set directly in this script, or defined as environment properties): # NAME Value Description # ============= ========= ============== # BIND_TO String Specify a Bluemix application name that whose bound services you wish to make available to the container. By default this is not set. # CONTAINER_SIZE String Specify container size: pico (64), nano (128), micro (256), tiny (512), small (1024), medium (2048), # large (4096), x-large (8192), 2x-large (16384). # Default is micro (256). # CONCURRENT_VERSIONS Number Number of versions of this container to leave active. # Default is 1 # /bin/bash deployscripts/deploycontainer.sh
  • 23.
    © 2014 IBMCorporation Modify Deploy Configuration 23 Let’s take look at the deploy script. (Continue) # Deploy Container Group: # Optional environment properties (can be set directly in this script, or defined as environment properties): # NAME Value Description # ============= ========= ============== # ROUTE_HOSTNAME String Specify the Hostname for the Cloud Foundry Route you wish to assign to this container group. By default this is not set. # ROUTE_DOMAIN String Specify domain name for the Cloud Foundry Route you wish to assign to this container group. By default this is not set. # BIND_TO String Specify a Bluemix application name that whose bound services you wish to make available to the container. By default this is not set. # DESIRED_INSTANCES: Number Specify the number of instances in the group. Default value is 1. # AUTO_RECOVERY: Boolean Set auto-recovery to true/false. Default value is false. # Default is false. # CONTAINER_SIZE String Specify container size: pico (64), nano (128), micro (256), tiny (512), small (1024), medium (2048), # large (4096), x-large (8192), 2x-large (16384). # Default is micro (256). # CONCURRENT_VERSIONS Number Number of versions of this group to leave active. # Default is 1 # IF YOU WANT CONTAINER GROUPS .. uncomment the next line, and comment out the previous deployment line (/bin/bash deployscripts/deploygroup.sh) #/bin/bash deployscripts/deploygroup.sh RESULT=$? # source the deploy property file if [ -f "${DEPLOY_PROPERTY_FILE}" ]; then source "$DEPLOY_PROPERTY_FILE" fi ######################### # Environment DETAILS # ######################### # The environment has been setup. # The Cloud Foundry CLI (cf), IBM Container Service CLI (ice), Git client (git), IDS Inventory CLI (ids-inv) and Python 2.7.3 (python) have been installed. # Based on the organization and space selected in the Job credentials are in place for both IBM Container Service and IBM Bluemix # The following colors have been defined to help with presentation of logs: green, red, label_color, no_color. if [ $RESULT -ne 0 ]; then echo -e "${red}Executed failed or had warnings ${no_color}" ${EXT_DIR}/print_help.sh exit $RESULT fi echo -e "${green}Execution complete${no_label}" If you want to deploy Container Group, you need to uncomment this line.
  • 24.
    © 2014 IBMCorporation Modify Deploy Configuration 24 Fill in the Name of the instance then click Save.
  • 25.
    © 2014 IBMCorporation Commit Change 25 Go back to EDIT CODE page then click GIT respository Let’s back to EDIT CODE perspective.EDIT CODE
  • 26.
    © 2014 IBMCorporation Commit Change 26 1. Select all of the changes. 2. Give a comment. 3. Click Confirm .4. Push the changes to build pipeline
  • 27.
    © 2014 IBMCorporation Build Docker Image 27 Switch to EDIT CODE perspective to see the result.Build & Deploy The docker image have been created.
  • 28.
    © 2014 IBMCorporation Build Docker Image 28 Let’s have a look at what happens during the build.  Started by user joseph  Building remotely on jenkins-build-slave-b9d10a965120 (.*Build) in workspace /home/jenkins/workspace/e6059a87-3337-a67b-64ea-4bf1b5df961f/7dc9942f-7e3b-47bb-9cdd- 665e50e37d55  Cloning the remote Git repository  Cloning repository https://hub.jazz.net/git/joseph/helloWebApp  Fetching upstream changes from https://hub.jazz.net/git/joseph/helloWebApp  using .gitcredentials to set credentials  Checking out Revision 918917ba36eb1bff5eee958e86cb14d6c1eee850 (detached)  [7dc9942f-7e3b-47bb-9cdd-665e50e37d55] $ /bin/bash /tmp/hudson1082149903417757598.sh  + cat /etc/lsb-release /etc/os-release  DISTRIB_ID=Ubuntu  DISTRIB_RELEASE=14.04  DISTRIB_CODENAME=trusty  DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"  NAME="Ubuntu"  VERSION="14.04.2 LTS, Trusty Tahr"  ID=ubuntu  ID_LIKE=debian  PRETTY_NAME="Ubuntu 14.04.2 LTS"  VERSION_ID="14.04"  HOME_URL="http://www.ubuntu.com/"  SUPPORT_URL="http://help.ubuntu.com/"  BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"  + source _script.sh
  • 29.
    © 2014 IBMCorporation Build Docker Image 29  ++ set +x  git clone https://github.com/Osthanes/utilities.git utilities  Cloning into 'utilities'...  APPLICATION_VERSION: 6  Archiving to /home/jenkins/workspace/e6059a87-3337-a67b-64ea-4bf1b5df961f/7dc9942f-7e3b-47bb-9cdd-665e50e37d55/.cs_archive  Installing IBM Container Service CLI  Installing Python 2.7  Python 2.7.6  Successfully installed IBM Container Service CLI  Installing Cloud Foundry CLI  Successfully installed Cloud Foundry CLI  Bluemix host is 'api.ng.bluemix.net'  Bluemix target is 'prod'  Date/Time : 2015-08-14 03:41:20.476922  Debug mode : False  CCS host/url : https://containers-api.ng.bluemix.net/v3/containers  Registry host : registry.ng.bluemix.net  Bluemix api host/url : api.ng.bluemix.net  Bluemix Org : changhs@tw.ibm.com (1f6d3957-c6c6-4804-a8c2-5c7b5d382387)  Bluemix Space : 0-sandbox (3fb3e792-dfb1-4fc2-83ab-62435218d59a)  ICE CLI Version : 2.0 646 2015-07-20T18:51:33  CCS API Version : 3.0 1306 2015-08-11T15:41:15  Repository namespace : jjregistry  Containers limit : Unlimited
  • 30.
    © 2014 IBMCorporation Build Docker Image 30  Containers usage : 1  Containers running : 1  CPU limit (cores) : Unlimited  CPU usage (cores) : 4  Memory limit (MB) : 2048  Memory usage (MB) : 256  Floating IPs limit : 2  Floating IPs allocated : 1  Floating IPs bound : 1  Image Id Created Image Name  97513e56aaa70b9daf1627734f18efcd7023 Aug 14 02:03:35 2015 registry.ng.bluemix.net/ibm-mobilefirst-starter:latest  97513e56aaa70b9daf1627734f18efcd7023 Aug 14 02:02:14 2015 registry.ng.bluemix.net/ibm-mobilefirst-starter:7.1.0  68e01b620447d7468f6b098ea0e6023257f6 Aug 6 03:31:53 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:10  777c0f64f1215d45272c9c301721e19689ee Aug 4 17:19:45 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:9  c0ace5c9ec7cd7f7c18a85fa841af99a79f9 Aug 1 16:31:19 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:8  de3ab2d47694b8482d1ca10d68e802d5ccd5 Aug 1 13:11:06 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:7  9a00bc0f-fbbf-4b48-9831-6271db8b8603 Aug 1 12:52:14 2015 registry.ng.bluemix.net/jjregistry/demo-nodejs:6  2209a9732f35a906491005f87c130bb73e26 Jul 23 15:08:49 2015 registry.ng.bluemix.net/ibmliberty:latest  8f962f6afc9a30b646b9347ecb7f458bf75b Jul 23 15:05:40 2015 registry.ng.bluemix.net/ibmnode:latest  17cd72f2667163c517253c0127425677d20d Jul 9 03:54:37 2015 registry.ng.bluemix.net/jjregistry/etherpad_bluemix:latest  Successfully accessed into IBM Container Service using credentials passed from IBM DevOps Services
  • 31.
    © 2014 IBMCorporation Build Docker Image 31  Successfully accessed into IBM Containers Service  Date/Time : 2015-08-14 03:41:26.812804  Debug mode : False  CCS host/url : https://containers-api.ng.bluemix.net/v3/containers  Registry host : registry.ng.bluemix.net  Bluemix api host/url : api.ng.bluemix.net  Bluemix Org : changhs@tw.ibm.com (1f6d3957-c6c6-4804-a8c2-5c7b5d382387)  Bluemix Space : 0-sandbox (3fb3e792-dfb1-4fc2-83ab-62435218d59a)  ICE CLI Version : 2.0 646 2015-07-20T18:51:33  CCS API Version : 3.0 1306 2015-08-11T15:41:15  Repository namespace : jjregistry  Containers limit : Unlimited  Containers usage : 1  Containers running : 1  CPU limit (cores) : Unlimited  CPU usage (cores) : 4  Memory limit (MB) : 2048  Memory usage (MB) : 256  Floating IPs limit : 2  Floating IPs allocated : 1  Floating IPs bound : 1  LOGMET setup failed with return code 2  Users namespace is jjregistry  The desired image repository name will be registry.ng.bluemix.net/jjregistry/tle_nodejs:6
  • 32.
    © 2014 IBMCorporation Build Docker Image 32  Initialization complete  Number of images: 0 and Image limit: 5  The number of images are less than the image limit  Init runtime of 0m 47s  Starting build script  No unit tests cases have been checked in  Building registry.ng.bluemix.net/jjregistry/tle_nodejs:6  zipped tar size: 1221307  Posting 1221307 bytes... It may take a while...  Step 0 : FROM registry.ng.bluemix.net/ibmnode  ---> 8f962f6afc9a  Step 1 : MAINTAINER Joseph Chang "changhs@tw.ibm.com"  ---> Running in de6d557e0124  ---> 3617945c3b59  Removing intermediate container de6d557e0124  Step 2 : ADD package.json /app/package.json  ---> c4561d03bc9c  Removing intermediate container 47dc78795a53  Step 3 : RUN cd /app && npm install  ---> Running in 6c3d1d3313e6  npm WARN package.json NodejsStarterApp@0.0.1 No README data  cfenv@1.0.0 node_modules/cfenv  express@4.12.4 node_modules/express
  • 33.
    © 2014 IBMCorporation Build Docker Image 33  ---> 260391a99b7c  Removing intermediate container 6c3d1d3313e6  Step 4 : ADD app.js /app/app.js  ---> e35785ccf97d  Removing intermediate container 0dc0dbe21815  Step 5 : COPY public /app/public  ---> fd9c9f0aa7f1  Removing intermediate container da63175d18d2  Step 6 : ENV WEB_PORT 80  ---> Running in 95c7d5e28cf8  ---> a99c74aedc13  Removing intermediate container 95c7d5e28cf8  Step 7 : EXPOSE 80  ---> Running in f8fe1b423788  ---> f68b44c65390  Removing intermediate container f8fe1b423788  Step 8 : CMD node /app/app.js  ---> Running in 2990e0f0b613  ---> e83417fad8ff  Removing intermediate container 2990e0f0b613  Successfully built e83417fad8ff  The push refers to a repository [registry.ng.bluemix.net/jjregistry/tle_nodejs] (len: 1)  Sending image list  Pushing repository registry.ng.bluemix.net/jjregistry/tle_nodejs (1 tags)
  • 34.
    © 2014 IBMCorporation Build Docker Image 34  Image 83e4dde6b9cf already pushed, skipping  Image b670fb0c7ecd already pushed, skipping  Image 29460ac93442 already pushed, skipping  Image d2a0ecffe6fa already pushed, skipping  Image 770bd0523a4b already pushed, skipping  Image bfad8ba883e4 already pushed, skipping  Image 5ed9589ea02f already pushed, skipping  Image 416009f52495 already pushed, skipping  Image 21676a84c1cc already pushed, skipping  Image 5c1479ef231c already pushed, skipping  Image 85e53b6dde50 already pushed, skipping  Image 5caa6af8b7bc already pushed, skipping  Image 4b9233194516 already pushed, skipping  Image eda651c947e4 already pushed, skipping  Image 8f962f6afc9a already pushed, skipping  Container build of registry.ng.bluemix.net/jjregistry/tle_nodejs:6 was successful  To send notifications, please set SLACK_WEBHOOK_PATH or HIP_CHAT_TOKEN in the environment  Uploading artifacts ...  UPLOAD SUCCESSFUL  Total time: 1 seconds  Finished: SUCCESS
  • 35.
    © 2014 IBMCorporation Trouble shooting 35 If the build quickly finish, but the image is not created. And the “Deploy to” is no space… Try ….Change the space, Uncheck the “Use cached layers”.
  • 36.
    © 2014 IBMCorporation View Docker Image in Bluemix Catagory 36 Login in to Bluemix and Switch to Catalog. Surprise!! Your docker image is shown in the Catalog now.
  • 37.
    © 2014 IBMCorporation Run Container 37 The container is successfully deployed.
  • 38.
    © 2014 IBMCorporation Manually create container from image 38 By clicking the tle_nodejs icon in the catalog, you can launch this form to create a new container
  • 39.
    © 2014 IBMCorporation Run Container 39 The application is running on Bluemix Docker Container now.
  • 40.
    © 2014 IBMCorporation40 You can also build Docker Image from local then push it to Bluemix Catalog Bluemix Desktop Edit Application Source Code Create Dockerfile Build Docker Image Run Docker Container vi app.js vi Dockerfile docker build docker run Create Dockerfile Commit change Build Docker Image Publish To Docker Registry Run Docker Container Edit Application Source Code Web Editor Web Editor Web Git Auto Build Bluemix Catalog Manual Deploy Create Dockerfile Commit change Build Docker Image Publish To Docker Registry Run Docker Container docker push docker pull
  • 41.
    © 2014 IBMCorporation Thank you 41 Take me to Bluemix Click Here

Editor's Notes

  • #12 # My Dockerfile FROM registry.ng.bluemix.net/ibmnode MAINTAINER Joseph Chang "changhs@tw.ibm.com" # Install the application ADD package.json /app/package.json RUN cd /app && npm install ADD app.js /app/app.js COPY public /app/public ENV WEB_PORT 80 EXPOSE 80 #Define command to run the applicaiton the the container starts CMD ["node","/app/app.js"]