ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)

2,888 views

Published on

http://www.zfconf.ru/2012/talks/capistrano-for-deployment-php-applications/

Published in: Technology, Design
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,888
On SlideShare
0
From Embeds
0
Number of Embeds
1,459
Actions
Shares
0
Downloads
17
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)

  1. 1. Capistrano длядеплоймента PHP приложений Рома Лапин, Evercode Lab@memphys, roma@evercodelab.com
  2. 2. 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/)
  3. 3. Обновить файлыОбновить базуСоздать файлы, папки, симлинкиВыставить праваСбросить кэшСохранить контентОткатиться в случае ошибки
  4. 4. FTP-клиентыVCS, hooksPhingShell scriptRsyncWePloy
  5. 5. SSHGit/SVN/Mercurial/...Server
  6. 6. © http://capifony.org/
  7. 7. ├── current -> /var/www/zf-capistrano/releases/20120414205035├── releases│   ├── 20120414204853│   │   ├── application│   │   ├── ...│   └── 20120414205035│   ├── application│   ├── ...└── shared ├── cached-copy │   ├── application │   ├── ... └── public └── uploads
  8. 8. $ gem install capistrano
  9. 9. $ cd ~/Sites/mycoolproject$ capify .[add] writing ./Capfile[add] making directory ./config[add] writing ./config/deploy.rb[done] capified!
  10. 10. config/deploy.rbset :application, "application_name"set :deploy_to, "/var/www/#{application}"
  11. 11. config/deploy.rbset :scm, :gitset :repository, "git@github.com:user/app.git"set :deploy_via, :remote_cacheset :branch, "master"set :keep_releases, 3
  12. 12. config/deploy.rbserver "domain", :app, :web, :db, :primary => trueset :ssh_options, {:forward_agent => true, :port => 22}set :user, "deployer"set :use_sudo, false
  13. 13. $ cap -h$ cap -T
  14. 14. config/deploy.rbnamespace :deploy do    task :start do    end    task :stop do    end    task :migrate do    end    task :restart do    endend
  15. 15. $ gem install railsless-deployCapfilerequire railsless-deployload config/deploy
  16. 16. $ cap deploy:setup$ cap deploy:check
  17. 17. $ cap deploy
  18. 18. $ cap deploy:update$ cap deploy:cleanup
  19. 19. $ cap deploy:rollback
  20. 20. Capfile (ZF1)load config/deploy
  21. 21. Capfile (ZF1)load config/deploy
  22. 22. Capfile (ZF1)load config/deployload application/configs/deploy
  23. 23. application/configs/deploy.rbnamespace :myproject do    task :symlink, :roles => :app do ...    endendafter "deploy:symlink", "myproject:symlink"
  24. 24. application/configs/deploy.rbnamespace :myproject do    task :symlink, :roles => :app do ...    endendafter "deploy:symlink", "myproject:symlink"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"
  25. 25. config/deploy.rb (ZF2)namespace :myproject do    task :symlink, :roles => :app do ...    endendafter "deploy:symlink", "myproject:symlink"
  26. 26. config/deploy.rb (ZF2)namespace :myproject do    task :symlink, :roles => :app do ...    endendafter "deploy:symlink", "myproject:symlink"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"
  27. 27. application/configs/deploy.rbnamespace :myproject do    task :uploads, :roles => :app do ...    endendafter "deploy:symlink", "myproject:symlink", "myproject:uploads"
  28. 28. application/configs/deploy.rbnamespace :myproject do    task :uploads, :roles => :app do ...    endendafter "deploy:symlink", "myproject:symlink", "myproject:uploads"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"
  29. 29. application/configs/deploy.rbtask :disable do ...endafter "deploy:update_code", "myproject:disable"
  30. 30. application/configs/deploy.rbtask :disable do ...endafter "deploy:update_code", "myproject:disable"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"
  31. 31. application/configs/deploy.rbtask :enable do ...endafter "deploy:symlink", "myproject:enable"
  32. 32. application/configs/deploy.rbtask :enable do ...endafter "deploy:symlink", "myproject:enable"run "rm -f #{latest_release}/public/maintenance.html"
  33. 33. application/configs/deploy.rbtask :migrate do ...endafter "deploy:finalize_update", "myproject:migrate"
  34. 34. application/configs/deploy.rbtask :migrate do ...endafter "deploy:finalize_update", "myproject:migrate"on_rollback { run "#{release_path}/bin/doctrine migrations:migrate down" }run "#{release_path}/bin/doctrine migrations:migrate"
  35. 35. application/configs/deploy.rbtask :unicornsandwizards do # notify by email # post to irc or group chat # send SMS # activate SkyNet # order some Pizzaendafter "deploy:finalize_update", "myproject:unicornsandwizards"
  36. 36. zf-capistrano https://github.com/memphys/zf-capistranozf2-capistrano https://github.com/memphys/zf2-capistranoCapistrano home https://github.com/capistrano/capistrano/wiki
  37. 37. MultistageCapifony (http://capifony.org)Webistrano
  38. 38. Спасибо за вниманиеРома ЛапинEvercode Labroma@evercodelab.com@memphys

×