We’re giving away 1,500 DJI Tello drones. Enter to win ›
By Cemre Göç | Published December 17, 2017 - Updated July 9, 2018
CloudContainersDevOpsPlatform as a Service
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.
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.
We will also be using two GitHub repositories that contain the bare minimum for a simple web app:
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.
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.
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.
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.
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.
We’re now presented with a blank toolchain. Let’s add a few tools that will help us run our application.
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.
Your toolchain page now should look like this:
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.
Click the Add Stage button.
Name it Build.
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"
Ensure the Run jobs whenever a change is pushed to Git radio button is selected.
Select the JOBS tab
Click Add Job and select Build as the job type.
Select Simple as the Builder type.
Ensure the Stop running this stage if this job fails is selected as well.
We will now be brought back to our Delivery Pipeline.
Name it Deploy.
The options for the INPUT tab should be correct by default, but we’ll list them here for completeness:
"Input type": "Build artifacts"
Ensure the Run jobs when previous stage is complete radio button is selected.
Click Add Job and select Deploy as the job type.
Select Cloud Foundry as the Deployer type.
Select the appropriate IBM Cloud region, organization, and space where application will be deployed.
Name the application sample-express-app.
Ensure the Stop running this stage if this job fails is selected also.
"Deployer type" : "Cloud Foundry"
"Application name": "sample-express-app"
Select the ENVIRONMENT PROPERTIES tab
Add a new property with type text property. Configure it with the following key-value pair:
The delivery pipeline should now look like this:
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.
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.
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.
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:
Before configuring the delivery pipeline we will need an IBM Cloud API key to interact with our IBM Cloud Private Container Registry.
Navigate to the Platform API Keys, or in the UI:
Click Manage button on the top right, select Security, and then Platform API Keys.
Create a new key by clicking the Create button.
Enter a name, such as docker-app, enter a description, and click Create.
An obfuscated API key will be generated, select the Show button to view the key. Copy this locally or jot it down.
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”.
"Input type": "Git repostory"
"Git repository": "sample-docker-app"
Select Container Registry as the Builder type.
Under the API key field, add your newly generated API key from the previous section.
Ensure the Container Registry namespace is set to sampleapps that we created earlier.
Update the “Docker image name to sampledocker
"Builder type" : "Container Registry"
"API Key": "<Paste the API key here>"
"Container Registry namespace": "sampleapps"
"Docker image name" : "sampledocker"
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.
View logs and history
Select the INPUT tab
Select Kubernetes as the Deployer type.
Select the appropriate IBM Cloud region, API key, and Cluster name where application will be deployed.
"Deployer type": "Kubernetes"
"API key": "<Paste the API key here>"
"Cluster name": "sampleapps"
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.
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.
Back to top