Capistrano for PHP Applications Deployment
-
Upload
roman-lapin -
Category
Technology
-
view
4.192 -
download
2
description
Transcript of Capistrano for PHP Applications Deployment
![Page 2: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/2.jpg)
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/)
![Page 3: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/3.jpg)
Обновить файлы
Обновить базу
Создать файлы, папки, симлинки
Выставить права
Сбросить кэш
Сохранить контент
Откатиться в случае ошибки
![Page 4: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/4.jpg)
![Page 5: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/5.jpg)
FTP-клиенты
VCS, hooks
Phing
Shell script
Rsync
WePloy
![Page 6: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/6.jpg)
![Page 7: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/7.jpg)
SSH
Git/SVN/Mercurial/...
Server
![Page 9: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/9.jpg)
├── current -> /var/www/zf-capistrano/releases/20120414205035
├── releases
│ ├── 20120414204853
│ │ ├── application
│ │ ├── ...
│ └── 20120414205035
│ ├── application
│ ├── ...
└── shared
├── cached-copy
│ ├── application
│ ├── ...
└── public
└── uploads
![Page 10: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/10.jpg)
$ gem install capistrano
![Page 11: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/11.jpg)
$ cd ~/Sites/mycoolproject$ capify .[add] writing './Capfile'[add] making directory './config'[add] writing './config/deploy.rb'[done] capified!
![Page 12: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/12.jpg)
config/deploy.rb
set :application, "application_name"set :deploy_to, "/var/www/#{application}"
![Page 13: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/13.jpg)
config/deploy.rb
set :scm, :gitset :repository, "[email protected]:user/app.git"set :deploy_via, :remote_cacheset :branch, "master"set :keep_releases, 3
![Page 14: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/14.jpg)
config/deploy.rb
server "domain", :app, :web, :db, :primary => trueset :ssh_options, {:forward_agent => true, :port => 22}set :user, "deployer"set :use_sudo, false
![Page 15: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/15.jpg)
$ cap -h$ cap -T
![Page 16: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/16.jpg)
namespace :deploy do task :start do end
task :stop do end
task :migrate do end
task :restart do end end
config/deploy.rb
![Page 17: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/17.jpg)
$ gem install railsless-deploy
Capfile
require 'railsless-deploy'load 'config/deploy'
![Page 18: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/18.jpg)
$ cap deploy:setup$ cap deploy:check
![Page 19: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/19.jpg)
$ cap deploy
![Page 20: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/20.jpg)
![Page 21: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/21.jpg)
$ cap deploy:update$ cap deploy:cleanup
![Page 22: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/22.jpg)
![Page 23: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/23.jpg)
$ cap deploy:rollback
![Page 24: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/24.jpg)
![Page 25: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/25.jpg)
Capfile (ZF1)
load 'config/deploy'
![Page 26: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/26.jpg)
Capfile (ZF1)
load 'config/deploy'
![Page 27: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/27.jpg)
Capfile (ZF1)
load 'application/configs/deploy'
load 'config/deploy'
![Page 28: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/28.jpg)
application/configs/deploy.rb
namespace :myproject do task :symlink, :roles => :app do
... endend
after "deploy:symlink", "myproject:symlink"
![Page 29: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/29.jpg)
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
... endend
after "deploy:symlink", "myproject:symlink"
![Page 30: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/30.jpg)
config/deploy.rb (ZF2)
namespace :myproject do task :symlink, :roles => :app do
... endend
after "deploy:symlink", "myproject:symlink"
![Page 31: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/31.jpg)
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
... endend
after "deploy:symlink", "myproject:symlink"
![Page 32: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/32.jpg)
namespace :myproject do task :uploads, :roles => :app do
... endend
after "deploy:symlink", "myproject:symlink", "myproject:uploads"
application/configs/deploy.rb
![Page 33: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/33.jpg)
namespace :myproject do task :uploads, :roles => :app do
... endend
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"
![Page 34: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/34.jpg)
application/configs/deploy.rb
task :disable do...
end
after "deploy:update_code", "myproject:disable"
![Page 35: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/35.jpg)
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"
![Page 36: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/36.jpg)
application/configs/deploy.rb
task :enable do...
end
after "deploy:symlink", "myproject:enable"
![Page 37: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/37.jpg)
application/configs/deploy.rb
run "rm -f #{latest_release}/public/maintenance.html"
task :enable do...
end
after "deploy:symlink", "myproject:enable"
![Page 38: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/38.jpg)
task :migrate do...
end
after "deploy:finalize_update", "myproject:migrate"
application/configs/deploy.rb
![Page 39: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/39.jpg)
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"
![Page 40: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/40.jpg)
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
![Page 41: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/41.jpg)
zf-capistrano
https://github.com/memphys/zf-capistrano
zf2-capistrano
https://github.com/memphys/zf2-capistrano
Capistrano home
https://github.com/capistrano/capistrano/wiki
![Page 43: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/43.jpg)
![Page 44: Capistrano for PHP Applications Deployment](https://reader038.fdocument.pub/reader038/viewer/2022102722/554a4fd2b4c9054b328b46e7/html5/thumbnails/44.jpg)
Спасибо за внимание
Рома ЛапинEvercode Lab
@memphys