Skip to content

Commit

Permalink
Added fail fast so that commands do not keep executing if the last co…
Browse files Browse the repository at this point in the history
…mmand

 failed
  • Loading branch information
philly-mac committed Feb 17, 2013
1 parent ae248c7 commit 122a57b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 50 deletions.
12 changes: 12 additions & 0 deletions Gemfile.lock
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
deploy (1.6)
erubis
pony
simpleconfig

GEM
Expand All @@ -17,13 +18,21 @@ GEM
erubis (2.7.0)
hashie (1.2.0)
i18n (0.6.1)
mail (2.5.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.21)
minitest (4.6.1)
minitest-reporters (0.14.7)
ansi
builder
minitest (>= 2.12, < 5.0)
powerbar
multi_json (1.6.1)
polyglot (0.3.3)
pony (1.4)
mail (> 2.0)
powerbar (1.0.11)
ansi (~> 1.4.0)
hashie (>= 1.1.0)
Expand All @@ -40,6 +49,9 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
wrong (0.7.0)
diff-lcs (~> 1.1.2)
predicated (~> 0.2.6)
Expand Down
19 changes: 10 additions & 9 deletions bin/dep
Expand Up @@ -9,15 +9,16 @@ options = {}
# Parse the options
op = OptionParser.new do |opts|
opts.banner = "Usage: dep [options]"
opts.on("-e", "--environment ENV", "Environment to execute in") { |e| options[:environment] = e }
opts.on("-t", "--task TASK", "The task to run") { |t| options[:task] = t }
opts.on("-c", "--config CONFIG", "Path to custom config") { |c| options[:config] = c }
opts.on("-d", "--dry", "Just show the commands") { |d| options[:dry] = d }
opts.on("-q", "--quiet", "Less noise") { |q| options[:quiet] = q }
opts.on("-T", "--tasks", "Show tasks") { |t| options[:tasks] = t }
opts.on("-l", "--list", "List all tasks modules") { |l| options[:list] = l }
opts.on("-p", "--parameters PARAMS", "comma separated list of parameters") { |p| options[:parameters] = p }
opts.on("-r", "--raw", "Output all commands only") { |r| options[:raw] = r }
opts.on("-c", "--config CONFIG", "Path to custom config") { |c| options[:config] = c }
opts.on("-d", "--dry", "Just show the commands") { |d| options[:dry] = d }
opts.on("-e", "--environment ENV", "Environment to execute in") { |e| options[:environment] = e }
opts.on("-o", "--without WITHOUT", "remove commands from the current command set") { |o| options[:without] = o }
opts.on("-p", "--parameters PARAMS", "comma separated list of parameters") { |p| options[:parameters] = p }
opts.on("-q", "--quiet", "Less noise") { |q| options[:quiet] = q }
opts.on("-r", "--raw", "Output all commands only") { |r| options[:raw] = r }
opts.on("-T", "--tasks", "Show tasks") { |t| options[:tasks] = t }
opts.on("-t", "--tasks TASKS", "Comma separated list of tasks to run") { |t| options[:tasks] = t }
opts.on("-w", "--with WITH", "add commands to the current command set") { |w| options[:with] = w }
end

op.parse!
Expand Down
1 change: 1 addition & 0 deletions deploy.gemspec
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency "simpleconfig"
s.add_runtime_dependency "erubis"
s.add_runtime_dependency "pony"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down
30 changes: 18 additions & 12 deletions lib/deploy/process.rb
Expand Up @@ -4,6 +4,14 @@ module Process
def self.included(base)
base.class_eval do

def self.queue(actions)
if actions.is_a?(Array)
self.actions = self.actions + actions
else
self.actions << actions
end
end

def self.process_queue
self.merge_actions
self.actions.each do |action|
Expand All @@ -14,14 +22,6 @@ def self.process_queue
self.actions = []
end

def self.queue(actions)
if actions.is_a?(Array)
self.actions = self.actions + actions
else
self.actions << actions
end
end

def self.merge_actions
self.prepended_actions.each do |pa|
if pa.last.nil?
Expand Down Expand Up @@ -66,7 +66,12 @@ def self.run_now!(command)
if config_present?(:raw)
puts command
else
system command unless config_present?(:dry_run)
return if config_present?(:dry_run)

unless system(command)
puts "*** Failure Not Continuing ***"
exit(1)
end
end
end

Expand All @@ -76,7 +81,8 @@ def self.run_now_with_return!(command)
if config_present?(:raw)
puts command
else
`#{command}` unless config_present?(:dry_run)
return if config_present?(:dry_run)
`#{command}`
end
end

Expand All @@ -96,11 +102,11 @@ def self.push!
end
end

run_now!(local_commands.join("; ")) unless local_commands.empty?

if config_present?(:raw)
run_now!(local_commands.join("; ")) unless local_commands.empty?
run_now!(remote_commands.join("; ")) unless remote_commands.empty?
else
run_now!(local_commands.join("; ")) unless local_commands.empty?
run_now!(ssh_cmd(remote_commands.join("; "))) unless remote_commands.empty?
end

Expand Down
35 changes: 34 additions & 1 deletion lib/deploy/setup.rb
Expand Up @@ -50,8 +50,41 @@ def self.process_options(options)
dep_config.set :app_name, "test"
dep_config.set :shell, "/bin/bash"
dep_config.set :app_root, "#{dep_config.deploy_root}/#{dep_config.app_name}"
dep_config.set :use_bundler, false
dep_config.set :bundler_use, false
dep_config.set :composite_name, "#{dep_config.app_name}-#{dep_config.env}"

# Mail settings
dep_config.set :mail_use, false
dep_config.set :mail_via, :sendmail # Or :smtp
dep_config.set :mail_to, "test@example.com"
dep_config.set :mail_from, "test@example.com"

# Sendmail options
# dep_config.set :mail_via_options => {
# :location => '/path/to/sendmail', # defaults to 'which sendmail' or '/usr/sbin/sendmail' if 'which' fails
# :arguments => '-t' # -t and -i are the defaults
# }

# SMTP options
# dep_config.set :mail_via_options => {
# :address => 'smtp.yourserver.com',
# :port => '25',
# :user_name => 'user',
# :password => 'password',
# :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
# :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
# }

# SMTP Gmail options
# dep_config.set :mail_via_options => {
# :address => 'smtp.gmail.com',
# :port => '587',
# :enable_starttls_auto => true,
# :user_name => 'user',
# :password => 'password',
# :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
# :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
# }
end

end
Expand Down
30 changes: 15 additions & 15 deletions lib/deploy/tasks/unicorn.rb
Expand Up @@ -5,6 +5,19 @@ module Unicorn
def self.included(base)
base.class_eval do

def self.create_conf_file(template, output, options)
require 'erubis'

nginx_conf = File.read(template)
nginx_erb_conf = Erubis::Eruby.new(nginx_conf)

filename = output

File.open(output, 'w') do |file|
file.write(nginx_erb_conf.result(options))
end
end

task :unicorn_start, "Start unicorn" do
remote "sudo /etc/init.d/#{dep_config.unicorn_script} start"
end
Expand All @@ -21,22 +34,9 @@ def self.included(base)
remote "sudo /etc/init.d/#{dep_config.unicorn_script} upgrade"
end

def self.create_conf_file(template, output, options)
require 'erubis'

nginx_conf = File.read(template)
nginx_erb_conf = Erubis::Eruby.new(nginx_conf)

filename = output

File.open(output, 'w') do |file|
file.write(nginx_erb_conf.result(options))
end
end

task :unicorn_setup_config, "Setup unicorn config for nginx and as an init file" do
sudo "ln -nfs #{dep_config.app_root}/config/deploy/nginx/unicorn_nginx_#{dep_config.composite_name} /etc/nginx/sites-enabled/"
sudo "ln -nfs #{dep_config.app_root}/config/deploy/unicorn/unicorn_init_#{dep_config.composite_name} /etc/init.d/"
remote "sudo ln -nfs #{dep_config.app_root}/config/deploy/nginx/unicorn_nginx_#{dep_config.composite_name} /etc/nginx/sites-enabled/"
remote "sudo ln -nfs #{dep_config.app_root}/config/deploy/unicorn/unicorn_init_#{dep_config.composite_name} /etc/init.d/"
end

task :create_config_nginx, "Create nginx conf file" do
Expand Down
13 changes: 0 additions & 13 deletions lib/deploy/util.rb
Expand Up @@ -30,19 +30,6 @@ def self.tasks_list(recipe_clazz)
return 0
end

def self.tasks_modules_list
sorted_files = []

Dir["#{APP_ROOT}/lib/deploy/tasks/*.rb"].each do |file_name|
chopped_file = file_name.split('/').last
sorted_files << chopped_file.split('.').first
end

sorted_files.each {|sorted_file| puts sorted_file}

return 0
end

def self.set_parameters(parameters)
return unless parameters
params = parameters.split(',')
Expand Down

0 comments on commit 122a57b

Please sign in to comment.