From e07fec6590e389ac9d6e1a503b6e212bb0bfb553 Mon Sep 17 00:00:00 2001 From: Erez Rabih Date: Sun, 17 May 2015 17:28:02 +0300 Subject: [PATCH 1/9] allow tag value delimiter to be configurable --- README.md | 7 +++++++ lib/cap-ec2/ec2-handler.rb | 2 +- lib/cap-ec2/tasks/ec2.rake | 1 + lib/cap-ec2/utils.rb | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d6ef04..fef019f 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ 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_access_key_id, nil set :ec2_secret_access_key, nil @@ -86,6 +87,12 @@ If running on EC2 the IAM instance profile credentials will be used if credentia 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/lib/cap-ec2/ec2-handler.rb b/lib/cap-ec2/ec2-handler.rb index 2d54887..322f30b 100644 --- a/lib/cap-ec2/ec2-handler.rb +++ b/lib/cap-ec2/ec2-handler.rb @@ -83,7 +83,7 @@ def get_server(instance_id) private def instance_has_tag?(instance, key, value) - (instance.tags[key] || '').split(',').map(&:strip).include?(value.to_s) + (instance.tags[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 e608f12..28ae5eb 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 9a18d9a..9e9a4bc 100644 --- a/lib/cap-ec2/utils.rb +++ b/lib/cap-ec2/utils.rb @@ -20,6 +20,10 @@ def stages_tag fetch(:ec2_stages_tag) end + def tag_delimiter + fetch(:ec2_tag_delimiter) + end + def self.contact_point_mapping { :public_dns => :public_dns_name, @@ -43,6 +47,7 @@ def load_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'] From dcaa4c3b6e6d040f0fb5b91410c0942e6e95ada0 Mon Sep 17 00:00:00 2001 From: Justin Downing Date: Thu, 10 Dec 2015 15:59:09 -0500 Subject: [PATCH 2/9] Use ERB with ec2_config It would be nice if we could use Ruby to set YAML keys with a default value. For example: config/ec2.yml ``` project_tag: <%= ENV['CAP_EC2_TAG'] || 'project_name' %> ``` This way, if `CAP_EC2_TAG` is not set, then `cap-ec2` will default to using project_name for the `project_tag`. --- lib/cap-ec2/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cap-ec2/utils.rb b/lib/cap-ec2/utils.rb index 9a18d9a..45df5fe 100644 --- a/lib/cap-ec2/utils.rb +++ b/lib/cap-ec2/utils.rb @@ -38,7 +38,7 @@ def self.contact_point(instance) def load_config 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'] From 7ef7287aeb722ca44a55d10fc88a04af134fc3e7 Mon Sep 17 00:00:00 2001 From: "Min.Kim" Date: Mon, 20 Mar 2017 16:53:21 +0000 Subject: [PATCH 3/9] Bump version --- CHANGELOG.md | 8 +++++++- lib/cap-ec2/version.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fee0f33..f584997 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Cap-EC2 changelog +## 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 @@ -28,7 +34,7 @@ decided to bump the version to 1.0.0. ## 0.0.15 -* Add `ec2_filter_by_status_ok?` to filter out instances that aren't returning `OK` +* Add `ec2_filter_by_status_ok?` to filter out instances that aren't returning `OK` for their EC2 status checks. [@tomconroy](https://github.com/tomconroy) ## 0.0.14 diff --git a/lib/cap-ec2/version.rb b/lib/cap-ec2/version.rb index f09ea84..543ea07 100644 --- a/lib/cap-ec2/version.rb +++ b/lib/cap-ec2/version.rb @@ -1,3 +1,3 @@ module CapEC2 - VERSION = '1.0.0' + VERSION = '1.1.0' end From 4ca2f5ce90161faa42a058ed3a48a3edeae7a658 Mon Sep 17 00:00:00 2001 From: Mike Szyndel Date: Mon, 10 Apr 2017 18:23:44 +0200 Subject: [PATCH 4/9] require aws-sdk v2 instead of v1 --- lib/cap-ec2/capistrano.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cap-ec2/capistrano.rb b/lib/cap-ec2/capistrano.rb index 9df98ce..4d6374f 100644 --- a/lib/cap-ec2/capistrano.rb +++ b/lib/cap-ec2/capistrano.rb @@ -1,5 +1,5 @@ require 'capistrano/configuration' -require 'aws-sdk-v1' +require 'aws-sdk' require 'colorize' require 'terminal-table' require 'yaml' From 203d70d153a01649ea2225c0255835da90ae599b Mon Sep 17 00:00:00 2001 From: masarakki Date: Tue, 16 May 2017 21:20:49 +0900 Subject: [PATCH 5/9] support-dotfile --- README.md | 3 ++- lib/cap-ec2/utils.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b938108..2f1eea0 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ set :ec2_project_tag, 'Project' set :ec2_roles_tag, 'Roles' set :ec2_stages_tag, 'Stages' +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 @@ -59,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 diff --git a/lib/cap-ec2/utils.rb b/lib/cap-ec2/utils.rb index ae23be8..a6adbb0 100644 --- a/lib/cap-ec2/utils.rb +++ b/lib/cap-ec2/utils.rb @@ -1,3 +1,5 @@ +require 'aws-sdk' + module CapEC2 module Utils @@ -40,6 +42,14 @@ 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) From 3ec18d0f9dcd35531cb4a79415964ecb83e514d6 Mon Sep 17 00:00:00 2001 From: Dave Lahn Date: Thu, 17 Aug 2017 16:28:24 +0100 Subject: [PATCH 6/9] Release v1.1.1 --- CHANGELOG.md | 6 ++++++ lib/cap-ec2/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f584997..2b0ee95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Cap-EC2 changelog +## 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 diff --git a/lib/cap-ec2/version.rb b/lib/cap-ec2/version.rb index 543ea07..e979247 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.1' end From cf3c9ed8c38a1c5c9e74082af1befa15f6b6dec3 Mon Sep 17 00:00:00 2001 From: Magnus von Koeller Date: Tue, 12 Dec 2017 15:17:05 -0500 Subject: [PATCH 7/9] Allow using aws-sdk v3 AWS-SDK v3 is compatible with v2, so this should "just work," according to their documentation: https://github.com/aws/aws-sdk-ruby#upgrade-from-version-2 --- cap-ec2.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cap-ec2.gemspec b/cap-ec2.gemspec index fb16171..04e4abe 100644 --- a/cap-ec2.gemspec +++ b/cap-ec2.gemspec @@ -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" From 95f9f7bdcb76eea1483212a962ba4a91072a02d8 Mon Sep 17 00:00:00 2001 From: Juri Hahn Date: Wed, 20 Dec 2017 14:33:51 +1300 Subject: [PATCH 8/9] Fix NoMethodError undefined method call for Hash Enumerable#find expects a callable object for its `ifnone` parameter. --- lib/cap-ec2/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cap-ec2/utils.rb b/lib/cap-ec2/utils.rb index be2b154..f4df6b0 100644 --- a/lib/cap-ec2/utils.rb +++ b/lib/cap-ec2/utils.rb @@ -23,7 +23,7 @@ def stages_tag 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 From 8d394eb5a21098ebea2e0ee20117a194205d0d7f Mon Sep 17 00:00:00 2001 From: Dave Lahn Date: Mon, 5 Feb 2018 11:00:18 +0000 Subject: [PATCH 9/9] Releasing v1.1.2 --- CHANGELOG.md | 6 ++++++ cap-ec2.gemspec | 4 ++-- lib/cap-ec2/version.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b0ee95..ce034f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Cap-EC2 changelog +## 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 diff --git a/cap-ec2.gemspec b/cap-ec2.gemspec index 04e4abe..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" diff --git a/lib/cap-ec2/version.rb b/lib/cap-ec2/version.rb index e979247..ca72012 100644 --- a/lib/cap-ec2/version.rb +++ b/lib/cap-ec2/version.rb @@ -1,3 +1,3 @@ module CapEC2 - VERSION = '1.1.1' + VERSION = '1.1.2' end