Tuesday, October 14, 2014

Building your own Python docker cartridge for Apache Stratos

How about building your own python-cartridge?
It’s easy, lets follow the steps below.
  1. Download github python-cartridge file contents - Download.
  1. Copy the github files to a shared location where your host machine and the VM can access. [e.g.: mine: users/suhanr/Documents in VirtualBox Settings -> Shared Folders]
This will be easy when you want to edit configuration files and modify file contents.
Important files and folders.
  • Dockerfile - Facilitate automated docker image building process.
  • packs folder contains our stratos cartridge agent, ActiveMQ libraries required and java 1.7 package.
  • init.sh
  • run_scripts.sh
  1. Open a terminal session in the VM and find the shared folder as follows. Go inside that folder.
Say for example your shared folder name is like “VMShared”, then it will appear inside /media/ folder as sf_VMShared.

  1. Simply issue the docker build command to start Docker image automated building process.
docker build -t python-cartridge .
When the build is successful the output will be similar as shown in the below image.

  1. Now tag your root repository as follows
docker tag python-cartridge

If you try to push the root repository to docker you will get the below error.
Impossible to push a "root" repository. Please rename your repository in <user>/<repo> (ex: <user>/python-cartridge)

  1. It is time to push your newly built docker image with the newly created tag to the glance repository
docker push
When the image is successfully pushed you will get an output similar to this.

  1. Now go to glance repository and get the image id of your newly pushed docker image. [This will be needed when you configure your newly built cartridge in Apache Stratos]
> cd /home/stratos/workspace/devstack/
> . openrc admin admin
> glance image-list

sample image ID: 7f179943-0b6b-4d54-af46-c334f65b76f3

  1. Now it is time to configure your newly built cartridge in Apache Stratos

You can find the python configuration files here - Download

Open your web browser in VM and go to the following link.
Since partition and auto scale policies are already defined configure Deployment policy and cartridge configuration.

Sample Deployment policy:
   "id": "python-openstack",
   "partitionGroup": {
       "id": "openstack",
       "partitionAlgo": "one-after-another",
       "partition": [
           "id": "P1",
           "partitionMax": "2",
           "partitionMin": "1"

Sample Cartridge configuration:
     "type": "python",
     "provider": "python",
     "host": "dev.stratos.org",
     "defaultAutoscalingPolicy": "economyPolicy",
     "defaultDeploymentPolicy": "python-openstack",
     "displayName": "Python",
     "description": "Python Cartridge",
     "version": "2.7",
     "multiTenant": "false",
     "portMapping": [
           "protocol": "http",
           "port": "80"
     "deployment": {},
      "iaasProvider": [
         "type": "openstack",
         "imageId": "RegionOne/7f179943-0b6b-4d54-af46-c334f65b76f3",
         "maxInstanceLimit": "1",
         "property": [
            "name": "instanceType",
            "value": "RegionOne/2"
           "name": "keyPair",
           "value": "demo"
           "name": "securityGroups",
           "value": "open-all"

Stratos terminal output will be as follows.

  1. Now subscribe to your newly built cartridge

Once you subscribe to the cartridge it will take some time to activate the instance.

You can find the python application on docker instances public ip address, in this scenario

No comments:

Post a Comment