Andreas Klunker – 15.12.2014
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Shiny new code</title>
...
↓$ git commit && git push
↓$ cap staging|production deploy
rzbvm005:/opt/raw_live/current -> /opt/raw_live/releases/20141211171712
/releases/20141211171712
/20141110092656
/20140829114502
/shared/foo
/bar
$ mkdir releases/[DATUMUHRZEIT]
$ git clone /opt/raw.git releases/[DATUMUHRZEIT]
$ ln -s releases/[DATUMUHRZEIT] current
$ ln -s shared/spot_of_the_week current/spot_of_the_week
$ gem install capistrano
$ cd projektverzeichnis/
$ cap install
├── Capfile
├── config
│ ├── deploy
│ │ ├── production.rb
│ │ └── staging.rb
│ └── deploy.rb
└── lib
└── capistrano
└── tasks
set :application, 'raw'
set :repo_url, "kaa01744@rzbvm005:/opt/raw.git"
set :keep_releases, 5
# targets for symlinks
set :img_symlink_target, '/opt/raw_live/shared/images/'
set :txt_symlink_target, '/opt/raw_live/shared/text/'
set :sotw_symlink_target, '/opt/raw_live/shared/spot_of_the_week/'
namespace :deploy do
desc "make a symlink for images, texts and spot of the week dirs"
task :symlink do
on roles(:all) do
execute "ln -s #{fetch(:img_symlink_target)} #{fetch(:img_symlink_name)}; true"
execute "ln -s #{fetch(:txt_symlink_target)} #{fetch(:txt_symlink_name)}; true"
execute "ln -s #{fetch(:sotw_symlink_target)} #{fetch(:sotw_symlink_name)}; true"
end
end
desc "make release dir writable for group, chmod files that need to be writable"
task :chmod do
on roles(:all) do
execute "chmod -R g+w #{File.join(fetch(:deploy_to), 'releases')}; true"
execute "chgrp raw #{File.join(fetch(:deploy_to), 'releases')} -R; true"
execute "chmod o+rw #{fetch(:writable_file)}; true"
end
end
after :finishing, 'deploy:cleanup'
after :finishing, 'deploy:symlink'
after :finishing, 'deploy:chmod'
end
# call: cap staging deploy
set :stage, :staging
server 'rzbvm005', roles: %w{web app db}, port: 22
set :deploy_to, '/opt/raw_test'
set :branch, 'raw_ng'
# linknames for symlinks
# images
set :img_symlink_name, '/var/www/raw_test/images'
# texts
set :txt_symlink_name, '/var/www/raw_test/text'
#spot of the week
set :sotw_symlink_name, '/var/www/raw_test/spot_of_the_week'
# file that needs to be writable by webserver
set :writable_file, '/var/www/raw_test/admin/export.xls'
# call: cap production deploy
set :stage, :production
server 'rzbvm005', roles: %w{web app db}, port: 22
set :deploy_to, '/opt/raw_live'
set :branch, 'master'
# linknames for symlinks
# images
set :img_symlink_name, '/var/www/raw_live/images'
# texts
set :txt_symlink_name, '/var/www/raw_live/text'
#spot of the week
set :sotw_symlink_name, '/var/www/raw_live/spot_of_the_week'
# file that needs to be writable by webserver
set :writable_file, '/var/www/raw_live/admin/export.xls'
$ cap production deploy:rollback