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