Showing posts with label IBM bluemix. Show all posts
Showing posts with label IBM bluemix. Show all posts

Monday, April 20, 2015

Dockerized Bluemix Development Environment

Introduction


Rather than configuring your actual development environment for IBM Bluemix, it makes more sense to create a Dockerfile.

Within a launched container we have full access to Bluemix, and can even push anad manage other containers.


FROM dind

MAINTAINER  Craig Trim "craigtrim@gmail.com"

RUN export DEBIAN_FRONTEND=noninteractive && \
  apt-get update -qq && apt-get autoremove -y && apt-get install -qqy \
    build-essential \
    python-dev \
    python-pip \
    wget 

# install python setup-utils
RUN \
  wget https://bootstrap.pypa.io/ez_setup.py -O - | python

# install IBM ICE
RUN \
  curl -O https://static-ice.ng.bluemix.net/icecli-2.0.zip && \
  pip install icecli-2.0.zip

# install cloudfoundry command line interface
RUN \
  $(wget -O cf-cli_amd64.deb https://cli.run.pivotal.io/stable?release=debian64&version=6.11.0&source=#github-rel) && \ 
  dpkg -i cf-cli_amd64.deb && \
  apt-get install -f -y
  #rm cf-cli_amd64.deb

# install docker-compose
RUN \
  wget https://github.com/docker/compose/releases/download/1.1.0/docker-compose-$(uname -s)-$(uname -m) && \
  mv docker-compose-$(uname -s)-$(uname -m) docker-compose && \
  chmod 777 docker-compose && \
  mv docker-compose /usr/local/bin/

# misc commands
RUN \
  usermod -a -G docker $(whoami) && \
  sh -c 'echo "export DOCKER_TLS_VERIFY=1" >> /etc/environment'



Usage


I launch a container using this script:
$ sudo docker build -t craig/bluemix .
$sudo docker run --privileged -t -i -p 4444 craig/bluemix



References


  1. [Github] Bluemix Dockerfile
    1. the script is maintained here
  2. [Github] dind image 
    1. the docker-in-docker image I extended

Configuring a local dev environment for IBM Bluemix

What is IBM Bluemix?


Using this great pizza-as-a-service paradigm, Bluemix is a SASS:
Fig 1: Bluemix is a SAAS


Developers can use existing Bluemix services, including Alchemy API:
Fig 2: Watson services on Bluemix


Developers can also deploy their own services, including containers using Docker technology.

This article will walk through the setup of a local development environment for working with Bluemix. All scripting and configuration is for Debian64-bit (Ubuntu 14.10 at the time of this article).


Python Development Environment


The first step is to create a python development environment.
# install pip 
sudo apt-get \
  install -y \
    build-essential \
    python-dev \
    python-pip

# install python setup-utils
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

pip is a package management system used to install and manage software packages written in Python and Setuptools is a package development process that enhances the Python standard library distribution utilities.


Installing Docker


Instructions for installing docker on Ubuntu are referenced below and the script is replicated here:
# add the Docker repository key to your local keychain: 
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

# add the Docker repository to your apt sources list: 
sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"

# prior to using any Ubuntu-maintained package installation, ensure existing packages are up to date: 
sudo apt-get update

# install the Docker-LXC package: 
sudo apt-get install -y lxc-docker

# install docker compose:
wget https://github.com/docker/compose/releases/download/1.1.0/docker-compose-$(uname -s)-$(uname -m)
mv docker-compose-$(uname -s)-$(uname -m) docker-compose
sudo chmod 777 docker-compose
sudo mv docker-compose /usr/local/bin/
docker-compose --version

Docker is a container-based software framework for automating deployment of applications. “Containers” are encapsulated, lightweight, and portable application modules.


IBM Extensions


Before you can create a container in Bluemix, you must install the IBM Containers Extension (ICE):
sudo apt-get \
  install -y \
    curl

# install ice
export ICE=icecli-2.0.zip
curl -O https://static-ice.ng.bluemix.net/$ICE
sudo pip install icecli-2.0.zip
rm $FILE
ice version



Cloud Foundry


Finally, we need to install the Cloud Foundry command line interface:
# install CF
export FILE=cf-cli_amd64.deb
wget -O $FILE https://cli.run.pivotal.io/stable?release=debian64&version=6.11.0&source=github-rel
sudo dpkg -i $FILE
sudo apt-get install -f -y
rm $FILE
cf --version



Miscellaneous Commands


We need to endsure that the necessary environment variables are set, user authorizations are in place and configuration files are correct.
# set docker env var
sudo sh -c 'echo "export DOCKER_TLS_VERIFY=1" >> /etc/environment'

# modify user authorization
sudo usermod -a -G docker $(whoami)

By default, the ice commands must be run with root authentication and therefore, require the prefix sudo. This last command will allow us to run docker and ice commands without sudo.



References

  1. [Blogger] Configuring a Python Development Environment
  2. [Blogger] Installing Docker on Ubuntu
  3. [GitHub] Individual Installation Scripts