Using Containers With Bluemix DevOps Services

Introduction

This tutorial will demonstrate some of the integrated capabilities found in IBM Bluemix and IBM Bluemix DevOps Services (IDS).

Bluemix now includes a new beta service to host Docker container-based applications. This service allows users to build and deploy their Docker applications completely on the IBM cloud.

Today's tutorial will highlight an agile process to write, build, and deploy Docker applications using DevOps best practices for continuous delivery using an automated pipeline to deliver new application versions faster.

I'll also demonstrate a new web-based way to code that does not require the installation of any development environment, or for that matter, any application besides a browser.

In order to walk through our guide, you will need a Bluemix account that has been previously linked with IDS. I'll show you how.

Build and Deploy an Application Using the IBM Container Service

Log in to Bluemix

1. Using your browser, go to the Bluemix website.

2a. If you don't have an account, please click SIGN UP to register.

IBM BlueMix and DevOps - Sign Up for Bluemix

Then, check your email for the confirmation link and complete your registration. Your username should be the email address you used during registration.

2b. Otherwise, press the LOG IN button located at the top right-hand corner of the page.

IBM BlueMix and DevOps - Bluemix Home Page

3. In the following page, provide the email and password and press the Sign in button.

IBM BlueMix and DevOps - Create IBM ID

4. In the Dashboard page, you should notice that you do not have any Applications created yet.

Log in to IDS

1. Using your browser, open another tab and go to the IDS website.

2. Press the LOG IN button located at the top right-hand corner of the page.

IBM BlueMix and DevOps - DevOps Home Page

3. In the following page, press the Sign In button.

IBM BlueMix and DevOps - Sign In Page for DevOps Requires IBM ID

4. In the IDS landing page, press the EXPLORE tab at the top of the page.

IBM BlueMix and DevOps - Explore IDS

5. In the Explore page, type “ibluemx” in the search bar and press the Enter key.

6. A list of projects will be displayed; select “container-devops”.

IBM BlueMix and DevOps - Project List

Fork the Project

1. Press FORK PROJECT to create a personal copy of the project to work with.

IBM BlueMix and DevOps - container-devops project

2. In the Fork Project window, provide a name for your project and make a note of it.

Note: The deployed application will need to have a unique name, so it would be a good idea to name the project something like “container-devops-<username>”, where <username> is your account's username.

And check the Make it private (not public) checkbox, leave all other items as set, and press the CREATE button.

IBM BlueMix and DevOps - Fork Project Popup

Inspect the Project Code

1. On the new project page, you should receive the following message “Congratulations! You have successfully created your new project.”

Let's look at the project source code by first pressing the EDIT CODE button.

IBM BlueMix and DevOps - Your copy of container-devops

2. In the left-hand tree view, select the file named “Dockerfile”. The file contents will display in the main editor window.

This will give you an opportunity to see the instructions that will be used to create our Docker container.

IBM BlueMix and DevOps - Instructions for Docker Container

3. In the left-hand tree view, select the “app. js” file. The file contents will display in the main editor window.

This will give you an opportunity to see the code for the simple application that will run inside the Docker container.

Note: On line 22, the application will output the following: “Hello Docker Pipeline! version 1.0”.

IBM BlueMix and DevOps - appjs file in viewer

Configure the DevOps Pipeline: Build Stage

1. Click on the BUILD & DEPLOY button.

IBM BlueMix and DevOps - Build and Deploy Button

2. On the Build & Deploy Pipeline page, press the + ADD STAGE link.

IBM BlueMix and DevOps - Build and Deploy Pipeline start

3. In the reloaded page, rename the stage name from the default “MyStage” to “Build” and press the JOBS tab in the window.

IBM BlueMix and DevOps - Rename the Stage to Build

4. In the JOBS tab, click on ADD JOB and select Build.

5. Set the Builder Type to IBM Container Service on Bluemix, set the Image Name to ibluenode and press the SAVE button to continue.

IBM BlueMix and DevOps - Build Configuration Page

Configure the DevOps Pipeline: Deploy Stage

1. Back on the Build & Deploy Pipeline page, press the + ADD STAGE link.

IBM BlueMix and DevOps - Add a Stage

2. In the reloaded page, rename the stage name from the default “MyStage” to “Deploy” and press the JOBS tab in the window.

IBM BlueMix and DevOps - Rename the Stage to Deploy

4. In the JOBS tab, click on ADD JOB and select Deploy.

5. On the Stage Configuration page, set the Deployer Type to IBM Container Service on Bluemix.

Press the SAVE button to continue.

IBM BlueMix and DevOps - Set the Deployer Type Configuration

Run an Initial Build and Deploy

1. To test the pipeline, we will run an initial build. Back on the Pipeline: All Stages page, press on the play arrow (which is a right-hand pointing triangle) at the top of the Build stage.

Note: At any time, you can click on the “View logs and history” link to see detailed messages.

IBM BlueMix and DevOps - Pipeline Stages Build  Deploy

2. The pipeline will automatically progress from Build to Deploy once the Build stage is complete.

Once the Deploy stage is complete, you will see the resulting container under the LAST EXECUTION RESULT in the Deploy stage box.

Click on the IP address located under the LAST EXECUTION RESULT in the Deploy stage box.

IBM BlueMix and DevOps - See IP Address in Deploy Stage

3. This will open a new browser window and show the result of the newly deployed web application, which should read:

Hello Docker Pipeline! Version 1.0

Change the Application Code

1. Press the EDIT CODE button to return to the editor.

IBM BlueMix and DevOps - Edit Code Button

2. Edit the “app. js” file and set the value of “res. send” to “Hello Docker Pipeline! version 2.0”, and save the changes by pressing Control-S (Windows), Command-S (Mac) or pressing File > Save (tablets) in the editor toolbar (not in the browser window).

IBM BlueMix and DevOps - appjs in viewer

Commit the Code to the Git Repository

1. Press the Git repository button at the left of the screen (under the pencil icon).

IBM BlueMix and DevOps - Commit to Git repository

2. In the Working Directory Changes window, press the Select All checkbox, provide some commit text (in my case I added “Increased the version displayed”), and press the Commit button.

IBM BlueMix and DevOps - Commit the code changes

3. Once the changes have been committed, you need to press the SYNC button to synchronize with the master branch.

IBM BlueMix and DevOps - Sync the changes with the master branch

Run a Build and Deploy

1. Press the BUILD & DEPLOY button to return to the Pipeline: All Stages page.

IBM BlueMix and DevOps - Click Build  Deploy

2. You will see that the build has automatically started running based on the synchronization of the change to the repository.

Note: At any time you can click on the “View logs and history” link to see detailed messages.

IBM BlueMix and DevOps - The Stages Build and Deploy

3. The pipeline will progress from Build to Deploy once the Build stage is complete.

Once the Deploy stage is complete, you will see the resulting container under the LAST EXECUTION RESULT header in the Deploy stage box.

Click on the IP address located under the LAST EXECUTION RESULT in the Deploy stage box.

IBM BlueMix and DevOps - Build and Deploy with IP Address

4. This will open a new browser window and show the result of the newly redeployed web application which should read:

Hello Docker Pipeline! Version 2.0

Continue to Iterate on Your Application

You can now extend the application by modifying the app. js file in a new way to render different content, or you can choose to use a completely different Dockerfile, such as one found on Containers and Cloud Foundry Hands-On Labs on GitHub, e.g. PCF-Demo.

Related Links

IBM BlueMix and DevOps -
Tags:

Comments

Related Articles