Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Capistrano for PHP Applications Deployment

Roma
April 22, 2012

Capistrano for PHP Applications Deployment

ZFConf 2012, 21.04.2012

Roma

April 22, 2012
Tweet

More Decks by Roma

Other Decks in Technology

Transcript

  1. If you cannot do your deployments with one command then

    you are DOING IT WRONG. Chris Hartjes, “Infrastructure Debt” (http:/ /www.littlehart.net/atthekeyboard/2011/11/03/infrastructure-debt/)
  2. Обновить файлы Обновить базу Создать файлы, папки, симлинки Выставить права

    Сбросить кэш Сохранить контент Откатиться в случае ошибки
  3. ᵓᴷᴷ current -> /var/www/zf-capistrano/releases/20120414205035 ᵓᴷᴷ releases ᴹ ᵓᴷᴷ 20120414204853 ᴹ

    ᴹ ᵓᴷᴷ application ᴹ ᴹ ᵓᴷᴷ ... ᴹ ᵋᴷᴷ 20120414205035 ᴹ ᵓᴷᴷ application ᴹ ᵓᴷᴷ ... ᵋᴷᴷ shared ᵓᴷᴷ cached-copy ᴹ ᵓᴷᴷ application ᴹ ᵓᴷᴷ ... ᵋᴷᴷ public ᵋᴷᴷ uploads
  4. $ cd ~/Sites/mycoolproject $ capify . [add] writing './Capfile' [add]

    making directory './config' [add] writing './config/deploy.rb' [done] capified!
  5. config/deploy.rb server "domain", :app, :web, :db, :primary => true set

    :ssh_options, {:forward_agent => true, :port => 22} set :user, "deployer" set :use_sudo, false
  6. namespace :deploy do task :start do end task :stop do

    end task :migrate do end task :restart do end end config/deploy.rb
  7. application/configs/deploy.rb namespace :myproject do task :symlink, :roles => :app do

    ... end end after "deploy:symlink", "myproject:symlink"
  8. application/configs/deploy.rb run "mkdir -p #{shared_path}/library" run "chmod -R 755 #{shared_path}/library"

    run "ln -nfs /path/to/zf/library/Zend #{shared_path}/library/Zend" run "ln -nfs #{shared_path}/library #{release_path}/library" namespace :myproject do task :symlink, :roles => :app do ... end end after "deploy:symlink", "myproject:symlink"
  9. config/deploy.rb (ZF2) namespace :myproject do task :symlink, :roles => :app

    do ... end end after "deploy:symlink", "myproject:symlink"
  10. config/deploy.rb (ZF2) run "mkdir -p #{shared_path}/vendor/ZendFramework/library" run "chmod -R 755

    #{shared_path}/vendor/ZendFramework/library" run "ln -nfs /path/to/ZendFramework-2.0.0beta3/library/Zend #{shared_path}/vendor/ ZendFramework/library/Zend" run "rm -rf #{release_path}/vendor" run "ln -nfs #{shared_path}/vendor #{release_path}/vendor" namespace :myproject do task :symlink, :roles => :app do ... end end after "deploy:symlink", "myproject:symlink"
  11. namespace :myproject do task :uploads, :roles => :app do ...

    end end after "deploy:symlink", "myproject:symlink", "myproject:uploads" application/configs/deploy.rb
  12. namespace :myproject do task :uploads, :roles => :app do ...

    end end after "deploy:symlink", "myproject:symlink", "myproject:uploads" application/configs/deploy.rb run "mkdir -p #{shared_path}/public/uploads" run "chmod -R 775 #{shared_path}/public/uploads" run "ln -nfs #{shared_path}/public/uploads #{release_path}/public/uploads"
  13. application/configs/deploy.rb run "echo 'Site is on maintenance right now. Sorry.'

    > #{shared_path}/public/ maintenance.html" run "cp #{shared_path}/public/maintenance.html #{latest_release}/public/ maintenance.html" task :disable do ... end after "deploy:update_code", "myproject:disable"
  14. task :migrate do ... end after "deploy:finalize_update", "myproject:migrate" application/configs/deploy.rb on_rollback

    { run "#{release_path}/bin/doctrine migrations:migrate down" } run "#{release_path}/bin/doctrine migrations:migrate"
  15. task :unicornsandwizards do # notify by email # post to

    irc or group chat # send SMS # activate SkyNet # order some Pizza end after "deploy:finalize_update", "myproject:unicornsandwizards" application/configs/deploy.rb