use >> instead of > for appending to sources.list
[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, "master"
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 -f #{release_path}/config/options.yml"
56     run "ln -s #{shared_path}/options.yml #{release_path}/config/options.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 soorun #{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 :restart do
77     run "touch #{current_path}/tmp/restart.txt"
78     run "sv restart /service/delayed_job_software"
79   end
80
81
82   desc "Send email notification of deployment"
83   task :notify do
84     #diff = `#{source.local.diff(current_revision)}`
85     begin
86       diff_log = `#{source.local.log( source.next_revision(current_revision) )}`
87     rescue
88       diff_log = "No REVISION found, probably initial deployment."
89     end
90     user = `whoami`
91     body = %Q[From: software-deploy@suse.de
92 To: #{deploy_notification_to.join(", ")}
93 Subject: software deployed by #{user}
94
95 Git log:
96 #{diff_log}]
97
98     Net::SMTP.start('relay.suse.de', 25) do |smtp|
99       smtp.send_message body, 'software-deploy@suse.de', deploy_notification_to
100     end
101   end
102   
103 end
104
105