use the whole section line for showing/hiding content
[opensuse:software-o-o.git] / config / deploy.rb
1 require 'net/smtp'
2
3 set :application, "software"
4
5 # git settings
6 set :scm, :git
7 set :repository,  "git://gitorious.org/opensuse/software-o-o.git"
8 set :branch, "master"
9 set :deploy_via, :remote_cache
10 set :git_enable_submodules, 1
11 set :migrate_target, :current
12
13 set :deploy_notification_to, ['tschmidt@suse.de', 'coolo@suse.de']
14 server "buildserviceapi.suse.de", :app, :web, :db, :primary => true
15
16 # If you aren't deploying to /u/apps/#{application} on the target
17 # servers (which is the default), you can specify the actual location
18 # via the :deploy_to variable:
19 set :deploy_to, "/srv/www/vhosts/opensuse.org/#{application}"
20 set :static, "software.o.o"
21
22 # set variables for different target deployments
23 task :stage do
24   set :deploy_to, "/srv/www/vhosts/opensuse.org/stage/#{application}"
25   set :branch, "derivates"
26   set :static, "software.o.o-stage/stage"
27 end
28
29
30 ssh_options[:forward_agent] = true
31 default_run_options[:pty] = true
32 set :normalize_asset_timestamps, false
33
34 # tasks are run with this user
35 set :user, "root"
36 # spinner is run with this user
37 set :runner, "root"
38
39 after "deploy:update_code", "config:symlink_shared_config"
40 after "deploy:update_code", "config:sync_static"
41 after "deploy:symlink", "config:permissions"
42 after "deploy:finalize_update", "deploy:notify"
43
44 after :deploy, 'deploy:cleanup' # only keep 5 releases
45
46
47 namespace :config do
48
49   desc "Install saved configs from /shared/ dir"
50   task :symlink_shared_config do
51     run "rm #{release_path}/config/environments/production.rb"
52     run "ln -s #{shared_path}/production.rb #{release_path}/config/environments/"
53     run "rm -f #{release_path}/config/database.yml"
54     run "ln -s #{shared_path}/database.yml #{release_path}/config/database.yml"
55     run "rm -r #{release_path}/tmp/cache"
56     run "ln -s #{shared_path}/software.o.o.cache #{release_path}/tmp/cache"
57   end
58
59   desc "Set permissions"
60   task :permissions do
61     run "chown -R soorun #{current_path}/db #{current_path}/tmp #{current_path}/tmp/cache/ #{current_path}/log #{current_path}/public"
62   end
63
64   desc "Sync public to static.o.o"
65   task :sync_static do
66     `rsync  --delete-after --exclude=themes -av --no-p public/ -e 'ssh -p2212' proxy-opensuse.suse.de:/srv/www/vhosts/static.opensuse.org/hosts/#{static}`
67     # Secondary (high-availability) VM for static needs the same content
68     `rsync  --delete-after --exclude=themes -av --no-p public/ -e 'ssh -p2213' proxy-opensuse.suse.de:/srv/www/vhosts/static.opensuse.org/hosts/#{static}`
69   end
70 end
71
72 # server restarting
73 namespace :deploy do
74   task :restart do
75     run "touch #{current_path}/tmp/restart.txt"
76     run "sv restart /service/delayed_job_software"
77   end
78
79
80   desc "Send email notification of deployment"
81   task :notify do
82     #diff = `#{source.local.diff(current_revision)}`
83     begin
84       diff_log = `#{source.local.log( source.next_revision(current_revision) )}`
85     rescue
86       diff_log = "No REVISION found, probably initial deployment."
87     end
88     user = `whoami`
89     body = %Q[From: software-deploy@suse.de
90 To: #{deploy_notification_to.join(", ")}
91 Subject: software deployed by #{user}
92
93 Git log:
94 #{diff_log}]
95
96     Net::SMTP.start('relay.suse.de', 25) do |smtp|
97       smtp.send_message body, 'software-deploy@suse.de', deploy_notification_to
98     end
99   end
100   
101 end
102
103