fb
WSO2 Tutorial 5 min

WSO2 (API Manager) Dockerized

Steve Liem
Steve Liem
Technical Consultant
am 2.0 pattern 3
Scroll

Offering complete solutions in a short time to market is one of the biggest things DevOps organizations need to deal with these days. Regarding WSO2 products we have a range of various complexities regarding setting up WSO2 products. Now we can fulfill the short time to market task by applying Docker containers for all WSO2 products. In this blog I will give a short guideline to get a good kickstart.

Getting started

First we need to apply for a WSO2 account. (If you haven’t done it yet) This can be done over here. We need this account later to login to the WSO2 Docker Hub, so that we are able to pull all the specific WSO2 Docker images we need for setting up an environment. 

Further requirements: Install vagrant on your system, Virtualbox and git client. 

Setting up a VM

Create directory with inside a normal file with Unix / UTF-8 format called “Vagrantfile” with the following content:

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby : 

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

 $bootstrap=<<SCRIPT
apt-get update
curl -sSL https://get.docker.com/ | sudo sh
gpasswd -a vagrant docker
service docker restart
curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
SCRIPT

 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "ubuntu/trusty64" 

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

   # Create a private network, which allows host-only access to the machine
  
# using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

   config.vm.provider "virtualbox" do |vb|
     vb.customize ["modifyvm", :id, "--memory", "4096"]   end 

  # Created a share map that is synced from your system to the VM
  config.vm.synced_folder "share/", "/srv/share"

     config.vm.provision :shell, inline: $bootstrap

 end

Also create a /share subdirectory. 

Now we hit vagrant:

$ vagrant up

Vagrant will setup a Virtualbox with inside Ubuntu, Docker and Docker Compose. If all finished we can directly do an ssh and enter the Virtualbox environment:

$ vagrant ssh

Building Docker images and run

Next step is to git clone the WSO2 GitHub repo. For our example we will clone the repo for API Manager, but this can be done with other WSO2 products too. First cd to the /share sub directory and then do a :

$ git clone https://github.com/wso2/docker-apim.git
$ cd /docker-apim
$ git submodule init
$ git submodule update

Please take a look at the README to see all the commands needed for building and running the Docker images for WSO2 API Manager. This you will do in the Virtualbox we’ve just started up.

WSO2 offers 9 different deployment patterns for running on a Docker host. These patterns are the official WSO2 deployment architectures.

Pattern 1

am-2.0-pattern-1.png

This pattern has one container running API Manager all in one, and a seperate container running a MySQL database. We use this pattern to easily run it on a local dev environment for implementation and local testing purposes.

Pattern 3

Distrubuted setup of the WSO2 API gateway and WSO2 API manager

This pattern deployes a distributed and clustered WSO2 API gateway, WSO2 API manager, API traffic manager, WSO2 API publisher / store, API key manager and WSO2 API analytics in seperate dedicated Docker containers, suitable for instance for setting up an active/passive situation on a VM or in the cloud. It also includes how to loadbalance directly to an NGINX loadbalancer. Loadbalancing WSO2 API manager with NGinx is a proven and very stable setup.

Pattern 4

Setup WSO2 API manager with Docker

This pattern is an out of the box setup suitable for setting up a clustered API Manager solution inside a corporate infrastructure with a Demilitarized Zone (DMZ) and a local area network (LAN). All done with Docker Compose scripts.

A complete collection of pattern pictures can be found here: https://github.com/wso2/docker-apim/tree/master/docker-compose/patterns/design. 

Run it!

The simplest environment we will setup is Pattern1. Inside the virtual first go to /srv/share/docker-apim/tree/master/docker-compose/pattern-1/. Our VM has 4Gb RAM resources which is exactly what we need to run Pattern 1. For other patterns like Pattern 3 or 4 we need more resources. How to determine the exact number for resources is a seperate subject based on WSO2 product Capacity Management, which is out of scope for this blog.

But for now do a vagrant ssh and do the following: 

$ cd /srv/share/docker-apim/tree/master/docker-compose/pattern-1/

 

 $ docker login docker.wso2.com
username: {your WSO2 acount name}
password: ****** 

$ docker-compose pull

$ docker-compose up --build -d

In the background MySQL and the APIManager is started up in seperate Docker containers. Take note that the API Manager is available the moment that the start up is finished. Because over here it is a background process in detached mode, one of the ways to take notice about the progress is to check the APIM logs. This we can easily check with the following command:

$ docker-compose logs -f api-manager

We now see a trace of the full logs.

The final results

After the containers are all started up, we can open a browser and explore the various interfaces provided according to the README.md file for pattern-1. Take note we are running API Manager inside a virtual, so we need to use the VM IP address instead of the suggested “localhost”. The IP is “192.168.33.10” determined by the given Vagrant script. Login with username admin and password admin.

Conclusion

We have full posibilities regarding setting up WSO2 products in any desired pattern depending on the situation. Besides Docker Compose we also have full Docker Compose Swarm setup scripts to setup high available clusters. In combination with Amazon Web Services or any other common cloud provider, Docker Swarm is supported out of the box, and an environment is easily realised with short time to market. Another nice addition for supporting a DevOps organisation.

Thanks to Dominique Mulder for his feedback and contribution to this blog.

If you have any questions about this blogpost contact us via the comments section of this blog. View also our WSO2 Tutorialswebinars or white papers for more technical information. Need support? We do deliver WSO2 Product Support, WSO2 Development SupportWSO2 Operational Support and WSO2 Training Programs.

Full API lifecycle Management Selection Guide

WHITEPAPER

smartmockups l0qqucke