diff --git a/CHANGELOG.md b/CHANGELOG.md index 62f0785..1f49f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,27 @@ # Cap-EC2 changelog -## 1.1.0 +## Mission Data Customizations -* Using kylev/cap-ec2, incorporated switch to AWS SDK v2 * Add the ability to use IAM roles to grant cross-account access for deployment. +## 1.1.2 + +* Allow using aws-sdk v3 [@magnusvk](https://github.com/magnusvk) +* Fix NoMethodError undefined method call for Hash [@ur5us](https://github.com/ur5us) +* Allow tag value delimiter to be configurable [@erez-rabih](https://github.com/erez-rabih) + +## 1.1.1 + +Require aws-sdk v2 instead of v1 + +* Require aws-sdk v2 instead of v1 [@hajder](https://github.com/hajder) + +## 1.1.0 + +Upgrade to AWS's v2 SDK + +* Upgrade to AWS's v2 SDK [@kylev](https://github.com/kylev) + ## 1.0.0 Cap-EC2 is pretty stable, and the rate of PRs has decreased, so I've diff --git a/README.md b/README.md index 08bcbb0..113113d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ set :ec2_config, 'config/ec2.yml' set :ec2_project_tag, 'Project' set :ec2_roles_tag, 'Roles' set :ec2_stages_tag, 'Stages' +set :ec2_tag_delimiter, "," +set :ec2_profile, 'myservice' # use ~/.aws/credentials with profile_name set :ec2_access_key_id, nil set :ec2_secret_access_key, nil set :ec2_region, %w{} # REQUIRED @@ -58,7 +60,7 @@ set :ec2_filter_by_status_ok?, nil #### Order of inheritance `cap-ec2` supports multiple methods of configuration. The order of inheritance is: -YAML File > User Capistrano Config > Default Capistrano Config > ENV variables. +YAML File > ~/.aws/credentials > User Capistrano Config > Default Capistrano Config > ENV variables. #### Regions @@ -114,6 +116,12 @@ The necessary access permissions policy is Cap-EC2 will look for a tag with this name to determine which instances belong to a given role. The tag name defaults to "Roles". +* tag_delimiter + + When Cap-EC2 reads a tag value, this will be the default delimiter. + For example, for a Roles tag with web,db and tag_delimiter set to ,(comma) + the server will have the web and db roles. + * filter_by_status_ok? If this is set to `true`, then Cap-EC2 will not return instances which do not have both EC2 status diff --git a/cap-ec2.gemspec b/cap-ec2.gemspec index fb16171..fd6a3eb 100644 --- a/cap-ec2.gemspec +++ b/cap-ec2.gemspec @@ -6,8 +6,8 @@ require 'cap-ec2/version' Gem::Specification.new do |spec| spec.name = "cap-ec2" spec.version = CapEC2::VERSION - spec.authors = ["Andy Sykes", "Robert Coleman"] - spec.email = ["github@tinycat.co.uk", "github@robert.net.nz"] + spec.authors = ["Andy Sykes", "Robert Coleman", "Forward3D Developers"] + spec.email = ["github@tinycat.co.uk", "github@robert.net.nz", "developers@forward3d.com"] spec.description = %q{Cap-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2 instance tags, dynamically building the list of servers to be deployed to.} spec.summary = %q{Cap-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2 instance tags, dynamically building the list of servers to be deployed to.} spec.homepage = "https://github.com/forward3d/cap-ec2" @@ -21,7 +21,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" - spec.add_dependency "aws-sdk", "~> 2.0" + spec.add_dependency "aws-sdk", ">= 2.0" spec.add_dependency "capistrano", ">= 3.0" spec.add_dependency "terminal-table" spec.add_dependency "colorize" diff --git a/lib/cap-ec2/ec2-handler.rb b/lib/cap-ec2/ec2-handler.rb index 8d400a2..0785efa 100644 --- a/lib/cap-ec2/ec2-handler.rb +++ b/lib/cap-ec2/ec2-handler.rb @@ -105,7 +105,7 @@ def get_server(instance_id) private def instance_has_tag?(instance, key, value) - (tag_value(instance, key) || '').split(',').map(&:strip).include?(value.to_s) + (tag_value(instance, key) || '').split(tag_delimiter).map(&:strip).include?(value.to_s) end def instance_status_ok?(instance) diff --git a/lib/cap-ec2/tasks/ec2.rake b/lib/cap-ec2/tasks/ec2.rake index 6bc2424..5cab58f 100644 --- a/lib/cap-ec2/tasks/ec2.rake +++ b/lib/cap-ec2/tasks/ec2.rake @@ -26,6 +26,7 @@ namespace :load do set :ec2_project_tag, 'Project' set :ec2_roles_tag, 'Roles' set :ec2_stages_tag, 'Stages' + set :ec2_tag_delimiter, "," set :ec2_access_key_id, nil set :ec2_secret_access_key, nil diff --git a/lib/cap-ec2/utils.rb b/lib/cap-ec2/utils.rb index ae23be8..2c7a38d 100644 --- a/lib/cap-ec2/utils.rb +++ b/lib/cap-ec2/utils.rb @@ -1,3 +1,5 @@ +require 'aws-sdk' + module CapEC2 module Utils @@ -20,8 +22,12 @@ def stages_tag fetch(:ec2_stages_tag) end + def tag_delimiter + fetch(:ec2_tag_delimiter) + end + def tag_value(instance, key) - instance.tags.find({}) { |t| t[:key] == key.to_s }[:value] + instance.tags.find(-> { {} }) { |t| t[:key] == key.to_s }[:value] end def self.contact_point_mapping @@ -40,13 +46,22 @@ def self.contact_point(instance) end def load_config + if fetch(:ec2_profile) + credentials = Aws::SharedCredentials.new(profile_name: fetch(:ec2_profile)).credentials + if credentials + set :ec2_access_key_id, credentials.access_key_id + set :ec2_secret_access_key, credentials.secret_access_key + end + end + config_location = File.expand_path(fetch(:ec2_config), Dir.pwd) if fetch(:ec2_config) if config_location && File.exists?(config_location) - config = YAML.load_file fetch(:ec2_config) + config = YAML.load(ERB.new(File.read(fetch(:ec2_config)))) if config set :ec2_project_tag, config['project_tag'] if config['project_tag'] set :ec2_roles_tag, config['roles_tag'] if config['roles_tag'] set :ec2_stages_tag, config['stages_tag'] if config['stages_tag'] + set :ec2_tag_delimiter, config['tag_delimiter'] if config['tag_delimiter'] set :ec2_access_key_id, config['access_key_id'] if config['access_key_id'] set :ec2_secret_access_key, config['secret_access_key'] if config['secret_access_key'] diff --git a/lib/cap-ec2/version.rb b/lib/cap-ec2/version.rb index 543ea07..ca72012 100644 --- a/lib/cap-ec2/version.rb +++ b/lib/cap-ec2/version.rb @@ -1,3 +1,3 @@ module CapEC2 - VERSION = '1.1.0' + VERSION = '1.1.2' end