Permalink
Browse files

Updating deployment scripts

  • Loading branch information...
1 parent 8da2373 commit 050401d30aae541e5cb760a4c7b6ee493a3b9626 @Altonymous Altonymous committed Mar 11, 2013
View
3 Gemfile
@@ -22,8 +22,9 @@ gem 'torquebox-rake-support', torquebox_version
gem 'torquebox', torquebox_version
gem 'padrino-rpm', git: 'https://github.com/6fusion/padrino-rpm.git'
-group :development do
+group :development, :test do
gem 'trinidad'
+ gem 'colorize'
gem 'capistrano'
gem 'capistrano-ext'
gem 'capistrano_colors'
View
12 Gemfile.lock
@@ -13,7 +13,7 @@ GIT
GIT
remote: https://github.com/padrino/padrino-framework.git
- revision: 2eb060ab502a5f9aa520ec56f876bda248ae460b
+ revision: c7c3e4e1a4383cc0fe7255596113fb089fffc283
branch: master
specs:
padrino (0.10.7)
@@ -32,7 +32,7 @@ GIT
padrino-core (0.10.7)
activesupport (>= 3.1.0)
http_router (~> 0.10.2)
- sinatra (~> 1.3.1)
+ sinatra (~> 1.3.5)
thor (~> 0.16.0)
tilt (~> 1.3.0)
padrino-gen (0.10.7)
@@ -70,6 +70,7 @@ GEM
git
tinder
capistrano_colors (0.5.5)
+ colorize (0.5.8)
diff-lcs (1.2.1)
edn (1.0.0)
parslet (~> 1.4.0)
@@ -102,7 +103,7 @@ GEM
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.21)
- mocha (0.13.2)
+ mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.6.1)
multipart-post (1.2.0)
@@ -142,7 +143,7 @@ GEM
tilt (~> 1.3, >= 1.3.3)
systemu (2.5.2)
thor (0.16.0)
- tilt (1.3.4)
+ tilt (1.3.5)
tinder (1.8.0)
activesupport (>= 2.3, < 4)
eventmachine (~> 0.12)
@@ -192,7 +193,7 @@ GEM
trinidad (1.4.4)
jruby-rack (>= 1.1.10)
trinidad_jars (>= 1.1.0)
- trinidad_jars (1.2.1)
+ trinidad_jars (1.2.2)
twitter-stream (0.1.16)
eventmachine (>= 0.12.8)
http_parser.rb (~> 0.5.1)
@@ -213,6 +214,7 @@ DEPENDENCIES
capistrano-ext
capistrano-helpers
capistrano_colors
+ colorize
haml
jruby-rack
json-jruby
View
127 config/deploy.rb
@@ -1,10 +1,12 @@
+require 'colorize'
require 'capistrano/ext/multistage'
require 'capistrano_colors'
require 'capistrano-helpers/specs'
require 'capistrano-helpers/version'
require 'bundler/capistrano'
require 'open-uri'
require 'rest_client'
+require 'new_relic/recipes'
default_run_options[:pty] = true
@@ -15,9 +17,9 @@
# set :bundle_dir, fetch(:shared_path)+"/bundle"
# set :bundle_flags, "--deployment --quiet"
-set :application, "adaptor-vmware"
-set :user, "deploy"
-set :group, "deploy"
+set :application, `git remote -v`[/([\w-]+)\.git\s\(fetch\)/,1]
+set :user, 'deploy'
+set :group, 'deploy'
set :ssh_options, { forward_agent: true }
set :scm, "git"
@@ -26,28 +28,30 @@
set :branch, ENV['TAG'] || ENV['BRANCH'] || `git branch --no-color 2> /dev/null`.chomp.split("\n").grep(/^[*]/).first[/(\S+)$/, 1]
set :deploy_to, "/var/6fusion/#{application}"
set :deploy_via, :remote_cache
-set :deploy_env, lambda { fetch(:stage) }
set :rails_env, lambda { fetch(:stage) }
set :keep_releases, 2
-set :tail_logs_location, "/var/log/torquebox/torquebox.log"
+set :tail_logs_location, "#{shared_path}/log/#{application}.log"
set :context_path, ""
-set :hipchat_alert, true
-set :use_default_branch, ENV['USE_DEFAULT_BRANCH'] || false
+set :hipchat_alert, ENV['HIPCHAT_ALERT'] || true
set :password, ENV['PASSWORD'] if ENV['PASSWORD']
+set :tag, `git branch --no-color 2> /dev/null`.chomp.split("\n").grep(/^[*]/).first[/(\S+)$/, 1]
+set :current_branch, nil
+set :current_version, nil
# Adaptor-VMware Specifics
set :ssh_port, 22
set :copy_exclude do
%w{Capfile Vagrantfile README.* spec config/deploy.rb
config/deploy .rvmrc .rspec data .git .gitignore **/test.* .yardopts} +
- (stages - [deploy_env]).map { |e| "**/#{e}.*" }
+ (stages - [rails_env]).map { |e| "**/#{e}.*" }
end
# Additional Deployment Actions
-before "verify:rules", "build:get_tag"
before "deploy", "verify:rules"
-after "deploy:cleanup", "alert:hipchat"
+after "verify:rules", "hipchat:start"
+after "deploy:cleanup", "hipchat:finish"
+after "deploy:cleanup", "newrelic:notice_deployment"
after("deploy") do
# Setup data directory
@@ -75,8 +79,14 @@
run "#{sudo} chmod 0755 #{current_path}/tmp"
run "#{sudo} chown -R torquebox:torquebox #{current_path}/tmp"
+ # Add the commit SHA to the VERSION file
+ deploy.update_version
+
# Deploy the application
- run "#{sudo} torquebox deploy #{current_path} --name #{application} --env #{deploy_env} --context-path=#{context_path}"
+ torquebox.deploy
+
+ # Setup New Relic
+ run "if [ -f #{shared_path}/newrelic.yml ]; then #{sudo} ln -sfn #{shared_path}/newrelic.yml #{current_path}/config; fi"
deploy.cleanup
end
@@ -87,72 +97,82 @@
end
after("deploy:rollback") do
- run "#{sudo} torquebox undeploy #{current_path} --name #{application}"
+ torquebox.undeploy
+end
+
+namespace :deploy do
+ task :update_version do
+ puts "*** executing \"git log origin/#{tag} | head -1\"".yellow
+ latest_commit_sha = `git log origin/#{tag} | head -1`.gsub("commit ", "")
+
+ run "#{sudo} sed -i -e '$a\\' #{release_path}/VERSION && #{sudo} echo -n \"#{latest_commit_sha}\" >> #{release_path}/VERSION"
+ end
end
namespace :verify do
+ task :branch, roles: :app do
+ current_branch = capture("#{sudo} cat #{deploy_to}/current/VERSION || true").split("\r\n").reject(&:empty?).first
+ puts "*** '#{current_branch}' branch is currently deployed to #{rails_env}.".light_blue
+
+ current_branch
+ end
+
+ task :version, roles: :app do
+ current_version = capture("#{sudo} cat #{deploy_to}/current/VERSION || true").split("\r\n").reject(&:empty?).last
+ puts "*** '#{current_version}' commit is currently deployed to #{rails_env}.".light_blue
+
+ current_version
+ end
+
task :rules, roles: :app do
+ puts "*** Verifying you are allowed to deploy this branch to this environment.".light_blue
+
next if stage == :development
if tag == "master"
- puts "Skipping verification since you are deploying master."
+ puts "*** Skipping verification since you are deploying master.".light_blue
next
end
- deployed_branch = capture("#{sudo} cat #{deploy_to}/current/VERSION || true").split("\r\n").last
+ deployed_branch = verify.branch
+ deployed_version = verify.version
next if deployed_branch.nil? || deployed_branch.empty? || deployed_branch.include?('No such file or directory')
- puts "'#{deployed_branch}' branch is currently deployed to #{rails_env}."
-
if deployed_branch == tag
- puts "Skipping verification since you are deploying the same branch."
+ puts "*** Skipping verification since you are deploying the same branch.".light_blue
next
end
if deployed_branch == "master"
- puts "Skipping verification since master is currently deployed."
+ puts "*** Skipping verification since master is currently deployed.".light_blue
next
end
- puts "Updating local commit logs to check the status of the found commit."
+ puts "*** Updating local commit logs to check the status of the found commit.".light_blue
`git fetch origin`
- puts "Looking at master branch to determine if commit exists."
- branches = `git branch -r --contains #{deployed_branch}`.split(/\r\n|\n/).map { |branch| branch.strip! }
+ puts "*** Looking at master branch to determine if commit exists.".light_blue
+ branches = `git branch -r --contains #{deployed_version}`.split(/\r\n|\n/).map { |branch| branch.strip! }
unless branches.include?('origin/master') || branches.include?("origin/#{tag}")
- action_requested = Capistrano::CLI.ui.ask "If you continue deploying this branch you will be overwriting someone else's work. Would you like to [c]ontinue, [s]top, or [r]eset the environment back to master? [stop]: "
+ action_requested = Capistrano::CLI.ui.ask "*** If you continue deploying this branch you will be overwriting someone else's work. Would you like to [c]ontinue, [s]top, or [r]eset the environment back to master? [stop]: ".red
case action_requested.to_s
when "c"
- puts "Overriding default rules and deploying your branch, you evil evil coder. You were warned!"
+ puts "*** Overriding default rules and deploying your branch, you evil evil coder. You were warned!".red
next
when "r"
- puts "Reseting the environment to master."
+ puts "*** Reseting the environment to master.".light_blue
set :tag, "master"
else
- puts "Aborting deploy..."
+ puts "*** Aborting deploy...".red
abort = true
end
end
- abort "Since #{deployed_branch} is currently deployed to #{rails_env}. Please either merge #{deployed_branch} to master OR re-deploy either #{deployed_branch} or master branch to this environment." unless branches.include?('origin/master') || branches.include?("origin/#{tag}") if abort
- puts "All rules have passed, continuing with deployment."
- end
-end
-
-namespace :build do
- task :get_tag, roles: :builder do
- default_tag = `git branch --no-color 2> /dev/null`.chomp.split("\n").grep(/^[*]/).first[/(\S+)$/, 1]
-
- unless use_default_branch
- branch_tag = Capistrano::CLI.ui.ask "Branch/Tag to deploy (make sure to push the branch/tag to origin first) [#{default_tag}]: "
- end
-
- branch_tag = default_tag if branch_tag.to_s == ''
-
- set :tag, branch_tag
+ abort "*** Since #{deployed_branch} is currently deployed to #{rails_env}. Please either merge #{deployed_branch} to master OR re-deploy either #{deployed_branch} or master branch to this environment.".red unless branches.include?('origin/master') || branches.include?("origin/#{tag}") if abort
+ puts "*** All rules have passed, continuing with deployment.".light_blue
end
end
@@ -161,11 +181,11 @@
task :tail, roles: :app do
run "tail -f #{tail_logs_location}" do |channel, stream, data|
data.split("\n").each do |line|
- puts "[#{channel[:host]}] #{line}"
+ puts "*** [#{channel[:host]}] #{line}".light_blue
end
break if stream == :err
end
- puts
+ puts.light_blue
end
desc 'truncate logs'
@@ -202,7 +222,7 @@
desc 'deploy application'
task :deploy, roles: :app do
- run "#{sudo} torquebox deploy #{current_path} --name #{application} --env #{deploy_env}"
+ run "#{sudo} torquebox deploy #{current_path} --name #{application} --env #{rails_env} --context-path=#{context_path}"
sleep 2
run "#{sudo} test ! -f /opt/torquebox/jboss/standalone/deployments/#{application}-knob.yml.failed"
end
@@ -219,14 +239,26 @@
end
end
-namespace :alert do
+namespace :hipchat do
+ desc 'Alert Hipchat development room of deployment starting'
+ task :start, roles: :app do
+ if hipchat_alert
+ hipchat_token = "06e70aeee31facbcbedafa466f5a90"
+ hipchat_url = URI.escape("https://api.hipchat.com/v1/rooms/message?format=json&auth_token=#{hipchat_token}")
+ message = "@#{ENV['USER']} is deploying #{branch} of #{application} to #{stage}"
+ RestClient.post(hipchat_url, { room_id: "#{stage}", from: "DeployBot", color: "green", message_format: "text", message: message })
+ RestClient.post(hipchat_url, { room_id: "Deployments", from: "DeployBot", color: "green", message_format: "text", message: message })
+ end
+ end
+
desc 'Alert Hipchat development room of successful deploy'
- task :hipchat, roles: :app do
+ task :finish, roles: :app do
if hipchat_alert
hipchat_token = "06e70aeee31facbcbedafa466f5a90"
hipchat_url = URI.escape("https://api.hipchat.com/v1/rooms/message?format=json&auth_token=#{hipchat_token}")
message = "@#{ENV['USER']} deployed #{branch} of #{application} to #{stage}"
- RestClient.post(hipchat_url, { room_id: "59147", from: "DeployBot", color: "green", message_format: "text", message: message })
+ RestClient.post(hipchat_url, { room_id: "#{stage}", from: "DeployBot", color: "green", message_format: "text", message: message })
+ RestClient.post(hipchat_url, { room_id: "Deployments", from: "DeployBot", color: "green", message_format: "text", message: message })
end
end
end
@@ -251,4 +283,3 @@
task :configure, roles: :app do
system "ssh configure@#{find_servers_for_task(self).first} -p #{ssh_port}"
end
-
View
3 config/deploy/crm-vmware-gin.rb
@@ -1,4 +1,3 @@
-set :deploy_env, "gin"
set :context_path, "/vmware"
-server "crm-vmware-3-0-001.6fusion.#{deploy_env}", :app, :crm
+server "crm-vmware-3-0-001.6fusion.#{rails_env}", :app, :crm
View
1 config/deploy/crm-vmware-ova.rb
@@ -1,4 +1,3 @@
-set :deploy_env, "production"
set :context_path, "/vmware"
server "192.168.125.50", :app, :web, primary: true
View
1 config/deploy/crm-vmware-production.rb
@@ -1,4 +1,3 @@
-set :deploy_env, "production"
set :context_path, "/vmware"
server '192.168.113.8', :app, :crm
View
1 config/deploy/crm-vmware-staging.rb
@@ -1,4 +1,3 @@
-set :deploy_env, "staging"
set :context_path, "/vmware"
server '192.168.113.8', :app, :crm
View
3 config/deploy/crm-vmware-vodka.rb
@@ -1,4 +1,3 @@
-set :deploy_env, "vodka"
set :context_path, "/vmware"
-server "crm-vmware-3-0-001.6fusion.#{deploy_env}", :app, :crm
+server "crm-vmware-3-0-001.6fusion.#{rails_env}", :app, :crm
View
3 config/deploy/crm-vmware-whiskey.rb
@@ -1,4 +1,3 @@
-set :deploy_env, "whiskey"
set :context_path, "/vmware"
-server "crm-vmware-3-0-001.6fusion.#{deploy_env}", :app, :crm
+server "crm-vmware-3-0-001.6fusion.#{rails_env}", :app, :crm
View
2 config/deploy/gin.rb
@@ -1 +1 @@
-server "adaptor-vmware-1-0-001.6fusion.#{deploy_env}", :app
+server "adaptor-vmware-1-0-001.6fusion.#{rails_env}", :app
View
2 config/deploy/staging.rb
@@ -1 +1 @@
-server "adaptor-vmware-1-0-001.6fusion.#{deploy_env}", :app
+server "adaptor-vmware-1-0-001.6fusion.#{rails_env}", :app
View
2 config/deploy/vodka.rb
@@ -1 +1 @@
-server "adaptor-vmware-1-0-001.6fusion.#{deploy_env}", :app
+server "adaptor-vmware-1-0-001.6fusion.#{rails_env}", :app
View
2 config/deploy/whiskey.rb
@@ -1 +1 @@
-server "adaptor-vmware-1-0-001.6fusion.#{deploy_env}", :app
+server "adaptor-vmware-1-0-001.6fusion.#{rails_env}", :app

0 comments on commit 050401d

Please sign in to comment.