Top Banner
Pablo Godel @pgodel - codemiami.com Jan 12th 2013 - Miami, FL Rock Solid Deployment of Web Applications
71

Rock Solid Deployment of Web Applications

May 11, 2015

Download

Documents

Pablo Godel

Presentation given at CodeMiami 2013
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: Rock Solid Deployment of Web Applications

Pablo Godel @pgodel - codemiami.comJan 12th 2013 - Miami, FL

Rock Solid Deploymentof Web Applications

Page 2: Rock Solid Deployment of Web Applications

Who Am I?

⁃ Born in Argentina, living in the US since 1999⁃ PHP & Symfony developer

⁃ Founder of the original PHP mailing list in spanish ⁃ Co-founder of ServerGrove

Page 3: Rock Solid Deployment of Web Applications
Page 4: Rock Solid Deployment of Web Applications

⁃ Founded ServerGrove Networks in 2005

⁃ Provider of web hosting specialized in PHP, Symfony, ZendFramework, MongoDB and others

⁃ Servers in USA (right here in Miami) and Europe!

ServerGrove!

Page 5: Rock Solid Deployment of Web Applications

⁃ Very active open source supporter through codecontributions and usergroups/conference sponsoring

Community is our teacher

Page 6: Rock Solid Deployment of Web Applications

Deployment

?

Page 7: Rock Solid Deployment of Web Applications

Deployment

Software deployment is all of the activities that makea software system available for use.

http://en.wikipedia.org/wiki/Software_deployment

Page 8: Rock Solid Deployment of Web Applications

Deployment

A very important part of the application life-cycle

Page 9: Rock Solid Deployment of Web Applications

Deployment

A very important critical part of the application life-cycle

Page 10: Rock Solid Deployment of Web Applications

Deployment

It should not be an after thought

Page 11: Rock Solid Deployment of Web Applications

Deployment

It should be predictable

Page 12: Rock Solid Deployment of Web Applications

Deployment

The more you do it the better it goes

Page 13: Rock Solid Deployment of Web Applications
Page 14: Rock Solid Deployment of Web Applications

Deployment: Goals

Page 15: Rock Solid Deployment of Web Applications

Deployment: Goals

One-click deploys

Page 16: Rock Solid Deployment of Web Applications

Continuous deploys

Deployment: Goals

Page 17: Rock Solid Deployment of Web Applications

Web AppsDeployment

Page 18: Rock Solid Deployment of Web Applications

Web AppsDeployment

Page 19: Rock Solid Deployment of Web Applications

Web AppsDeployment

Page 20: Rock Solid Deployment of Web Applications

Anytime & Anywhere

Deployment: Goals

Page 21: Rock Solid Deployment of Web Applications

Anyone

Deployment: Goals

Page 22: Rock Solid Deployment of Web Applications

Reliable

Deployment: Goals

Page 23: Rock Solid Deployment of Web Applications

Rollbacks

Deployment: Goals

Page 24: Rock Solid Deployment of Web Applications

No downtime

Deployment: Goals

Page 25: Rock Solid Deployment of Web Applications

Reusable

Deployment: Goals

Page 26: Rock Solid Deployment of Web Applications

Scalable

Deployment: Goals

Page 27: Rock Solid Deployment of Web Applications

• One-click / continuous deploys• Anytime & Anywhere• Anyone • No downtime• Predictable & Reliable• Rollbacks• Reusable• Scalable

Deployment: Goals

Page 28: Rock Solid Deployment of Web Applications

Deployment Facts

Page 29: Rock Solid Deployment of Web Applications

Deployment: Fact #1

Deployment starts with the developer

• Setup development environment to be as close as possible to productions servers

• Setup test/qa/staging servers• Use Vagrant to manage VMs• Use Puppet/Chef to manage OS packages/

configuration

Page 30: Rock Solid Deployment of Web Applications

Deployment: Fact #2

Success linked to server OS setup

• Use Puppet/Chef to manage OS packages/configuration

• Create OS packages for 3rd party software• Setup your own package repositories

Page 31: Rock Solid Deployment of Web Applications

Deployment: Fact #3

Monitoring is uptime

• Use monitoring tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)

• Add monitoring and metrics to your app (Graphite, StatsD, New Relic)

• Use your logs wisely (Graylog, Logstash, Kibana)

Page 32: Rock Solid Deployment of Web Applications

Deployment Methodologies

Page 33: Rock Solid Deployment of Web Applications

Deployment Methodologies

• VIM-style• FTP uploads• rsync• source control (svn, git)• Build tools (ant, phing)• Specialized tools (capistrano, fabric, etc)• Package based (rpm, deb, etc)

Page 34: Rock Solid Deployment of Web Applications

Web Apps Deployment: Steps overview

Page 35: Rock Solid Deployment of Web Applications

Web Apps Deployment: First time

• Copy files to server(s)• Set server-side configurations• Load DB fixtures• Process and install assets• Warm up cache• “Enable” site

Page 36: Rock Solid Deployment of Web Applications

• Copy files to server(s)• Apply DB updates (migrations)• Process and install assets• Warm up cache• “Enable” site

Web Apps Deployment: Subsequent times

Page 37: Rock Solid Deployment of Web Applications

Deployment: Challenges

Page 38: Rock Solid Deployment of Web Applications

Deployment: Challenges

• rsync• git pull• setup git repo on local network to save

bandwidth and avoid issues if git server is down (i.e. github)

Challenge:Fast & reliable copy of files

Solutions:

Page 39: Rock Solid Deployment of Web Applications

Deployment: Challenges

• use a tool that allows to go from 1 to n servers easily (i.e. capistrano)

• pssh allows to send commands to n servers in parallel

• package your app in OS packages like .rpm/.deb to easily install across n servers

Challenge:Scalable

Solutions:

Page 40: Rock Solid Deployment of Web Applications

Deployment: Challenges

• test!• tag releases• dedicated branches (master for production)• deploy each release in its own directory

Challenge:Rollbacks

Solutions:

Page 41: Rock Solid Deployment of Web Applications

Deployment: Challenges

• use ssh based connections• don’t store passwords on source control• store sensitive strings (passwords) in server

environment variables

Challenge:Secure

Solutions:

Page 42: Rock Solid Deployment of Web Applications

Deployment: Challenges

Challenge:DB migrations

Solutions:• Doctrine Migrations• Consider document oriented DBs like

MongoDB

“The best migrations are the ones you don’t have to do”

Page 43: Rock Solid Deployment of Web Applications

Deployment: Challenges

Challenge:Static assets

Solutions:• YUICompress shrinks JS and CSS file sizes• Enable web server compression• Add versioning to static assets links (code.js?v=1)• Assetic combines multiple files into one• Run utilities locally or in a staging server, deploy

result

Page 44: Rock Solid Deployment of Web Applications

Deployment: Challenges

Challenge:Caching

Solutions:• Update one server while others handle load• Group servers and update group at a time• execute commands on “finalize” to clear up APC

cache

Page 45: Rock Solid Deployment of Web Applications

Deployment: Challenges

Challenge:File permission conflicts

Solutions:• Run Apache/PHP with same user• Use php-fpm instead of mod_php• Create “deploy” user and add web server to the

group• Use setfacl to give write access to multiple users

Page 46: Rock Solid Deployment of Web Applications

Web Apps Deployment: Other common pitfalls

Page 47: Rock Solid Deployment of Web Applications

Web Apps Deployment: Other common pitfalls

• Case sensitive filesystems• Configuration differences• Outdated 3rd party software• Github down

$ git daemon --base-path=/git/repo/path/ --export-all

$ git clone git://127.0.0.1/repo

http://ozmm.org/posts/when_github_goes_down.html

Page 48: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

Page 49: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

Simplest continuous deployment ever!

<?php

exec(‘/usr/bin/env -i HOME=/var/www git pull’);echo “All done!”;

hook.php

screenshot

Page 50: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

Capistrano

• Ruby based• Very extensible• Large number of extensions• Simple client side installation

$ gem install capistrano

Page 51: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

Capistrano

set :application, "myapp" # Application nameset :deploy_to, "/var/www/myapp"

set :user, "deployer"set :use_sudo, false # sudo isn't required

set :deploy_via, :remote_cache set :repository, "[email protected]:user/repo.git"

role :web, "server.example.com", “server2.example.com”

Page 52: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

$ cap deploy:setup

Capistrano

Page 53: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

|-- releases`-- shared |-- logs `-- uploads

Capistrano

Page 54: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

Capistrano

$ cap deploy$ cap deploy:migrations$ cap deploy:rollback

Page 55: Rock Solid Deployment of Web Applications

Web Apps Deployment: Examples

|-- current (symlink to releases/20130112)|-- releases| `-- 20130112`-- shared |-- logs `-- uploads

Capistrano

Page 56: Rock Solid Deployment of Web Applications

Web Apps Deployment:Other options

• Fabric• WePloy• Phing• Magallanes• Jenkins

Page 57: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

Page 58: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

App Metrics: StatsD & Graphite

Page 59: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

Logging: LogstashShip logs from any source, parse them, get the right timestamp, index them, and search them

Page 60: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

Logging: Logstash

Configure Apache to log jsonLogFormat "{ \"@timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \"@fields\": { \"client\": \"%a\", \"duration_usec\": %D, \"status\": %s, \"request\": \"%U%q\", \"method\": \"%m\", \"referrer\": \"%{Referer}i\" } }" logstash_json

# Write our 'logstash_json' logs to logs/access_json.logCustomLog logs/access_json.log logstash_json

{ "@timestamp": "2012-08-22T14:35:19-0700", "client": "127.0.0.1", "duration_usec": 532, "status": 404, "request": "/favicon.ico", "method": "GET", "referrer": "-" }

Result

Page 61: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

Logging: Graylog

Page 62: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

Logging: KibanaKibana is a user friendly way to view, search and visualize your log data

Page 63: Rock Solid Deployment of Web Applications

Web Apps Deployment: Tools

Packaging: fpm

https://github.com/jordansissel/fpm

Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity.

fpm -s dir -t rpm -n "myapp" -v 1.0 /var/www/myapp

fpm -s dir -t deb -a all -n myapp -v 1.0 /etc/apache2/conf.d/my.conf /var/www/myapp

Page 64: Rock Solid Deployment of Web Applications

Web Apps Deployment: Summary

Page 65: Rock Solid Deployment of Web Applications

•Stop using FTP

Page 66: Rock Solid Deployment of Web Applications

•Stop using FTP•Plan early

Page 67: Rock Solid Deployment of Web Applications

•Stop using FTP•Plan early•Practice

Page 68: Rock Solid Deployment of Web Applications

•Stop using FTP•Plan early•Practice•Monitor

Page 69: Rock Solid Deployment of Web Applications

•Stop using FTP•Plan early•Practice•Monitor•AUTOMATE!

Page 70: Rock Solid Deployment of Web Applications

QUESTIONS?

Slides: http://slideshare.net/pgodelTwitter: @pgodel

E-mail: [email protected]

Page 71: Rock Solid Deployment of Web Applications

Thank you!

Slides: http://slideshare.net/pgodelTwitter: @pgodel

E-mail: [email protected]