RC1 is public
[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 public/ -e 'ssh -p2212' 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 :start do
75     run "sv start /service/#{runit_name}-*"
76   end
77
78   task :restart do
79     run "for i in /service/#{runit_name}-*; do sv restart $i; sleep 3; done"
80   end
81
82   task :stop do
83     run "sv stop /service/#{runit_name}-*"
84   end
85
86
87   desc "Send email notification of deployment"
88   task :notify do
89     #diff = `#{source.local.diff(current_revision)}`
90     begin
91       diff_log = `#{source.local.log( source.next_revision(current_revision) )}`
92     rescue
93       diff_log = "No REVISION found, probably initial deployment."
94     end
95     user = `whoami`
96     body = %Q[From: software-deploy@suse.de
97 To: #{deploy_notification_to.join(", ")}
98 Subject: software deployed by #{user}
99
100 Git log:
101 #{diff_log}]
102
103     Net::SMTP.start('relay.suse.de', 25) do |smtp|
104       smtp.send_message body, 'software-deploy@suse.de', deploy_notification_to
105     end
106   end
107   
108 end
109
110