Public | Automated Build

Last pushed: a year ago
Short Description
Kabali Static App
Full Description

Docker - Build - Deploy (code: kabali)

Requirements:

* Ubuntu 16.04
* Docker engine 1.12.0-rc2
* Docker machine v0.8.0-rc1
* Virtualbox 5.0
* curl

1. Build Images:

* dynamic
    - Assumption: sample.war ci artifact in build/dynamic directory
    - Build sample.file as ROOT.war in a jetty image
    - docker cloud is setup to automatically build the image on git push - vasanth/kabali-dynamic:latest 
    (or) the image can be built locally and pushed to a registry

* static
    - Assumption: assets.tar.gz ci artifact in build/static directory
    - Build assets.tar.gz as default document root in a nginx image
    - docker cloud is setup to automatically build the image on git push - vasanth/kabali-static:latest 
    (or) the image can be built locally and pushed to a registry

The immutable image is used in test, training and production env 
and any change to sample.war or assets.tar.gz a new image is built and versioned.

2. Create Machine:

Initial Setup: 3 Swarm managers and 3 Worker swarm nodes

In production, worker swarm worker nodes are placed in an Autoscaling group 
and using launch config, the instance on boot - registers to swarm cluster as worker node

3. Deploy/Scale Service:

Assumption: DOCKER_REPO=vasanth/kabali
Refer /deploy/deploy.sh help

Workflow:

vasanth@dex:~/prod$ git clone git@github.com:vasanthperiyasamy/kabali.git

vasanth@dex:~/prod$ cd kabali

vasanth@dex:~/prod$ ./machine/setup.sh
Manage docker machines

Usage: ./setup.sh create
       ./setup.sh status MACHINE_NAME
       ./setup.sh delete
       ./setup.sh help

vasanth@dex:~/prod/kabali$ ./machine/setup.sh create
....
Creating machine...
ID                           NAME      MEMBERSHIP  STATUS  AVAILABILITY  MANAGER STATUS
2bk2503awu6nl2bar78xsw2ap    worker2   Accepted    Ready   Active
6a3vs6mxv0i757qfxgiy7fvc4    manager2  Accepted    Ready   Active
72bl8q9sxxc66emy0911qrbb3    worker1   Accepted    Ready   Active
7c4iz2vaq2vxyrfuqosmaty59    manager1  Accepted    Ready   Active
7vt1e8fi7hqy7w00oqgog83zq    worker0   Accepted    Ready   Active
95ejm0fcly8zgh23w47c744do *  manager0  Accepted    Ready   Active        Leader

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh
Manage docker image deployments to a cluster of machines

Usage: ./deploy.sh create APP_NAME REPLICAS [hostPort:containerPort]
       ./deploy.sh scale APP_NAME REPLICAS
       ./deploy.sh status APP_NAME
       ./deploy.sh delete APP_NAME
       ./deploy.sh help

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh create static 2 80:80
49obfqo8eeczc5mkab1vqdvok
ID                         NAME      SERVICE  IMAGE                  LAST STATE           DESIRED STATE  NODE
8vb0p9wnmyg8tmsff7vitzydd  static.1  static   vasanth/kabali-static  Preparing 1 seconds  Running        manager1
8mnrzkyne9d36dcwooy39fuhw  static.2  static   vasanth/kabali-static  Preparing 1 seconds  Running        worker0


vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh status static
ID                         NAME      SERVICE  IMAGE                  LAST STATE          DESIRED STATE  NODE
8vb0p9wnmyg8tmsff7vitzydd  static.1  static   vasanth/kabali-static  Running 45 seconds  Running        manager1
8mnrzkyne9d36dcwooy39fuhw  static.2  static   vasanth/kabali-static  Running 45 seconds  Running        worker0

vasanth@dex:~/prod/kabali$ curl -I $(docker-machine ip manager1)
HTTP/1.1 200 OK
Server: nginx/1.11.1
Date: Tue, 28 Jun 2016 22:53:24 GMT
Content-Type: text/html
Content-Length: 219
Last-Modified: Mon, 27 Jun 2016 07:57:30 GMT
Connection: keep-alive
ETag: "5770dc6a-db"
Accept-Ranges: bytes

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh scale static 10
static scaled to 10
ID                         NAME       SERVICE  IMAGE                  LAST STATE           DESIRED STATE  NODE
8vb0p9wnmyg8tmsff7vitzydd  static.1   static   vasanth/kabali-static  Running 3 minutes    Running        manager1
8mnrzkyne9d36dcwooy39fuhw  static.2   static   vasanth/kabali-static  Running 3 minutes    Running        worker0
2192f0rno34pax1p2ra8c1kag  static.3   static   vasanth/kabali-static  Preparing 1 seconds  Running        manager1
bhpmw2svap7mfgcp7mek8vdmh  static.4   static   vasanth/kabali-static  Preparing 1 seconds  Running        manager0
1q80v9c29tjpjg3lvja5n5bv9  static.5   static   vasanth/kabali-static  Preparing 1 seconds  Running        worker2
26n4rjrz39x05uyfjgxuklq3b  static.6   static   vasanth/kabali-static  Preparing 1 seconds  Running        worker1
71ss6slo2ql4glxu6qhrvflxx  static.7   static   vasanth/kabali-static  Preparing 1 seconds  Running        worker2
erka660ewpoom1gbgs7sfavbq  static.8   static   vasanth/kabali-static  Preparing 1 seconds  Running        worker0
9xg7wvo0u3zn6jjcc42nkiumf  static.9   static   vasanth/kabali-static  Preparing 1 seconds  Running        manager0
efaq0bgs4l2e7f297b38ucbwy  static.10  static   vasanth/kabali-static  Preparing 1 seconds  Running        manager2

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh status static
ID                         NAME       SERVICE  IMAGE                  LAST STATE          DESIRED STATE  NODE
8vb0p9wnmyg8tmsff7vitzydd  static.1   static   vasanth/kabali-static  Running 3 minutes   Running        manager1
8mnrzkyne9d36dcwooy39fuhw  static.2   static   vasanth/kabali-static  Running 3 minutes   Running        worker0
2192f0rno34pax1p2ra8c1kag  static.3   static   vasanth/kabali-static  Running 23 seconds  Running        manager1
bhpmw2svap7mfgcp7mek8vdmh  static.4   static   vasanth/kabali-static  Running 23 seconds  Running        manager0
1q80v9c29tjpjg3lvja5n5bv9  static.5   static   vasanth/kabali-static  Running 23 seconds  Running        worker2
26n4rjrz39x05uyfjgxuklq3b  static.6   static   vasanth/kabali-static  Running 23 seconds  Running        worker1
71ss6slo2ql4glxu6qhrvflxx  static.7   static   vasanth/kabali-static  Running 23 seconds  Running        worker2
erka660ewpoom1gbgs7sfavbq  static.8   static   vasanth/kabali-static  Running 23 seconds  Running        worker0
9xg7wvo0u3zn6jjcc42nkiumf  static.9   static   vasanth/kabali-static  Running 23 seconds  Running        manager0
efaq0bgs4l2e7f297b38ucbwy  static.10  static   vasanth/kabali-static  Running 23 seconds  Running        manager2

vasanth@dex:~/prod/kabali$ docker-machine rm worker0 -y
Successfully removed worker0

vasanth@dex:~/prod/kabali$ docker-machine rm worker1 -y
Successfully removed worker1

vasanth@dex:~/prod/kabali$ docker-machine rm worker2 -y
Successfully removed worker2

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh status static
ID                         NAME       SERVICE  IMAGE                  LAST STATE              DESIRED STATE  NODE
8vb0p9wnmyg8tmsff7vitzydd  static.1   static   vasanth/kabali-static  Running 5 minutes       Running        manager1
ajd2oloz02hy5fg97fhzmgeo9  static.2   static   vasanth/kabali-static  Preparing 9 seconds     Running        manager2
2192f0rno34pax1p2ra8c1kag  static.3   static   vasanth/kabali-static  Running About a minute  Running        manager1
bhpmw2svap7mfgcp7mek8vdmh  static.4   static   vasanth/kabali-static  Running About a minute  Running        manager0
digomkwgsy9uvb8v906gi3e1i  static.5   static   vasanth/kabali-static  Accepted 2 seconds      Accepted       manager0
35fhzn8fqae78k4ukm56and4w  static.6   static   vasanth/kabali-static  Accepted 2 seconds      Accepted       manager0
euwya8varz6a5qs6tyh63odvb  static.7   static   vasanth/kabali-static  Accepted 2 seconds      Accepted       manager1
1e9sgqjc3n02cxz62zkxtl273  static.8   static   vasanth/kabali-static  Accepted 4 seconds      Accepted       manager2
9xg7wvo0u3zn6jjcc42nkiumf  static.9   static   vasanth/kabali-static  Running About a minute  Running        manager0
efaq0bgs4l2e7f297b38ucbwy  static.10  static   vasanth/kabali-static  Running About a minute  Running        manager2

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh create dynamic 2 8080:8080
9znlsf42ptfcnc71vj3ye2bxu
ID                         NAME       SERVICE  IMAGE                   LAST STATE           DESIRED STATE  NODE
8xqcovjrel5qn5ybvit4kdo8h  dynamic.1  dynamic  vasanth/kabali-dynamic  Preparing 1 seconds  Running        manager0
6mwqmztqvnyi4bflvsejq8yhn  dynamic.2  dynamic  vasanth/kabali-dynamic  Preparing 1 seconds  Running        manager0

vasanth@dex:~/prod/kabali$ ./deploy/deploy.sh status dynamic
ID                         NAME       SERVICE  IMAGE                   LAST STATE              DESIRED STATE  NODE
8xqcovjrel5qn5ybvit4kdo8h  dynamic.1  dynamic  vasanth/kabali-dynamic  Running About a minute  Running        manager0
6mwqmztqvnyi4bflvsejq8yhn  dynamic.2  dynamic  vasanth/kabali-dynamic  Running About a minute  Running        manager0

vasanth@dex:~/prod/kabali$ curl -I $(docker-machine ip manager0):8080
HTTP/1.1 200 OK
Last-Modified: Mon, 30 Jul 2007 16:26:28 GMT
Content-Type: text/html
Accept-Ranges: bytes
Content-Length: 636
Server: Jetty(9.3.10.v20160621)

vasanth@dex:~/pro/kabali$ ./deploy/deploy.sh delete dynamic
dynamic

vasanth@dex:~/pro/kabali$ ./deploy/deploy.sh status dynamic
Error: No such service: dynamic

vasanth@dex:~/pro/kabali$ ./machine/setup.sh delete
About to remove manager0
Successfully removed manager0
About to remove manager1
Successfully removed manager1
About to remove manager2
Successfully removed manager2
About to remove worker0

Todo:

- Env: Separate deploy script for dev/training and production
- Image: Squash image size
- Swarm: Tag swarm worker nodes & deploy images based on tags(e.g dynamic/static)
- Swarm: Associate worker nodes based on tags to elbs
- Swarm: Autos-cale worker nodes
- Swarm: Support service update to deploy new image
- Consul: Setup consul agent(client mode) in each worker nodes
- Log: Push logs out of host/container to a central log aggregator
- Dashboard: To view swarm - nodes and its deployed services and states
- AWS: Security Groups and separate VPC's for each layer(consul/manager/worker cluster)
- AWS: Cloudformation or Terraform templates for creating VPC/Security groups/ELB/ASG
- Arch: Diagram describing the stack
Docker Pull Command
Owner
vasanth
Source Repository

Comments (0)