Using the Engineyard Gem for Not Deploying
Jul 24th , 2011
As you may or may not be aware I wrote several gists that display how to use the engineyard gem to either pull your instance ips, or to run custom recipes to clean out an errored instance.
#!/usr/bin/env ruby
require 'yaml'
require 'rubygems'
require 'engineyard'
api_token = YAML.load_file(File.expand_path("~/.eyrc"))["api_token"]
puts "Environments + Instances: "
puts ""
api = EY::API.new(api_token)
envs = api.apps.map{ |a| a.environments }
envs.flatten.map{|x| x.name}.uniq.each do |env|
puts env
blahsies = api.environments.match_one!(env).instances.select
blahsies.map do |instance|
puts "#{instance.amazon_id} - #{instance.status} - #{instance.role} - #{instance.public_hostname}"
end
end
puts ""
puts "Applications:"
api.apps.map do |app|
puts "#{app.name} / #{app.repository_uri} "
end
#!/usr/bin/env ruby
require 'yaml'
require 'rubygems'
require 'engineyard'
def usage
str =<<-EOS
Usage: #{__FILE__} <environment>
Example: #{__FILE__} production
Example: #{__FILE__} staging
EOS
end
def run_chef(instance)
puts "=" * 60
puts "Running chef recipe on #{instance.amazon_id} #{instance.role} #{instance.public_hostname}"
cmd = %Q{ssh root@#{instance.public_hostname} "/usr/local/ey_resin/bin/ey-enzyme --custom --chef-bin /usr/local/ey_resin/bin/chef-solo"}
puts cmd
puts `#{cmd}`
end
def main(args)
if args.empty?
puts usage
exit 1
end
env = args[0]
api_token = YAML.load_file(File.expand_path("~/.eyrc"))["api_token"]
api = EY::API.new(api_token)
# envs = api.apps.map{ |a| a.environments }
puts "finding instances on env: #{env}"
environment = api.environments.match_one!(env)
# run recipes all all non app_master instances first
environment.instances.select{|x| x.role != "app_master"}.each do |x|
run_chef(x)
end
# then run on app_master
app_master = environment.instances.find{|x| x.role == "app_master"}
run_chef(app_master) if app_master
end
main(ARGV)