YACS | Sessions

Continuous Integration & Delivery

Featuring...

Continuous Integration

  • Motivation:
    • Find errors quickly
    • Minimize conflicts
  • "Push Early, Fail Often"
  • Building / Testing should be automated
    • Travis-CI, Jenkins, etc...
    • Yes, you need to have tests
  • Ideally, every commit should be built
    • In practice, this is often done every PR instead of every commit due to long / intensive builds
      • PRs should be as small and atomic as possible
    • Forces the developer to write small, functional, tested increments

In Practice...

The Config

# .travis.yml

language: ruby
rvm:
  - 2.2.3
before_script:
  - psql -c 'create database "yacs-test";' -U postgres

In your project...

In your settings...

Travis-CI + Github makes this very easy with pre-build integrations

Travis uses helpful sane defaults, simplifying config

The PR

The Build

The Pass

The Review

Continuous Delivery & Continuous Deployment

'What is these tests? Where are my deploy?'

CD - What and Why?

  • Applies the principles from CI to deployment
  • Ensures the state of the app is always shippable
    • Requires testing in a production-like environment ('staging')
  • Introduces automated deployment
    • Continuous Delivery: Manual deployment to production
    • Continuous Deployment: Automated deployment to production with every update

Continuous Delivery

  • Ensures the state of the app is always shippable
    • Requires testing in a production-like environment ('staging')

Pull Request

Automated Testing

Deploy to Staging

Acceptance Testing

Deploy to Production

Auto

Auto

Auto

Manual

  • After acceptance testing, deploying to production is manual
    • Is not mandator to deploy every update
  • This model is universally applicable

Listen to Your Heart

With a little creativity, we can make a simple Github integration

We're using the same system as Heroku's auto-deploy and Slack's notifications

Github will POST to the provided address whenever a branch is updated

Listen to the Rain

# deploy_server.rb

require 'sinatra'

post '/deploy' do
  if verify_webhook(request: request, secret: 'GET CREATIVE')
    system('sh ../app/deploy.sh')
  end
end

# deploy.sh

puma_ctl stop

git pull

mkdir -p ./tmp/pids/puma

bundle exec rake db:create db:migrate
bundle exec rake assets:precompile
puma_ctl start
  1. Check out the branch
  2. Run the deploy server
  3. Profit!!

Our Model Now...

True Continuous Deployment

Pull Request

Automated Testing

Deploy to Staging

Acceptance Testing

Deploy to Production

git checkout staging
ruby deploy_server.rb &

Staging Server

git checkout master
ruby deploy_server.rb &

Production Server

Auto

Auto

Auto

Auto

The only manual action is the merging of the pull requests

  • Development => Staging
  • Staging => Master (production)

Some Problems...

  • My passing tests are failing!
    • Bad
  • My failing tests are passing!
    • Worse
  • Too Many Cooks
    • App server, File Server, Workers, Database, Cache, K/V Store, Search, ...
  • I Installed 2 versions of postgresql... Help me!!!
  • Native extensions won't compile in production!
  • The solution: Containers 
    • Later: Dockerizing your app

THANK YOU

Dr. Krishnamoorthy

Dr. Goldschmidt

Dr. Turner

Red Hat

Sean O'Sullivan

Our Mentors!

The YACS team!

Sources:

DigitalOcean

Heroku

Github

Docker

Travis-CI

Agile Alliance

Useful Links:

YACS | Sessions - CI & CD

By Ada Young

YACS | Sessions - CI & CD

A short introduction to Continuous Integration and Continuous Deployment

  • 444