Taxonomy Icon

DevOps

With the IBM Cloud DevOps service we can create Continuous Development (CD) and Continuous Integration (CI) toolchains to go from source code to a running application in minutes. Toolchains allow us to develop, track, plan and deploy applications in one place, we can access everything we need to build all types of applications.

Learning objectives

In this tutorial we will demonstrate how to create a custom toolchain from scratch to deploy your sample application as a Cloud Foundry application and as a Docker container running on a Kubernetes cluster, both on IBM Cloud.

Prerequisites

We will also be using two GitHub repositories that contain the bare minimum for a simple web app:

Estimated time

This how-to will take approximately 30 minutes to complete. Creating the toolchain will take around 10 minutes and configuring each delivery pipeline will take another 20 minutes.

Steps

Fork the GitHub repositories

To take full advantage of the Continuous Delivery service it is necessary to be the owner of the GitHub repo we intend to use. The easiest way to do this is to fork the repositories we’ll be using. Simply visit each repository mentioned above and click the Fork option on the top right and select an organization where you are the owner.

Build and deploy Cloud Foundry applications with the DevOps service

This portion of the how-to will describe how to: 1) creating a custom toolchain, 2) add tools to the toolchain, and 3) configuring the Delivery Pipeline for a Cloud Foundry application.

Cloud Foundry based toolchain: Create a new custom toolchain

After launching the Continuous Delivery service there are two options: Start with Pipeline and Start with Toolchain, since we’ll be using toolchains, go ahead and click Start with Toolchain.

toolchain

We’re now redirected to a page where several template toolchains are available. We will not be using these, rather we’ll be creating a toolchain from scratch.

  • Scroll to the bottom of the page and click Build your own toolchain under Other Templates.
  • Name the service and click Create.

Cloud Foundry based toolchain: Add tools to the toolchain

Cloud Foundry based toolchain: Add GitHub to the toolchain

We’re now presented with a blank toolchain. Let’s add a few tools that will help us run our application.

  • Click the Add a Tool button on top right corner.
  • Search for “GitHub”.
  • Click the GitHub option, it has a Third Party label.

Note: If this is the first time using this tool, you will need to authorize IBM Cloud to use your GitHub credentials. Click on Authorize and log into Github.

  • For the GitHub server option, leave the default GitHub (https://github.com/) value.
  • For the Repository type option, choose Existing.
  • For the Repository URL option, type in the forked GitHub repo value, for example: https://github.com/ceroloy/sample-express-app.
  • Ensure both the Enable GitHub Issues and Track deployement of code changes options are selected.
  • Click the Create Integration button.

Cloud Foundry based toolchain: Add a Delivery Pipeline to the toolchain

  • Click the Add a Tool button on top right corner.
  • Search for “Delivery Pipeline”.
  • Click the Delivery Pipeline option.
  • Name the pipeline and click Create.

Your toolchain page now should look like this:

complete toolchain

Cloud Foundry based toolchain: Configure the Delivery Pipeline

By clicking on the newly created Delivery Pipeline tool from the previous step we’ll be able to configure it. The Delivery Pipeline is where we will configure the stages of the application’s development lifecycle. We’ll be adding two stages: a “Build” stage and a “Deploy” stage. It is while configuring these stages that we’ll be referencing the application code, the repository we forked earlier, to build and deploy.

Cloud Foundry based toolchain: Add a Build stage

  1. Click the Add Stage button.

  2. Name it Build.

  3. The options for the INPUT tab should be correct by default, but we’ll list them here for completeness:

"Input type": "Git repostory"
"Git repository": "sample-express-app"
"Branch": "master"
  1. Ensure the Run jobs whenever a change is pushed to Git radio button is selected.

  2. Select the JOBS tab

  3. Click Add Job and select Build as the job type.

  4. Select Simple as the Builder type.

  5. Ensure the Stop running this stage if this job fails is selected as well.

  6. Click Save.

We will now be brought back to our Delivery Pipeline.

Cloud Foundry based toolchain: Add a Deploy stage

  1. Click the Add Stage button.
  2. Name it Deploy.

  3. The options for the INPUT tab should be correct by default, but we’ll list them here for completeness:

"Input type": "Build artifacts"
"Stage": "Build"
"Job": Build"
  1. Ensure the Run jobs when previous stage is complete radio button is selected.

  2. Select the JOBS tab

  3. Click Add Job and select Deploy as the job type.

  4. Select Cloud Foundry as the Deployer type.

  5. Select the appropriate IBM Cloud region, organization, and space where application will be deployed.

  6. Name the application sample-express-app.

  7. Ensure the Stop running this stage if this job fails is selected also.

"Deployer type" : "Cloud Foundry"
"Application name": "sample-express-app"
  1. Select the ENVIRONMENT PROPERTIES tab

  2. Add a new property with type text property. Configure it with the following key-value pair:

"CF_APP": "sample-express-app"
  1. Click Save.

    The delivery pipeline should now look like this:

    complete pipeline

  2. Click the Play button on the Build stage to manually trigger a build and watch pipeline automatically start the Deploy stage. After the Deploy stage is completed successfully, you can return to your dashboard and see your application under the Cloud Foundry apps heading.

Build and deploy Docker based applications that run on Kubernetes with the DevOps service

This portion of the how-to will describe how to: 1) add to an existing toolchain, 2) add tools to the toolchain, and 3) configuring the Delivery Pipeline for a Kubernetes cluster.

As mentioned earlier, for this part of the how-to a running Kubernetes cluster on IBM Cloud is required. Once provisioned, create a namespace called sampleapps on your cluster.

Docker and Kubernetes based toolchain: Add to an existing toolchain

You can add a separate toolchain alongside your existing one. This practice is often used in a microservices architecture where each microservice has its own toolchain and delivery pipeline. In this how-to, however, you will simply extend the existing toolchain to create a parallel pipeline to deploy the same app as a Docker container on Kubernetes.

Docker and Kubernetes based toolchain: Add tools to the toolchain

We’ll be using the same tools that we mentioned earlier, so repeat the Add tools to the toolchain section from the first part of this how-to. The only difference between the steps is that we’ll be using the forked version of https://github.com/ceroloy/sample-docker-app instead of the forked version of https://github.com/ceroloy/sample-express-app. Your toolchain page now should look like this:

devops-added

Docker and Kubernetes based toolchain: Configure the Delivery Pipeline

By clicking on the newly created Delivery Pipeline tool from the previous step we’ll be able to configure it. The Delivery Pipeline is where we will configure the stages of the application’s development lifecycle. We’ll be adding two stages: a “Build” stage and a “Deploy” stage. It is while configuring these stages that we’ll be referencing the application code, the repository we forked earlier, to build and deploy.

Docker and Kubernetes based toolchain: Create an IBM Cloud API key

Before configuring the delivery pipeline we will need an IBM Cloud API key to interact with our IBM Cloud Private Container Registry.

  1. Navigate to the Platform API Keys, or in the UI:

  2. Click Manage button on the top right, select Security, and then Platform API Keys.

  3. Create a new key by clicking the Create button.

  4. Enter a name, such as docker-app, enter a description, and click Create.

  5. An obfuscated API key will be generated, select the Show button to view the key. Copy this locally or jot it down.

  6. Click Close.

Now let’s return to the delivery pipeline and just like with the Cloud Foundry application, let’s configure the delivery pipeline with two stages: “Build” and “Deploy”.

Docker and Kubernetes based toolchain: Add a Build stage

  1. Click the Add Stage button.

  2. Name it Build.

  3. The options for the INPUT tab should be correct by default, but we’ll list them here for completeness:

"Input type": "Git repostory"
"Git repository": "sample-docker-app"
"Branch": "master"
  1. Ensure the Run jobs whenever a change is pushed to Git radio button is selected.

  2. Select the JOBS tab

  3. Click Add Job and select Build as the job type.

  4. Select Container Registry as the Builder type.

  5. Under the API key field, add your newly generated API key from the previous section.

  6. Ensure the Container Registry namespace is set to sampleapps that we created earlier.

  7. Update the “Docker image name to sampledocker

  8. Ensure the Stop running this stage if this job fails is selected also.

"Builder type" : "Container Registry"
"API Key": "<Paste the API key here>"
"Container Registry namespace": "sampleapps"
"Docker image name" : "sampledocker"
  1. Click Save.

  2. Click the play button to manually trigger the build stage and click View logs and history to track it’s progess. Similar to creating a Docker image on your local machine, the delivery pipeline will first create a Docker image from the Dockerfile in the repository and push it to the Private Registry. Later, in the deploy stage, it will pull from this image from the registry and run it as a deployement on the provisioned Kubernetes cluster.

Docker and Kubernetes based toolchain: Add a Deploy stage

  1. Click the Add Stage button.

  2. Name it Deploy.

  3. Select the INPUT tab

    The options for the INPUT tab should be correct by default, but we’ll list them here for completeness:

"Input type": "Build artifacts"
"Stage": "Build"
"Job": Build"
  1. Ensure the Run jobs when previous stage is complete radio button is selected.

  2. Select the JOBS tab

  3. Click Add Job and select Deploy as the job type.

  4. Select Kubernetes as the Deployer type.

  5. Select the appropriate IBM Cloud region, API key, and Cluster name where application will be deployed.

  6. Ensure the Stop running this stage if this job fails is selected also.

"Deployer type": "Kubernetes"
"API key": "<Paste the API key here>"
"Cluster name": "sampleapps"
  1. Click Save.

  2. Click the play button to manually trigger the build stage and click View logs and history to follow the deployement. At the end of a successful deployment the logs will show the URL of the deployed sample app. Visit that URL to see the sample application running on your Kubernetes cluster.

Summary

Congratulations! You’ve now successfully create two toolchains in the IBM DevOps service. You can now deploy your own Cloud Foundry and Docker applications with your own toolchains.