Why is deployment important?

  • The only place your code can truly be tested is in the live environment
  • Getting code into production code is the ultimate goal
  • ...apart from dying in glorious battle
  • "Great Artists ship" - Steve Jobs

History Lesson

  • FTP
  • LFTP mirror
  • SSH: rsync, svn up
  • Scripted deployment tools

"It's just dropping files on the server right?" - A. Producer

What else are we doing?

  • Tag release
  • Install packages / requirements
  • DB migrations
  • Clearing caches
  • Pushing static files to CDN
  • Minification, closure compiler, uglify
  • SaSS/Less compilation
  • Back-ups
  • Restarting services
  • Updating server configuration

WTF is Provisioning?

  • Infrastructure Management
  • Configuration as code
  • The automated creation of a fully configured server
  • Updating the configuration of a server
  • Done with a configuration management tool: Chef, Puppet, Salt
  • Overlaps with deployment

Scripted Deployments

  • Anyone can deploy
  • Requires a staging environment too
  • Replaces documentation (to an extent)

Deployment Tools

  • Shell scripts
  • Grunt
  • Fabric
  • Capistrano
  • Rake
  • Make
  • Chef
  • Rpm
  • Buildout

Which Deployment Tool to pick?

It depends.

Code Example 1: Basic Deployment

Code Example 2: Back-up Deployment

More flexibility, let's you choose which git commit to put live. Backs-up site.

2_backup_deploy.py

Code Example 3: Deploy to multiple servers

Code Example 3: Performance

server-1: deploy_code           5 seconds
server-1: install_requirements  20 seconds
server-1: backup_database       15 seconds
server-1: migrate_database      12 seconds
server-1: collectstatic         10 seconds
server-1: switch_release        1 second
server-1: reload_server         1 second
server-2: deploy_code           5 seconds
server-2: install_requirements  20 seconds
server-2: backup_database       15 seconds
server-2: migrate_database      12 seconds
server-2: collectstatic         10 seconds
server-2: switch_release        1 second
server-2: reload_server         1 second
            

Total time to deploy = 128 seconds

Code Example 3: Performance continued...

Problems:

  • Migrate database is run twice, this could be harmful with some operations
  • Potential Downtime
        Server-2 Potential Downtime is from migrate_database starts to reload_server
        Server-1 Potential Downtime = 12 + 10 + 1 + 1
                                                                = 24 seconds

        Server-2 Potential Downtime is from migrate_database starts (on server1) to reload_server on server-2
        Server-2 Potential Downtime = 64 + 24
                                                                = 88 seconds

        The more servers you have the longer the potential downtimes will become.
        Server-3 Potential Downtime = 24 + 64 + 64
                                                                = 152 seconds
        Server-4 Potential Downtime = 216 seconds
                

Code Example 4: Parallel deploy with roles

  • Have roles for servers, so some tasks are only performed by certain roles
  • Run deployments in parallel

4_multi_server_parallel.py

Code Example 4: Performance

server-1 + 2: deploy_code           5 seconds
server-1 + 2: install_requirements  20 seconds
server-1 + 2: backup_database       15 seconds
server-1: migrate_database      12 seconds
server-1 + 2: collectstatic         10 seconds
server-1 + 2: switch_release        1 second
server-1 + 2: reload_server         1 second
            

Total time to deploy = 64 seconds

Server-1 Potential Downtime = 24 seconds
Server-2 Potential Downtime = 24 seconds
Server-X Potential Downtime = 24 seconds
            

Code Example 5: Two step Deploy

Producer says 64 seconds is too long to have to wait to see those very important copy changes.

  • Split deployment into prepare deployment and activate deployment
  • Re-work packaging of code to stop crash when one server is much slower than the other.

Code Example 5: Performance

# Prepare deploy
server-1 + 2: deploy_code           5 seconds
server-1 + 2: install_requirements  20 seconds
server-1 + 2: backup_database       15 seconds
server-1 + 2: collectstatic         10 seconds

# Activate deploy
server-1: migrate_database      12 seconds
server-1 + 2: switch_release        1 second
server-1 + 2: reload_server         1 second
            

Total time to deploy = 64 seconds
Total time to activate deploy = 14 seconds

Server-1 Potential Downtime = 14 seconds
Server-2 Potential Downtime = 14 seconds
Server-X Potential Downtime = 14 seconds
            

Thank You!

Slides will be available online.