Академический Документы
Профессиональный Документы
Культура Документы
Whiskey Media
Whiskey Sites
WSGIDaemonProcess my-site python-path=/home/code/ processes=2 threads=150 maximum-requests=5000 WSGIProcessGroup my-site WSGIScriptAlias / /home/code/my-site/deploy/wsgi/my-site.wsgi
MySQL
Percona @ www.mysqlperformanceblog.com
# 5 minutes
Basic Deployment
Copy Code & Media (rsync or scp) Run DB migrations / syncdb Bounce wsgi daemons
Deployment Reqs
Copy media to CDN Maintenance splash page Run DB migrations Install/Upgrade Python dependencies Add a new web server to the cluster Execute arbritrary commands for sysadmin maintenance tasks
Deployment Options
Capistrano
+ Out of box support for common use cases + Hooks to customize tasks + Source control integration + Threaded deployment to multiple hosts
- Ruby :(
Deployment Options
Fabric
+ Very simple, tasks are just Python functions + Easy to chain together tasks to create complex scripts out of bite size pieces - No source control integration - No out of box support - Some bugs, although fairly easy to work around, and new maintainer is working on fixes
Fabric Basics
sudo easy_install fabric need a fabfile.py from fabric.api import * be mindful of tasks that may fail each remote command starts fresh changing directories
Core Functionality
local() - Run a command locally run() - Run a command remotely sudo() - Run a command remotely as
another user
put() - Copy a file from local to remote get() - Copy a file from remote to local many more helper-ish commands
Authentication
Relies on SSH model Use SSH keys Control access to root user via sudoers When you have to revoke access, you just turn off their SSH account
Configuration
Fabric environment (env) -- it's just a dictionary
Hosts and Roles Code Repositories Whatever you need
~/fabricrc
Global settings or all Fabric deployments SSH username
Example Config
# fabfile.py from fabric.api import * env.roledefs = { 'web' : ['10.1.1.1', '10.1.1.2'], 'db' : ['10.1.1.3'], 'lb' : ['10.1.1.4'], } env.repositories = {...}
Tasks
# fabfile.py def uptime(): run('uptime')
$> fab uptime -H 10.1.1.3 [10.1.1.3] run: uptime [10.1.1.3] out: 05:20:39 up 88 days, 12:00, 0 users, load average: 0.03, 0.03, 0.00
Decorator Problems
Some problems with Fabric's role management Can't override decorated tasks at command line as docs suggest
def default_roles(*role_list): def selectively_attach(func): if not env.roles and not env.hosts: return roles(*role_list)(func) else: if env.hosts: func = hosts(*env.hosts)(func) if env.roles: func = roles(*env.roles)(func) return func
Easy sys-admin
Make an "invoke" command Great for sys-admin and one-off tasks
# fabfile.py @default_roles('all') def invoke(command): "Invoke an arbritrary command" sudo(command) # install new packages on all hosts in one command
bounce_wsgi_procs deploy deploy_media invoke migrate reload_nginx splash_off splash_on update_repositories update_dependencies
Bounce the WSGI procs by touching the files Full deployment Push media to S3 Invoke an arbritrary command Run any migrations via South Update Nginx's running config Configure Nginx to serve the site Configure Nginx to serve a downed-site page Push code to servers Update dependencies to third party libs
Whiskey's Deployment
def deploy(splash='no'): "Full deployment" deploy_media() update_cached_repositories() update_dependencies() generate_releases() if splash == 'yes': splash_on() _symlink_code() migrate() bounce_wsgi_procs() if splash == 'yes': splash_off()
Questions?