This article discusses detailed steps to building and deploying docker image to IBM container using bluemix delivery pipeline and further binding these IBM container(s) to existing Bluemix services to leverage them in docker based application. This will help in reducing the deployment time of docker images to bluemix and fasten application development time.
Setting up Workspace for DevOps using IBM Jazz or GitHub
Login into JazzHub. The URL is https://hub.jazz.net/ if you do not have an id you can request for one.
Create a new project
Once you logged into the accound create a project by selecting the respective option as shown below
Give the name to the project and select Create a new repository option.
Once you select Create a new repository it will further flash for options as shown below. Select Create a Git repo on GitHub to create a Git repo on your public account. Once can also proceed with an option of Create a Git repo on Bluemix. The first option will ask you to login into public GitHub account (you must have an id in prior).
Authorize your application in GitHub
Now login into the GitHub account and authorise your application. This will give access to delivery pipeline in Bluemix your GitHub resources.
This will login into the Git hub repository and allow you to authorise.
Once authorized it will create a Git url and ask for selecting Region, Organization and Space as shown below.
Select appropriate options as shown above and press Create button. This will create a workspace where in one can put in their artifacts.
We are now ready with workspace which could be used to upload the docker related artifacts. Click on Edit Code and pull in all the related artifacts into the workspace. In our case it is a Dockerfile and a JDBC driver jar file.
Commit the changes by selecting brach icon on the left, so that these are available to our delivery pipeline.
Once committed successfully, now push and synchronize changes in master branch.
Select Build and Deploy from the top right corner to create a delivery pipeline.
Running Build Pipeline
Once the above changes are done and commited successfully we are now ready to test Build pipeline. After manually Run the build, goto logs to track the log messages for successful or unsuccessful build.
The build process starts with cloning the git repositiry which was created at the start where in Dockerfile is uploaded.
Once the process is completed one could see the SUCCESS message as below.
Now we can check whether Docker Image has been created or not. For this login to Bluemix console and Containers > Start Container and there you can see wildfly9 image successfully created.
We can now test the Image by instantiating it. To do this click the Image and fill in the necessary details.
Adding Delivery Pipeline- Build
Now we are done with setting up workspace to keep our artifacts. In this section we will setup Build pipeline which will help us build the docker image.
Add a new stage
Edit the content as shown below to map this stage to Docker build process
Build Configuration Details
Note: Make sure that Dockerfile points to correct region url or elase dockerbuild will fail.
Creating Bluemix Services Bridge
In this section we will be creating a services bridge for all the services which we need to add to our IBM Container to be called from our docker Implementation. To bind existing services to docker Instance we will first creat a bridge application which in current case is a web application and this application will be associated with multiple other applications which we want to use with docker container. In this article we will create a web application named weatherapp and associate this app with all the services which we want to leverage in our docker container.
For this we will create an application named watherapp which is primarily a NodeJS application binded to weather service. We will be further binding other services which we need to bind to our docker container.
Below are the list of services binded to this application
Now we are ready with bridge application we will create a new delivery pipeline which will create a docker container instance of previously created Image.
Binding existing services to Docker Instance through bridge
To create a docker Instance from docker build one need to create a new stage in pipeline to auto deploy the docker Image. Repeat the above steps (Build Stage) to add the deploy stage to delivery pipeline. This will be out second stage after docker build stage. For this article we will be running this stage manually, however this could be automatically run after build stage is completed. For the Input stage enter the below details.
Note: Services could be binded to IBM Container only at deploy stage.
In the Jobs tab select the below details.
Enter the below deploy configuration
In environment properties we will specify the details of the application to be binded.
We will name the stage as DockerImageDeploy
We are now ready to run this stage as previous stage is already successfully run and generated a wildfly9 docker Image which this stage will help us instantiate the previously built Image to a usable container. Run the stage manually as we did previously and validate the logs as below. SUCCESS message in the end indicates successfully building of instance.
At the end of the execution one could see stages as below.
One can see the docker instance built on the dashboard
When we click on the Image we can see the binded services which we incorporated through bridged application
With the help of IBM Bluemix devops delivery pipeline one can not only build and deploy docker containers Images and Instances but can bind essential usable services with these containers to be used later to enhance the application capabilities.