Top Banner
Continuous deployment with Jenkins and Salt LinuxCon CloudOpen ContainerCon North America 2015, Seattle Anirban Saha
26

Continuous Deployment with Jenkins and Salt

Jan 16, 2017

Download

Technology

Anirban Saha
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Continuous Deployment with Jenkins and Salt

Continuous deployment with Jenkins and Salt

LinuxCon CloudOpen ContainerCon

North America 2015, Seattle

Anirban Saha

Page 2: Continuous Deployment with Jenkins and Salt

About me

Techie…

Traveller…

Thinker…

Author of ‘Salt Cookbook’

Page 3: Continuous Deployment with Jenkins and Salt

Deployment

Should be…

• Simple

• Stable

• Fast (good to have…)

• Reliable

• One click

Page 4: Continuous Deployment with Jenkins and Salt

Problems faced

• Code distribution

• Additional tasks (commands, migrations)

• Latency

• Parallel execution

• Batch deployments

• Ensuring uptime

Page 5: Continuous Deployment with Jenkins and Salt

Methods availableDeployment

Configuration management tools :

• Puppet, Chef, Ansible, Salt

Remote execution tools:

• SSH, Parallel SSH, Rundeck

Packages:

• Code packaged as RPM or DEB files

Page 6: Continuous Deployment with Jenkins and Salt

Code storage

• GIT server (Github, Gitlab, Bitbucket, etc.)

• Object storage (Amazon S3, Swift, etc.)

• Package repositories (YUM/Debian)

• Configuration management repositories

• File servers managed manually

Page 7: Continuous Deployment with Jenkins and Salt

ProblemsDeployment:

• Remote execution tools :

• Time consuming (over SSH)

• Need to maintain inventory of hosts

Code storage:

• GIT repositories:

• Usually centrally located, latency when deployed from GIT

• Package repositories (RPM/DEB):

• Problems in simultaneously updating repo metadata

Rollback:

• Version manipulation is a problem with most configuration

management and remote execution tools

Page 8: Continuous Deployment with Jenkins and Salt

Salt

Provides…

• Agent based communication

• Fast execution

• Orchestration

• Batch execution

• Strong Integration with providers and

services

Page 9: Continuous Deployment with Jenkins and Salt

Salt featuresTargeting deployment nodes :

• By hostname

• ‘myappweb*’

• By specific grains

• -G ‘node_type:webserver’

• By nodegroups

• -N webgroup

Page 10: Continuous Deployment with Jenkins and Salt

Salt featuresTask dependencies :

• Salt requisites to make tasks dependent on each other

get_archive:

module.run:

.

.

deploy_app:

module.run:

.

.

- require:

- module: get_archive

Page 11: Continuous Deployment with Jenkins and Salt

Salt featuresOrchestration :

webgrp2_deploy: salt.state:

- tgt: ' webgrp2' - tgt_type: nodegroup - sls:

- webserver.deploy - require:

- salt: webgrp1_deploy

webgrp1_deploy: salt.state:

- tgt: 'webgrp1'- tgt_type: nodegroup - sls:

- webserver.deploy

Page 12: Continuous Deployment with Jenkins and Salt

Salt features

Batch Execution :

• By number of hosts

• --batch-size 5

• Executes on 5 hosts at a time

• By percentage of hosts

• --batch-size 25%

• Executes on 25% of total target

hosts at a time

Page 13: Continuous Deployment with Jenkins and Salt

Salt features

Salt API:

# curl -H "Accept: application/json"

-d secretkey= "mysupersecretkey"

-k https://10.0.0.2:8080/hook/deploy

{"success": true}

Page 14: Continuous Deployment with Jenkins and Salt

Tools

To be used…

• GIT for code repository

• Jenkins for CI

• Ant for build and tasks

• Amazon S3 for code archive storage

• Salt for deployment

• Shell scripts (good old bash) for

additional tasks

Page 15: Continuous Deployment with Jenkins and Salt

Salt deployment methods

• Salt hosted on the Jenkins server.

Jenkins calls Salt binary

• Salt hosted independently.

Jenkins calls Salt via SSH

• Jenkins calls Salt via Salt API

Page 16: Continuous Deployment with Jenkins and Salt

Objective

Page 17: Continuous Deployment with Jenkins and Salt

Steps• salt-cloud used to launch instances

• Post install actions used to synchronize EC2 grains

• Salt reactor used to run states on new instances ,

perform deployment and register with load balancer

• Jenkins build job used to build new code, create tags

and push new deployment ready archive to Amazon

S3

• Jenkins deploy job used to fetch new code version

and deploy code on target servers

Page 18: Continuous Deployment with Jenkins and Salt

Steps explained• Salt cloud is used to spawn instances

• Following parameter is provided in the profile to push custom EC2 grains,

• sync_after_install: grains

• The node is registered and deregistered from the load balancer with the

following module definition,

register:

module.run:

- name: boto_elb.register_instances

- m_name: mywebapp

- instances:

- {{ grains['ec2']['instance_id'] }}

• Here ['ec2']['instance_id'] is one of the custom grains pushed to the node

Page 19: Continuous Deployment with Jenkins and Salt

Steps explained

Fetching archive:

Salt s3 execution module used to get code archive from

Amazon S3

fetch_app_archive: module.run:

- name: s3.get

- bucket: mywebapp-us

- path: mywebapp-{{ app_version }}.tar

- local_file: /tmp/mywebapp-{{ app_version }}.tar

Page 20: Continuous Deployment with Jenkins and Salt

Steps explained

Setting App version grain:

After every deploy, a grain is set to record the

app version deployed for tracking,

app_version:

grains.present:

- value: {{ app_version }}

- require:

- cmd: deploy_app

Page 21: Continuous Deployment with Jenkins and Salt

Steps explainedDeployment based on App version:

At every deploy, it is checked if the version to

be deployed is already on the node using the

app_version grain,

{% if grains['app_version'] != app_version %}

deregister:

fetch_app_archive:

deploy_app:

register:

{% endif %}

Page 22: Continuous Deployment with Jenkins and Salt

Lets do it then !!!

Page 23: Continuous Deployment with Jenkins and Salt

Demo repository

Get the demo repository at the

following location,

https://github.com/rosesnthornz/

cloudopen-na-2015

Page 24: Continuous Deployment with Jenkins and Salt

Questions ?

Page 25: Continuous Deployment with Jenkins and Salt

Contact

Email :

[email protected]

Twitter : @rosesnthornz

Page 26: Continuous Deployment with Jenkins and Salt

Thank You !!!