capistrano-srv_hosts 0.1.0

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/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'rspec'
5
+ end
6
+
7
+ gemspec
data/LICENSE.TXT ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rally Software Development Corp
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Capistrano::SrvHosts [![Build Status](https://travis-ci.org/RallySoftware/capistrano-srv_hosts.png)](https://travis-ci.org/RallySoftware/capistrano-srv_hosts)
2
+
3
+ Capistrano extension to fetch deploy hosts via DNS SRV records.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-srv_hosts'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself:
16
+
17
+ $ gem install capistrano-srv_hosts
18
+
19
+ ## Usage
20
+
21
+ Create appropriate DNS records, e.g.:
22
+
23
+ # service proto name ttl class type priority weight port target
24
+ _service._tcp.example.com 3600 IN SRV 10 1000 0 server01.example.com
25
+ _service._tcp.example.com 3600 IN SRV 20 1000 0 server02.example.com
26
+
27
+ Configure your config/deploy.rb:
28
+
29
+ At the top add:
30
+
31
+ ```ruby
32
+ require 'capistrano/srv_hosts'
33
+ ```
34
+
35
+ Then you can define roles like this:
36
+
37
+ ```ruby
38
+ srv_role :app, '_service._tcp.example.com'
39
+ srv_role :web, '_service._tcp.example.com', :primary => true
40
+ ```
41
+
42
+ And like this:
43
+
44
+ ```ruby
45
+ role :db, srv_hosts('_service._tcp.example.com').first, :primary => true
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
55
+
56
+ ## Copyright
57
+
58
+ © Rally Software Development Corp. Released under MIT license, see
59
+ [LICENSE](https://github.com/RallySoftware/capistrano-srv_hosts/blob/master/LICENSE.TXT)
60
+ for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'capistrano/srv_hosts/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-srv_hosts"
7
+ s.version = Capistrano::SrvHosts::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tuomas Silen"]
10
+ s.email = ["tsilen@rallydev.com"]
11
+ s.homepage = ""
12
+ s.license = "MIT"
13
+ s.summary = %q{Capistrano extension to fetch deploy hosts via DNS}
14
+ s.description = %q{Allows capistrano to configure deploy hosts and roles using DNS SRV records}
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'capistrano', '>= 2'
22
+ s.add_development_dependency 'bundler', '~> 1.3'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rspec', '~> 2.13'
25
+ end
@@ -0,0 +1 @@
1
+ require 'capistrano/srv_hosts'
@@ -0,0 +1,28 @@
1
+ require 'capistrano'
2
+ require 'resolv'
3
+
4
+ module Capistrano::SrvHosts
5
+ module InstanceMethods
6
+ def srv_hosts(srv_record)
7
+ @srv_hosts ||= {}
8
+ @srv_hosts[srv_record] ||= Resolv::DNS.open do |dns|
9
+ dns.getresources(srv_record, Resolv::DNS::Resource::IN::SRV).sort_by{|rr| [rr.priority, rr.weight, rr.target.to_s]}.map{ |rr| rr.target.to_s}
10
+ end
11
+ @srv_hosts[srv_record].dup
12
+ end
13
+
14
+ def srv_role(new_role, srv_record, *params)
15
+ role new_role, *srv_hosts(srv_record), *params
16
+ end
17
+ end
18
+
19
+ def self.load_into(configuration)
20
+ configuration.load do
21
+ extend InstanceMethods
22
+ end
23
+ end
24
+ end
25
+
26
+ if Capistrano::Configuration.instance
27
+ Capistrano::SrvHosts.load_into(Capistrano::Configuration.instance(:must_exist))
28
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module SrvHosts
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/srv_hosts'
3
+
4
+ describe Capistrano::SrvHosts do
5
+ before(:all) do
6
+ @test_data = [
7
+ srv_record(15, 1000, 0, 'server04.example.com'),
8
+ srv_record(10, 1000, 0, 'server03.example.com'),
9
+ srv_record(10, 1000, 0, 'server02.example.com'),
10
+ srv_record(10, 1005, 0, 'server01.example.com')
11
+ ]
12
+ end
13
+
14
+ before(:each) do
15
+ @configuration = Capistrano::Configuration.new
16
+ Capistrano::SrvHosts.load_into(@configuration)
17
+ end
18
+
19
+ it 'should load instance methods into Capistrano' do
20
+ @configuration.methods.should include(:srv_hosts)
21
+ @configuration.methods.should include(:srv_role)
22
+ end
23
+
24
+ describe '#srv_hosts' do
25
+ it 'should query DNS and cache results' do
26
+ Resolv::DNS.any_instance.should_receive(:getresources).with('_test._tcp.example.com', Resolv::DNS::Resource::IN::SRV).exactly(1).times.and_return(@test_data)
27
+ @configuration.srv_hosts('_test._tcp.example.com')
28
+ @configuration.srv_hosts('_test._tcp.example.com')
29
+ end
30
+
31
+ it 'should sort the results properly' do
32
+ Resolv::DNS.any_instance.should_receive(:getresources).with('_test._tcp.example.com', Resolv::DNS::Resource::IN::SRV).exactly(1).times.and_return(@test_data)
33
+ res = @configuration.srv_hosts('_test._tcp.example.com')
34
+ res.size.should eq(4)
35
+ res.should eq(['server02.example.com', 'server03.example.com', 'server01.example.com', 'server04.example.com'])
36
+ end
37
+ end
38
+
39
+ describe '#srv_role' do
40
+ it 'should define the role' do
41
+ @configuration.should_receive(:srv_hosts).and_return(['server01.example.com', 'server02.example.com'])
42
+ @configuration.srv_role :app, '_test._tcp.example.com'
43
+ @configuration.roles[:app].servers.size.should eq(2)
44
+ @configuration.roles[:app].servers.map(&:to_s).should eq(['server01.example.com', 'server02.example.com'])
45
+ end
46
+
47
+ it 'should handle role params' do
48
+ @configuration.should_receive(:srv_hosts).and_return(['server01.example.com'])
49
+ @configuration.srv_role :app, '_test._tcp.example.com', :primary => true
50
+ @configuration.roles[:app].servers.size.should eq(1)
51
+ @configuration.roles[:app].servers.first.options.should eq({:primary => true})
52
+ end
53
+ end
54
+
55
+ def srv_record(priority, weight, port, host)
56
+ Resolv::DNS::Resource::IN::SRV.new(priority, weight, port, host)
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-srv_hosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tuomas Silen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.13'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.13'
78
+ description: Allows capistrano to configure deploy hosts and roles using DNS SRV records
79
+ email:
80
+ - tsilen@rallydev.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .travis.yml
86
+ - Gemfile
87
+ - LICENSE.TXT
88
+ - README.md
89
+ - Rakefile
90
+ - capistrano-srv_hosts.gemspec
91
+ - lib/capistrano-srv_hosts.rb
92
+ - lib/capistrano/srv_hosts.rb
93
+ - lib/capistrano/srv_hosts/version.rb
94
+ - spec/capistrano/srv_hosts_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.21
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Capistrano extension to fetch deploy hosts via DNS
121
+ test_files:
122
+ - spec/capistrano/srv_hosts_spec.rb
123
+ - spec/spec_helper.rb
124
+ has_rdoc: