1 # require 'capistrano/ext/multistage'
2 # require 'config/git-deployment'
4 # set :application, "deployment"
5 # set :repository, "ssh://repo.or.cz/srv/git/deployment-test.git"
7 # set :no_release, true
9 # set :stages, %w(devqa production)
10 # set :default_stage, "devqa"
11 # set :branch, "master"
13 # namespace :deploy do
16 # task :restart, :roles => :app, :except => { :no_release => true } do; end
24 require 'capistrano/ext/multistage'
25 require 'config/git-deployment'
27 set :stages, %w(devqa production)
28 set :default_stage, "devqa"
30 set :application, "deployment"
31 set :repository, "ssh://repo.or.cz/srv/git/deployment-test.git"
32 set :git_shallow_clone, 1
33 set :deploy_via, :copy
34 set :copy_strategy, :export
35 set :copy_comperssion, :gzip
38 set :group_writable, false
40 set :synchronous_connect, true
43 set :no_release, true # TODO
45 set :attachments_path, "attachments"
46 set :branch, begin branch rescue Grit::Repo.new(".").head.name || "master" end
49 # run "rm -r #{release_path}/#{attachments_path}"
50 # run "ln -nfs #{shared_path}/#{attachments_path} #{release_path}/#{attachments_path}"
53 def send_mail(from, from_alias, to, to_alias, subject, message)
54 msg = <<END_OF_MESSAGE
55 From: #{from_alias} <#{from}>
56 To: #{to_alias} <#{to}>
58 Content-Type: text/html; charset="utf-8"
63 Net::SMTP.start('mail.nodeta.fi', 25) do |smtp|
64 smtp.send_message msg, from, to
69 run "touch #{branch_path}"
70 return capture("cat #{branch_path}").chomp
74 run "echo '#{_branch}' > #{branch_path}"
78 capture("cat #{deploy_to}/current/REVISION").to_s.chomp
82 desc "Restart mod_rails"
83 task :restart, :roles => :app, :except => { :no_release => true } do
84 run "touch #{current_path}/tmp/restart.txt"
87 desc "Create attachments directory"
88 after :setup, :roles => [:web, :app] do
89 run "mkdir -p #{shared_path}/#{attachments_path}"
94 set :deployed, (get_deployed rescue nil)
98 set :current_branch, "master"
99 set :branch_path, "#{deploy_to}/current/BRANCH"
100 set :branch, "master" # force master on production
101 set :_branch, "master"
103 set :branch_path, "#{deploy_to}/current/BRANCH"
104 set :current_branch, (get_branch rescue "")
105 set :_branch, "master"
107 if current_branch != branch && !current_branch.empty?
108 c = Capistrano::CLI.ui.ask <<-eos
109 \e[31mCurrently deployed branch is \e[1m\e[4m\e[33m#{current_branch}\e[0m\e[31m. You are deploying \e[1m\e[4m\e[33m#{branch}\e[0m\e[31m.\e[0m
110 \e[31m\e[1mProceed? (yes/no)\e[0m
113 exit unless c == "yes"
122 # after :deploy, :"deploy:gems", :"deploy:minify", :"deploy:notify", :"deploy:cleanup", :"deploy:remove_test", :"deploy:run_at"
124 desc "Remove test.html"
126 # run "cd #{current_path}/public && rm test.html"
129 desc "Run JavaScript and CSS optimizers"
131 # require 'config/initializers/static_files'
133 # # Merge and minify CSS files
134 # run "cd #{current_path}; ruby -S juicer merge --force -d ./public -o public/stylesheets/application.min.css #{CSS_FILES.map{|f| "./public/stylesheets/#{f}.css"}.join(" ")}"
135 # # Merge and minify javascript files
136 # run "cd #{current_path}; ruby -S juicer merge --force -s -i -m none -o public/javascripts/application.min.js #{JS_FILES.map{|f| "./public/javascripts/#{f}.js"}.join(" ")}"
139 desc "Notify flow about deployment using email"
141 # repo = Grit::Repo.new(".")
142 # repo.remote_fetch("origin")
144 # if branch == current_branch
145 # message = "<p>The following changes were just deployed to #{host}:</p>"
146 # commits = repo.commits_between(deployed, repo.commit("origin/#{current_branch}").sha).reverse
148 # unless commits.empty?
149 # commits.each do |c|
150 # short, long = c.message.split(/\n+/, 2)
152 # message << "\n<div style=\"margin-bottom: 10px\"><div class=\"ui-corner-all\" style=\"background:url(http://gravatar.com/avatar/#{MD5::md5(c.author.email)}?s=30) no-repeat scroll center;height:30px;width:30px;float:left;margin-right:5px;\"> </div>"
153 # message << "<div style=\"padding-left: 35px;\">#{CGI.escapeHTML(short)}<br/>"
155 # long.gsub!(/\n/, '<br />')
156 # message << '<p style="margin:5px 0px; padding: 0 5px; border-left: 3px solid #ccc">' + long + '</p>'
158 # message << "<span style=\"font-size: 90%; color: #333\"><code>#{c.id_abbrev}</code> <a href=\"mailto:#{CGI.escapeHTML(c.author.email)}\">#{CGI.escapeHTML(c.author.name)}</a> on #{c.authored_date.strftime("%b %d, %H:%M")}</span></div></div>"
162 # message = "Branch #{branch} was deployed to #{host}. Previously deployed branch was #{current_branch}"
165 # config = Grit::Config.new(repo)
166 # send_mail(config["user.email"], config["user.name"], "flowdock@nodeta.tuntivirta.com", "Flowdock Team", "Flowdock Rails deployed #frontend #deploy ##{rails_env}", message)
169 desc "Update gems on remote server"
171 # run "cd #{current_path}; RAILS_ENV=#{rails_env} rake gems:install"
173 desc "Run migrations on remote server"
175 # run "cd #{current_path}; RAILS_ENV=#{rails_env} rake db:migrate"
178 desc "Tell Integrity on Pollux to run acceptance tests"
181 # Net::HTTP.new("gw.kutomotie.nodeta.fi", 880).start { |http|
182 # http.post("/flowdock-at/builds", nil)
187 desc "List pending commits since last deploy"
189 set :branch_path, "#{deploy_to}/current/BRANCH"
190 set :deployed, get_deployed
191 set :current_branch, get_branch
195 if branch != current_branch
196 HighLine.new.say <<-eos
197 Currently deployed branch is <%= color('#{current_branch.empty? ? 'unknown' : current_branch}', YELLOW+ON_RED) %>. Listing changes that would take effect when deploying differing branch <%= color('#{branch}', YELLOW+ON_RED) %> does not provide useful information.
199 Use '-s branch=<branch_name>' in command to compare non-master branch.
204 Capistrano::CLI.ui.ask <<-eos
205 Should you deploy <%= color('#{branch}', YELLOW+ON_RED) %> to <%= color('#{stage}', YELLOW+BOLD+UNDERLINE) %> (current branch: <%= color('#{current_branch.empty? ? 'unknown' : current_branch}', YELLOW+ON_RED) %>),
206 the following changes would take effect.
208 (Press any key to continue)
211 exec("git log #{deployed}..origin/#{branch}")