Don't stop Deploying

Ironhack

Your Host this Afternoon

Alex Fernández


Software developer with 15+ years experience
Currently at MediaSmart Mobile
Shameless tinkerer since forever
@pinchito, alexfernandez, alejandrofer

Tests


Who automatizes the automatizer?

Anonymous

types of Tests


Unit tests


Integration tests / system tests


Load tests



Automatic tests — are the bests!

Better than the rests!

Automate!


Design a control API

Start and stop the system using the API


Self-contained tests: clean-up


Three basic rules:

  • One single button
  • Fail fast and loudly
  • No human intervention


Make your life easier



Make your systems easy to test

Continuous Integration


Store unit and integration tests


Run the whole suite with every change


Check if something has broken


For any new error, introduce a new test


Why Integrate All the Time?


Close the gap between development and tests


Safety net for developers


Notice errors when the code is fresh


Shorten development cycles!

Travis-CI


Tool for continuous integration


Creates an environment for every run


Free for open source projects


It is, of course, open source

Practical Session 1


Clone node.js project addPath

git clone https://github.com/alexfernandez/demo-deployment.git


Verify integration tests


Add to Travis-CI


Break tests and see what happens, then fix them

Tech Spec


Web service on port 12322

Adds two numbers in the path


URL: /1/2, returns 3

/1/2
\=> 3

MIME type: text/plain


If any of the values is not a number, use 0

Tests


Unit test

Integration test

Load test


Added to test.js


Run as npm test

Integrate addPath with Travis-CI


Create account on Travis-CI


Activate project


Add .travis.yml


Push something

Bonus Round!


Break tests...

... push to repo...

... then fix tests


Change build status


Send pull request to main repo

Success!


Rails Equivalent


Project: add_path


Same spec


Run tests: rake test


.travis.yml for Ruby

Deployment


Amateurs talk about programming

Professionals care about deployment

Anonymous

Deploying Code


Put your code into production


Different servers, different rules


With node:
git pull
npm install
restart [service]

Automate!


Do the manual way...

Or do the cool way: with code


DevOps for the win!


Three basic rules:

  • One single button
  • Fail fast and loudly
  • No human intervention

Make your life easier



Make your systems easy to deploy

Integration Environment


Between Development and Production


Also called: preproduction, replica, build env


Enough data to run all tests

Populated with a script


Self-contained

Continuous Deployment


Too much of a good thing?


Shorten deployment cycles


Don't let changes accumulate


Stability increases (paradoxically!)

Test Before Deploying


Run all test suites

Verify results

Certify quality


A small but essential addition:

git pull
npm install
npm test
restart [service]

Practical Session 2


Create a deployment script


Run manual deployment


Run automatic deployment


Add Webhook to GitHub

Deployment package


Install deployment:

$ sudo npm install -g deployment


Parameters:

$ deployment-run --help
$ deployment-server --help

--testdir: integration directory

--dir: production directory

--exec: command to run

Run Deployments


Run local deployment:

 $ deployment-run --testdir .
--testdir: integration directory


Create deployment server:

 $ deployment-server --token ks9cfwyy862wf56a --testdir .
Access to run automatic deployment:

http://localhost:3470/deploy/ks9cfwyy862wf56a

GitHub WebHook


Access GitHub repo Settings


Go to Service Hooks


Add Webhook URLs

Success!



Rails Deployment


Run tests with rake test


Deployment with Capistrano


Local and remote deployment

Distributed

Deployment

From one Server to Many


Horizontal architecture


One deployment, many servers


Production: listen to signal


Integration: send signals

Overview


Travis-CI to the Rescue


Use Travis-CI as integration environment


Add a WebHook to the build


Notify all production servers


Notify hub that notifies servers

Practical Session 3


Teams with two IronHackers:

  • Integration server
  • Production server


Configure production server


Configure integration server


Run continuous deployment

Configure Production Server


Run deployment server:

 $ deployment-run --token production --dir .

Access server:

http://localhost:3470/deploy/production


Get production IP address:
 $ ifconfig

Configure Integration Server


Run integration server:

 $ URL="http://[prodIP]:3470/deploy/production"
$ deployment-run --token integration --testdir . --exec "wget $URL"

Upon completion notifies production.


Access server:
http://localhost:3470/deploy/integration


And watch it do its magic!

Success!


Bonus Track

MONITORING

Proactive Monitoring


Let alarms, alerts and warnings come to you


Every alarm must have:

  • A cause
  • An alert system
  • An action associated

Make your life easier



Make your systems easy to monitor

Practical Session 4


Watch notifications from a continuous deployment system


Watch a monitoring system in action


Watch how an alert is created

Thanks!


Questions?

Ironhack: Deployment (2013)

By Alex Fernández

Ironhack: Deployment (2013)

Continuous Deployment workshop for IronHack (2013 edition). Kept only for historical purposes; please access the latest edition at https://slid.es/alexfernandez/ironhack-deployment

  • 1,492
Loading comments...

More from Alex Fernández