From de885d7bd2d1c5fa7357c31504dec1b0a8c0991b Mon Sep 17 00:00:00 2001 From: Tom Wilson Date: Tue, 29 Dec 2009 09:00:11 -0500 Subject: [PATCH] removed yml --- config/hugo.yml.example | 0 lib/hugo/app_server.rb | 67 ++++++++++++++++++---------------- lib/hugo/rds.rb | 6 +-- spec/lib/hugo/balancer_spec.rb | 15 ++++---- spec/lib/hugo/database_spec.rb | 14 +++---- spec/lib/hugo_spec.rb | 2 + 6 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 config/hugo.yml.example diff --git a/config/hugo.yml.example b/config/hugo.yml.example new file mode 100644 index 0000000..e69de29 diff --git a/lib/hugo/app_server.rb b/lib/hugo/app_server.rb index 1dd93f8..d5dba19 100644 --- a/lib/hugo/app_server.rb +++ b/lib/hugo/app_server.rb @@ -5,11 +5,22 @@ class Hugo::AppServer DEFAULT_ZONE = 'us-east-1c' DEFAULT_IMAGE_ID = 'ami-1515f67c' DEFAULT_KEY_NAME = 'ec2-keypair' + DEFAULT_COOKBOOK = 'git://github.com/twilson63/hugo-cookbooks.git' attr_accessor :name, :uri, :type, :zone, :image_id, :key_name, :db, :lb, :instances, - :port, :ssl, :application, :cloud + :port, :ssl, :application, :cookbook, + :github_url, :publickey, :privatekey, + :gem_list, :package_list, :run_list + def initialize + self.zone = DEFAULT_ZONE + self.image_id = DEFAULT_IMAGE_ID + self.key_name = DEFAULT_KEY_NAME + self.instances = 1 + self.cookbook = DEFAULT_COOKBOOK + end + def database(name, &block) database = Hugo::Database.instance database.instance_eval(&block) @@ -28,14 +39,6 @@ def balancer(&block) self.lb = balancer.deploy self.lb end - - def initialize - self.zone = DEFAULT_ZONE - self.image_id = DEFAULT_IMAGE_ID - self.key_name = DEFAULT_KEY_NAME - self.instances = 1 - - end def deploy @@ -75,8 +78,6 @@ def create_ec2 end def setup_ec2 - hugo_config = YAML.load_file("config/hugo.yml") - commands = [] commands << 'sudo apt-get update -y' commands << 'sudo apt-get install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential git-core xfsprogs -y' @@ -89,52 +90,54 @@ def setup_ec2 commands << 'sudo gem source -a http://gems.github.com' commands << 'sudo gem install chef-deploy --no-ri --no-rdoc' commands << 'sudo gem install git --no-ri --no-rdoc' - commands << "git clone #{hugo_config['git']} ~/hugo-repos" + commands << "git clone #{self.cookbook} ~/hugo-repos" # Setup base role dna = { :run_list => ["role[web-base]"], - :package_list => hugo_config['package_list'], - :gem_list => hugo_config['gem_list'], - :git => hugo_config['git'], - :github => hugo_config['github'], - :access_key => Ec2::ACCESS_KEY, - :secret_key => Ec2::SECRET_KEY, - :apache => hugo_config['apache'] + :package_list => self.package_list, + :gem_list => self.gem_list, + :git => self.cookbook, + :github => { :url => self.github_url, + :publickey => self.publickey, + :privatekey => self.privatekey}, + :access_key => Hugo::Ec2::ACCESS_KEY, + :secret_key => Hugo::Ec2::SECRET_KEY, + :apache => { :listen_ports => [self.port, self.ssl] } } commands << 'sudo chef-solo -c /home/ubuntu/hugo-repos/config/solo.rb -j /home/ubuntu/dna.json' - Ec2.find(instance_id).ssh(commands, dna) + Hugo::Ec2.find(instance_id).ssh(commands, dna) end def deploy_ec2 - hugo_config = YAML.load_file("config/hugo.yml") - app_config = YAML.load_file("config/#{application}.yml") commands = [] #commands << "git clone #{@@hugo_config['git']} ~/hugo-repos" commands << "cd hugo-repos && git fetch && git merge" commands << 'sudo chef-solo -c /home/ubuntu/hugo-repos/config/solo.rb -j /home/ubuntu/dna.json' - dna = { :run_list => app_config['run_list'], - :package_list => app_config['package_list'] || {}, - :gem_list => app_config['gem_list'] || {}, + dna = { :run_list => self.run_list, + :package_list => self.package_list || {}, + :gem_list => self.gem_list || {}, :application => self.application, - :customer => self.cloud, + :customer => self.name, :database => { :uri => self.db.uri, :user => self.db.user, :password => self.db.password }, :web => { :port => self.port, :ssl => self.ssl }, - :git => hugo_config['git'], - :github => hugo_config['github'], - :access_key => Ec2::ACCESS_KEY, - :secret_key => Ec2::SECRET_KEY, - :app => app_config['app'] || nil + :git => self.cookbook, + :github => { :url => self.github_url, + :publickey => self.publickey, + :privatekey => self.privatekey}, + :access_key => Hugo::Ec2::ACCESS_KEY, + :secret_key => Hugo::Ec2::SECRET_KEY, + :app => self.application || nil } lb.instances.each do |i| - Ec2.find(i).ssh(commands, dna) + Hugo::Ec2.find(i).ssh(commands, dna) end end diff --git a/lib/hugo/rds.rb b/lib/hugo/rds.rb index 0668a61..cf53e0d 100644 --- a/lib/hugo/rds.rb +++ b/lib/hugo/rds.rb @@ -7,7 +7,7 @@ class Rds INSTANCE_CLASS = "db.m1.small" ZONE = "us-east-1c" - attr_accessor :db, :uri, :server, :user, :pwd, :instance_class, + attr_accessor :db, :uri, :server, :user, :password, :instance_class, :zone, :size, :status, :create_time def initialize(options={}) @@ -16,7 +16,7 @@ def initialize(options={}) @server = options[:server] || options["DBInstanceIdentifier"] @db = options[:name] || options["DBName"] @user = options[:user] || options["MasterUsername"] - @pwd = options[:password] || "****" + @password = options[:password] || "****" @size = options[:size] || options["AllocatedStorage"] || DEFAULT_SIZE @instance_class = options[:instance_class] || options["DBInstanceClass"] || INSTANCE_CLASS @zone = options[:zone] || options["AvailabilityZone"] || ZONE @@ -38,7 +38,7 @@ def create :db_instance_class => self.instance_class, :engine => "MySQL5.1", :master_username => self.user, - :master_user_password => self.pwd, + :master_user_password => self.password, :db_name => self.db, :availability_zone => self.zone) unless self.create_time diff --git a/spec/lib/hugo/balancer_spec.rb b/spec/lib/hugo/balancer_spec.rb index 1e63df6..96f6bf7 100644 --- a/spec/lib/hugo/balancer_spec.rb +++ b/spec/lib/hugo/balancer_spec.rb @@ -4,13 +4,13 @@ it "should be valid" do block = lambda do - cloud "my_cloud" do |c| - c.instances = 1 - c.balancer do end - c.database "testapp" do |db| - db.server = "serverx" - db.user = "test_user" - db.password = "test_password" + cloud "my_cloud" do + @instances = 1 + balancer do end + database "testapp" do + @server = "serverx" + @user = "test_user" + @password = "test_password" end end end @@ -34,6 +34,7 @@ lb = Hugo::Balancer.instance lb.name = "myserver" lb.deploy.should be_a_kind_of(Hugo::Elb) + end before(:each) do diff --git a/spec/lib/hugo/database_spec.rb b/spec/lib/hugo/database_spec.rb index ce73846..a07fd45 100644 --- a/spec/lib/hugo/database_spec.rb +++ b/spec/lib/hugo/database_spec.rb @@ -11,13 +11,13 @@ it "should be valid" do block = lambda do - cloud "my_cloud" do |c| - c.instances = 1 - c.balancer do end - c.database "testapp" do |db| - db.server = "serverx" - db.user = "test_user" - db.password = "test_password" + cloud "my_cloud" do + @instances = 1 + balancer do end + database "testapp" do + @server = "serverx" + @user = "test_user" + @password = "test_password" end end end diff --git a/spec/lib/hugo_spec.rb b/spec/lib/hugo_spec.rb index c08ca5d..34a813e 100644 --- a/spec/lib/hugo_spec.rb +++ b/spec/lib/hugo_spec.rb @@ -19,6 +19,8 @@ end.should be_true end + + it "should deploy infrastructure" do block = lambda do cloud "mycloud" do