/cd-infrastructure

An example Continuous Delivery Infrastructure with Docker-Swarm

Primary LanguageCSS

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/)

Technologies

  • 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.

Overview

CD infrastructure overview

Delivery Workflow

An usual deployment workflow will have these steps:

  1. The developer pushes a new version of the code to the Git Repository
  2. Git Repository send a notification to the CI server
  3. 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
  4. Docker Swarm Master pulls the new image from Docker Registry
  5. Docker Swarm Master identifies on which Slave node ( or nodes if multiple instances are required ) to deploy the image
  6. Docker Slave Node received the deploy instruction and runs the container
  7. Local Consul Agent setup identifies the change in service configuration and updates the configuration on Consul Master
  8. consul-template on Load Balancer identifies the change in service configuration and updates the Balancer configuration with new ip and ports of the service.
  9. Load Balancer starts to forward requests to new instances of the application.

##Manual steps:

  • Gitlab ( http://10.100.199.203/)
  • Jenkins (http://10.100.199.200:8080/)
    • slave needs to be manually added using following steps.
      1. Click Manage Jenkins > Manage Nodes > New Node
      2. Name it cd, select Permanent Agent and click OK
      3. Type /data/jenkins/slaves/cd as Remote Root Directory
      4. In Launch method, select Launch slave agents on Unix machines via SSH
      5. Type 10.100.199.200 as Host
      6. Click Add* next to **Credentials
      7. Use vagrant as both Username and Password and click Add
      8. Click Save
    • manually configure Java:
      1. Click Manage Jenkins > Global Tool Configuration
      2. Find Java tool config
      3. Type java in Name field
      4. Select Install automatically option
      5. Add your Oracle user and password for download
    • manually configure ansible:
      1. Click Manage Jenkins > Global Tool Configuration
      2. Find Ansible tool config
      3. Type ansible in Name field
      4. Type /usr/local/bin in Path to ansible executables directory field
    • manually configure maven:
      1. Click Manage Jenkins > Global Tool Configuration
      2. Find Maven tool config
      3. Type maven in Name field
      4. Select Install automatically option
  • Test service

##TODO

  • Swarm
  • 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