Skip to content

Instantly share code, notes, and snippets.

@mikehale
Created May 14, 2010 19:10
Show Gist options
  • Select an option

  • Save mikehale/401518 to your computer and use it in GitHub Desktop.

Select an option

Save mikehale/401518 to your computer and use it in GitHub Desktop.
Example deploy.rb for use with Engine Yard Cloud
task :production do
set :rails_env, "production"
role :app, "example.com", :master => true
role(:app) { |opts| compute_ec2_addresses(:app, opts) }
role(:db, :master => true) { |opts| compute_ec2_addresses(:db, opts) }
end
task :staging do
set :rails_env, "staging"
role :app, "staging.example.com", :master => true
role(:app) { |opts| compute_ec2_addresses(:app, opts) }
role(:db, :master => true) { |opts| compute_ec2_addresses(:db, opts) }
end
# =============================================================================
def compute_ec2_addresses(role, opts)
role = "#{role}_master" if opts[:master] == true
unless roles[:app].respond_to? :static_servers
roles[:app].class.send(:define_method, :static_servers) { @static_servers }
end
app_master = roles[:app].static_servers.detect{|server| server.options[:master] == true }.host
unless @dna
require 'rubygems'
require 'json'
@dna = JSON.parse(capture("sudo cat /etc/chef/dna.json", :hosts => [app_master]))
end
instances = @dna["engineyard"]["environment"]["instances"]
instance = instances.detect {|instance| instance["role"] == role.to_s }
instance ? instance["public_hostname"] : nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment