Delivery Pipeline deploying Node app to IBM Container binding to Bluemix Service
If you have stumbled on this post , I believe you are fairly acquainted with Docker and IBM Containers on Bluemix. The scenario which I am penning here is showcase how to build / deploy application on IBM Containers in Bluemix through delivery pipeline and have that communicate to Bluemix Services.
Now if you are familiar with Bluemix – you know that Bluemix comes with Boiler Plates which are basically applications (along with code) which can be deployed to Bluemix cloud foundry runtimes. Instead of writing whole new app , I shall re-use the same app and show deployment to IBM Containers and connecting to Bluemix Service. I decide to go ahead with Node.js Cloudant Web Starter where I shall deploy the same app to IBM Node Container and have it communicate with Bluemix Cloudant Service.
1. From Bluemix dashboard create a web application using ‘Node.js Cloudant Web Starter’ . I named mine ‘samplenodeCFapp’. I have my CF app running
2. To get source code of this app, I click on ‘Add ToolChain’ ( ToolChain is experimental as this stage , and as Beta User I have access to it , for others it would be ‘Add Git’ button). ToolChain is really a cool capability provided in Bluemix which basically plugs various Devops tools together for project requirements – at this stage Toolchain has handful of features, which are expected to grow.We shall explore ToolChains maybe later in another blog entry.
So having said that my ToolChain is created as below.
The fascinating part is that at the click of button I have the whole DevOps toolchain plugged and wired-ready for use : The source-code of the application setupin SCM repository (GitHub) , Issue tracking setup , Web based Eclipse Orion IDE for coding online , and Delivery Pipleline which lets you Build and Deploy applications. Neat ain’t it ?
Let’s go and check out Delivery Pipeline – we see that it is created as below ( this basically does deployment to cf, what we are interested now is building the same for IBM Containers )
So what we need to add is abilty to run Docker Build which will create Docker Image and then Docker Deploy which would depoy the Container.
Build Docker :
I click on Add Stage – name my stage ‘Build Docker‘ and in Input tab select Input Type – ‘SCM repository‘ ,and Trigger as ‘Run jobs whenever change is pushed to git‘.
In the Jobs tab – add Build job and select Build Type as ‘IBM Container Service‘, I name my image ‘samplenodedockerapp‘ and in Ports add 80, 443,3000 . I ensure the right Target /Organisation/Space where I want to deploy my container are selected.
Deploy Docker
I click on Add Stage – name my stage ‘Deploy Docker‘
Input Tab select Input type as ‘Built Artifacts‘, stage as ‘Build Docker‘ ( docker stage created earlier) , Job as ‘Build’ and Stage Trigger as ‘Run Jobs when previous stage is completed‘
In the Jobs Tab – select Deployer Type as ‘IBM Containers on Bluemix‘ , select name ‘samplenodecontainer‘ , ports ‘80,443, 3000‘ . I ensure the right Target /Organisation/Space where I want to deploy my container are selected.
Environment Tab
In the Environment tab , we can specify which application we want to Bind to and size of container .
Inorder to bind services to Container , one can bind services to dummy app – the Service credentials get stored in VCAP_SERVICES.
Since the services which I want to bind to this container are bound to app ‘samplenodeCFapp’, I specify the same .
The app which we write basically parses the VCAP_SERVICES to get information on the services.
I have done all the required configurations and the delivery pipeline is configured as below :
Now one key piece which must be there in place for Build Docker stage is the Dockerfile which is text document that contains all the commands a user could call on the command line to assemble an image.
I go back to my ToolChain and open the Web Editor and add Dockerfile with content as below
FROM registry.ng.bluemix.net/ibmnode:latest ADD . /node WORKDIR /node RUN npm install EXPOSE 443 EXPOSE 80 EXPOSE 3000 ENTRYPOINT ["node", "/node/app.js"]
On Bluemix dashboard we have default IBM Container like ibmnode – we shall deploy our sample Node.js application to this Container. So in my Dockerfile what I am doing is pulling the default node Image, copying my content to /node folder and them mentioning that command to run as Entrypoint. I also mention the ports to expose .
My file is as below
Commit and Push this file using by clicking on ‘git’ icon on left sidebar. The moment that is done , one can see that delivery pipeline is activated and is running
( One can ignore the first two stages – those are deploying a CF app which were part of boiler plate)
Once Build Docker stage passes – one can go to Bluemix Dashboard and click on ‘Start Containers’ to check that Image is now present ..
Once the Deploy Docker stage in the Delivery Pipeline completes , it creates an instance in the space specified :
Open your browser and enter link http://<public ip>:3000 and your Node application is now accessible on IBM Container .
So in this article we saw how we can deploy Node.js app to IBM Container and have it communicate to Cloudant DB Service in Bluemix.
Oh my goodness! Incredible article dude! Many thanks.