This article is about Codeship Pro.

Deploying To IBM Bluemix Container Service

You'll need roughly 4 minutes to read this article.

You can find a sample repo for deploying to IBM Bluemix with Codeship Pro on Github here.

Continuous Delivery To IBM Bluemix Container Service

To make it easy for you to deploy your application to IBM Bluemix Container Service, we’ve built deployment images that have the Bluemix CLI installed and configured for use in the CI/CD process.

You will simply need to add one of the IBM deployment images as a service in your codeship-services.yml file so that you can run the commands you need.

IBM Bluemix Deployment Container

Prerequisites

Prior to getting started, please ensure you have the following:

Authentication

To deploy to IBM, you will need to add the following values to your encrypted environment variables that you encrypt and include in your codeship-services.yml file:

  • BLUEMIX_API_ENDPOINT
  • BLUEMIX_CONTAINER_SERVICE_HOST
  • BLUEMIX_CONTAINER_SERVICE_CLUSTER_NAME
  • BLUEMIX_ORGANIZATION
  • BLUEMIX_SPACE

These variables will be set on the IBM deployment container, which you can read more about below. This deployment container will use the environment variables as part of the authentication required by the IBM Bluemix CLI when you run your deployment commands.

Configuring Deployment Service

Once you have created your encrypted environment variables, you will want to add a new service to your codeship-services.yml file.

This file will use the image Codeship maintains for IBM-based deployments, and will read your code from a volume connected to your primary service.

This service will be used for all of your Container Service deployment commands, and will use the encrypted environment variables you created above.

app:
  build:
    image: your-org/your-app
    path: .
    dockerfile_path: Dockerfile.app
  encrypted_env_file: ibm.env.encrypted
  volumes:
    - ./deployment/tests:/tests

dockercfg_generator:
  image: codeship/ibm-bluemix-dockercfg-generator
  add_docker: true
  encrypted_env_file: bluemix.env.encrypted

deployment:
  image: codeship/ibm-bluemix-deployment
  encrypted_env_file: ibm.env.encrypted
  volumes:
    - ./deployment/tests:/tests

Container Registry

Using IBM Bluemix Container Service usually involves pushing images to the IBM Bluemix Container Registry as part of your CI/CD process.

We recommend reading our guide for pushing to the Bluemix registry, as the deployment commands below will feature an image push based on those instructions.

Deploying Your App

Once you have added the deployment service to your codeship-services.yml file, you will now run Container Service deployment commands from your codeship-steps.yml file using that service to execute the commands.

Note that in this example, all of the Container Service deployment commands have been moved to a script file named deploy_to_kubernetes.sh. The reason it is named deploy_to_kubernetes.sh is because the IBM Bluemix Container Service uses Kubernetes to orchestrate container deployments, so you will use Kubernetes commands in your deployment commands.

- name: Push To Bluemix Container Registry
  service: app
  type: push
  image_name: registry.ng.bluemix.net/your-org/your-image
  registry: registry.ng.bluemix.net
  dockercfg_service: dockercfg_generator  

- name: Bluemix Container Service Kubernetes Deployment
  service: deployment
  command: /tests/deploy_to_kubernetes.sh

Inside the deploy_to_kubernetes.sh script, you will have something similar to:

#!/bin/bash

set -e

# login to IBM Bluemix via credentials provided via (encrypted) environment
# variables
bluemix login \
  --apikey "${BLUEMIX_API_KEY}" \
  -a "${BLUEMIX_API_ENDPOINT}" \
  -o "${BLUEMIX_ORGANIZATION}" \
  -s "${BLUEMIX_SPACE}"

bluemix cs init \
  --host "${BLUEMIX_CONTAINER_SERVICE_HOST}"

# Get the required configuration for `kubectl` from Bluemix and load it
bluemix cs cluster-config \
  --export "${BLUEMIX_CONTAINER_SERVICE_CLUSTER_NAME}" \
  > .kubectl_config
source .kubectl_config && rm -rf .kubectl_config

# run the commands required to deploy the application via `kubectl`
kubectl version
kubectl cluster-info

See Also

To learn more: