ec2launcher 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.12
2
+
3
+ * Embed runurl and setup.rb scripts in user-data to avoid having to retrieve them.
4
+
1
5
  ## 1.0.11
2
6
 
3
7
  * Support launching multiple instances with one command.
data/ec2launcher.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "ec2launcher"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = Ec2launcher::VERSION
15
+ gem.version = EC2Launcher::VERSION
16
16
 
17
17
  gem.add_runtime_dependency "aws-sdk", [">= 1.5.0"]
18
18
  end
@@ -6,4 +6,7 @@ module EC2Launcher
6
6
 
7
7
  AVAILABILITY_ZONES = %w{us-east-1a us-east-1b us-east-1c us-east-1d}
8
8
  INSTANCE_TYPES = %w{m1.small m1.medium m1.large m1.xlarge t1.micro m2.xlarge m2.2xlarge m2.4xlarge c1.medium c1.xlarge cc1.4xlarge cg1.4xlarge}
9
+
10
+ RUN_URL_SCRIPT = "http://bazaar.launchpad.net/~alestic/runurl/trunk/download/head:/runurl-20090817053347-o2e56z7xwq8m9tt6-1/runurl"
11
+ SETUP_SCRIPT = "https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts/setup.rb"
9
12
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
- module Ec2launcher
5
- VERSION = "1.0.11"
4
+ module EC2Launcher
5
+ VERSION = "1.0.12"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -31,6 +31,11 @@ module EC2Launcher
31
31
  class Launcher
32
32
  include BackoffRunner
33
33
 
34
+ def initialize()
35
+ @run_url_script_cache = nil
36
+ @setup_script_cache = nil
37
+ end
38
+
34
39
  def launch(options)
35
40
  @options = options
36
41
 
@@ -324,12 +329,18 @@ module EC2Launcher
324
329
  ##############################
325
330
  # Launch the new intance
326
331
  ##############################
332
+ puts ""
327
333
  instances = []
328
334
  fqdn_names.each_index do |i|
329
- block_device_tags = block_device_builder.generate_device_tags(fqdn[i], short_hostnames[i], @environment.name, @application.block_devices)
330
- instances << launch_instance(fqdn[i], ami.ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
335
+ block_device_tags = block_device_builder.generate_device_tags(fqdn_names[i], short_hostnames[i], @environment.name, @application.block_devices)
336
+ user_data = build_launch_command(fqdn_names[i], short_hostnames[i], roles, chef_validation_pem_url, aws_keyfile, gems, packages, email_notifications)
337
+
338
+ instance = launch_instance(fqdn_names[i], ami.ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
339
+ instances << instance
331
340
 
332
- puts "Launched #{fqdn[i]} (#{instance.id}) [#{instance.public_dns_name} / #{instance.private_dns_name} / #{instance.private_ip_address} ]"
341
+ public_dns_name = instance.public_dns_name.nil? ? "no public dns" : instance.public_dns_name
342
+ private_dns_name = instance.private_dns_name.nil? ? "no private dns" : instance.private_dns_name
343
+ puts "Launched #{fqdn_names[i]} (#{instance.id}) [#{public_dns_name} / #{private_dns_name} / #{instance.private_ip_address} ]"
333
344
  end
334
345
 
335
346
  ##############################
@@ -491,19 +502,31 @@ module EC2Launcher
491
502
  #
492
503
  # @return [AWS::EC2::Instance] newly created EC2 instance or nil if the launch failed.
493
504
  def launch_instance(hostname, ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings = nil, block_device_tags = nil, vpc_subnet = nil)
494
- puts "Launching instance..."
505
+ puts "Launching instance... #{hostname}"
495
506
  new_instance = nil
496
507
  run_with_backoff(30, 1, "launching instance") do
497
- new_instance = @ec2.instances.create(
498
- :image_id => ami_id,
499
- :availability_zone => availability_zone,
500
- :key_name => key_name,
501
- :security_group_ids => security_group_ids,
502
- :user_data => user_data,
503
- :instance_type => instance_type,
504
- :block_device_mappings => block_device_mappings,
505
- :subnet => vpc_subnet
506
- )
508
+ if block_device_mappings.nil? || block_device_mappings.keys.empty?
509
+ new_instance = @ec2.instances.create(
510
+ :image_id => ami_id,
511
+ :availability_zone => availability_zone,
512
+ :key_name => key_name,
513
+ :security_group_ids => security_group_ids,
514
+ :user_data => user_data,
515
+ :instance_type => instance_type,
516
+ :subnet => vpc_subnet
517
+ )
518
+ else
519
+ new_instance = @ec2.instances.create(
520
+ :image_id => ami_id,
521
+ :availability_zone => availability_zone,
522
+ :key_name => key_name,
523
+ :security_group_ids => security_group_ids,
524
+ :user_data => user_data,
525
+ :instance_type => instance_type,
526
+ :block_device_mappings => block_device_mappings,
527
+ :subnet => vpc_subnet
528
+ )
529
+ end
507
530
  end
508
531
  sleep 5
509
532
 
@@ -683,7 +706,7 @@ module EC2Launcher
683
706
  # @param [EC2Launcher::DSL::EmailNotifications] email_notifications Email notification settings for launch updates
684
707
  #
685
708
  # @return [String] Launch commands to pass into new instance as userdata
686
- def build_launch_command(fqdn, short_hostname, chef_validation_pem_url, aws_keyfile, gems, packages, email_notifications)
709
+ def build_launch_command(fqdn, short_hostname, roles, chef_validation_pem_url, aws_keyfile, gems, packages, email_notifications)
687
710
  # Build JSON for setup scripts
688
711
  setup_json = {
689
712
  'hostname' => fqdn,
@@ -704,9 +727,9 @@ module EC2Launcher
704
727
 
705
728
  ##############################
706
729
  # Build launch command
707
- user_data = "#!/bin/sh
708
- export HOME=/root
709
- echo '#{setup_json.to_json}' > /tmp/setup.json"
730
+ user_data = "#!/bin/sh"
731
+ user_data += "\nexport HOME=/root"
732
+ user_data += "\necho '#{setup_json.to_json}' > /tmp/setup.json"
710
733
 
711
734
  # pre-commands, if necessary
712
735
  unless @environment.precommands.nil? || @environment.precommands.empty?
@@ -714,15 +737,42 @@ echo '#{setup_json.to_json}' > /tmp/setup.json"
714
737
  user_data += "\n" + precommands
715
738
  end
716
739
 
717
- # Primary setup script
718
- user_data += "\ncurl http://bazaar.launchpad.net/~alestic/runurl/trunk/download/head:/runurl-20090817053347-o2e56z7xwq8m9tt6-1/runurl -o /tmp/runurl
719
- chmod +x /tmp/runurl
720
- /tmp/runurl https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts/setup.rb -e #{@environment.name} -a #{@application.name} -h #{hostname} /tmp/setup.json > /var/log/cloud-startup.log
721
- rm -f /tmp/runurl"
722
- user_data += " -c #{options.clone_host}" unless options.clone_host.nil?
740
+ user_data += "\n"
741
+
742
+ if @run_url_script_cache.nil?
743
+ puts "Downloading runurl script from #{RUN_URL_SCRIPT}"
744
+ @run_url_script_cache = `curl -s #{RUN_URL_SCRIPT} |gzip -f |base64`
745
+ end
746
+
747
+ if @setup_script_cache.nil?
748
+ puts "Downloading setup script from #{SETUP_SCRIPT}"
749
+ @setup_script_cache = `curl -s #{SETUP_SCRIPT} |gzip -f |base64`
750
+ end
751
+
752
+ # runurl script
753
+ user_data += "cat > /tmp/runurl.gz.base64 <<End-Of-Message\n"
754
+ user_data += @run_url_script_cache
755
+ user_data += "End-Of-Message"
756
+
757
+ # setup script
758
+ user_data += "\ncat > /tmp/setup.rb.gz.base64 <<End-Of-Message2\n"
759
+ user_data += @setup_script_cache
760
+ user_data += "End-Of-Message2"
761
+
762
+ user_data += "\nbase64 -d /tmp/runurl.gz.base64 | gunzip > /tmp/runurl"
763
+ user_data += "\nchmod +x /tmp/runurl"
764
+ # user_data += "\nrm -f /tmp/runurl.gz.base64"
765
+
766
+ user_data += "\nbase64 -d /tmp/setup.rb.gz.base64 | gunzip > /tmp/setup.rb"
767
+ user_data += "\nchmod +x /tmp/setup.rb"
768
+ # user_data += "\nrm -f /tmp/setup.rb.gz.base64"
769
+
770
+ user_data += "\n/tmp/setup.rb -e #{@environment.name} -a #{@application.name} -h #{fqdn} /tmp/setup.json > /var/log/cloud-startup.log"
771
+ user_data += " -c #{@options.clone_host}" unless @options.clone_host.nil?
772
+ # user_data += "\nrm -f /tmp/runurl /tmp/setup.rb"
723
773
 
724
774
  # Add extra requested commands to the launch sequence
725
- options.commands.each {|extra_cmd| user_data += "\n#{extra_cmd}" }
775
+ @options.commands.each {|extra_cmd| user_data += "\n#{extra_cmd}" }
726
776
 
727
777
  # Post commands
728
778
  unless @environment.postcommands.nil? || @environment.postcommands.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: