Based on great example from @vfarcic : https://github.com/vfarcic/docker-swarm. Also highly recommend his series of articles on the topic: Scaling To Infinity with Docker Swarm, Docker Compose and Consulual-services/)
- Docker
- Docker Swarm cluster for running application containers
- Docker Repository (or Registry) for storing the images
- Consul
- Consul Master server
- Consul Agent installed on each other servers
- consul-template for configuration management and automatic reload.
- registrator, executed as a docker container, for services registration and monitoring.
- Ansible
- CI server ( Jenkins )
- Git Repository The example uses GitLab Community Edition, executed as a docker container.
- Load Balancer The example uses HAProxy, feed with the configuration from the Consul
Almost all infrastructure set-up and configuration can be automated with an Ansible Playbook. Unfortunately there are some manual configuration steps that can not be automated. See manual steps.
An usual deployment workflow will have these steps:
- The developer pushes a new version of the code to the Git Repository
- Git Repository send a notification to the CI server
- CI server executes the defined job or a pipeline of jobs, that include:
- code compilation
- execution of tests and code quality checks
- building of a Docker Image
- image is pushed to Docker Registry
- the Ansible Playbook is executed, in which the Docker Swarm master is instructed to deploy new version of the image
- Docker Swarm Master pulls the new image from Docker Registry
- Docker Swarm Master identifies on which Slave node ( or nodes if multiple instances are required ) to deploy the image
- Docker Slave Node received the deploy instruction and runs the container
- Local Consul Agent setup identifies the change in service configuration and updates the configuration on Consul Master
- consul-template on Load Balancer identifies the change in service configuration and updates the Balancer configuration with new ip and ports of the service.
- Load Balancer starts to forward requests to new instances of the application.
##Manual steps:
- Gitlab ( http://10.100.199.203/)
- root user password needs to be changed on fist login
- create new public project named test_service
- jenkins hook needs to be configured in the Settings > Webhooks http://10.100.199.200:8080/gitlab/build_now
- Jenkins (http://10.100.199.200:8080/)
- slave needs to be manually added using following steps.
- Click Manage Jenkins > Manage Nodes > New Node
- Name it cd, select Permanent Agent and click OK
- Type /data/jenkins/slaves/cd as Remote Root Directory
- In Launch method, select Launch slave agents on Unix machines via SSH
- Type 10.100.199.200 as Host
- Click Add* next to **Credentials
- Use vagrant as both Username and Password and click Add
- Click Save
- manually configure Java:
- Click Manage Jenkins > Global Tool Configuration
- Find Java tool config
- Type java in Name field
- Select Install automatically option
- Add your Oracle user and password for download
- manually configure ansible:
- Click Manage Jenkins > Global Tool Configuration
- Find Ansible tool config
- Type ansible in Name field
- Type /usr/local/bin in Path to ansible executables directory field
- manually configure maven:
- Click Manage Jenkins > Global Tool Configuration
- Find Maven tool config
- Type maven in Name field
- Select Install automatically option
- slave needs to be manually added using following steps.
- Test service
- add the created repo to the existing project git remote add origin http://10.100.199.203/root/test_service.git
##TODO
- Swarm
- use Docker 1.2 swarm. Waiting for ansible/ansible-modules-core#4607
- Jenkins
- create pipeline using Jenkinsfile
- automate the creation of slave
- automate the configuration of plugins
- Consul
- use separate config files for server and agent
- configure consul for local dns lookup
- Gitlab
- automate the configuration of jenkins hook
- implement git workflow