dev-consul 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +23 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +59 -0
- data/Rakefile +20 -0
- data/bin/consul_0.6.4_darwin_386 +0 -0
- data/bin/consul_0.6.4_darwin_amd64 +0 -0
- data/bin/consul_0.6.4_freebsd_386 +0 -0
- data/bin/consul_0.6.4_freebsd_amd64 +0 -0
- data/bin/consul_0.6.4_freebsd_arm +0 -0
- data/bin/consul_0.6.4_linux_386 +0 -0
- data/bin/consul_0.6.4_linux_amd64 +0 -0
- data/bin/consul_0.6.4_linux_arm +0 -0
- data/bin/consul_0.6.4_solaris_amd64 +0 -0
- data/dev-consul.gemspec +27 -0
- data/lib/dev/consul/build.rb +55 -0
- data/lib/dev/consul/version.rb +5 -0
- data/lib/dev/consul.rb +106 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 238b535dccb9e4783798a09ba3b87b2fe5f180e3
|
4
|
+
data.tar.gz: 7807db2097ae7c00759061f7c5eb6da0e97dbdc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5555252d67edd303f066abcd0777cc7b0c92f1294c6a7be6c049f24e360c04adb32fcbf5abb47785be67cba20f7b2fb66f94c4075bca5b43d78356ccce7f0c63
|
7
|
+
data.tar.gz: 4fe4336c672456016f97f49f79cb4de8bb27d488e81322d6f5416b4a78c739d43e918fc29aaee3684c340c16101c6aabb93de0c6833569269b82952943bc1aa5
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Metrics/AbcSize:
|
4
|
+
Max: 48
|
5
|
+
Metrics/CyclomaticComplexity:
|
6
|
+
Max: 24
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Max: 48
|
9
|
+
Metrics/PerceivedComplexity:
|
10
|
+
Max: 12
|
11
|
+
|
12
|
+
Encoding:
|
13
|
+
Enabled: false
|
14
|
+
LineLength:
|
15
|
+
Enabled: false
|
16
|
+
HashSyntax:
|
17
|
+
Enabled: false
|
18
|
+
FileName:
|
19
|
+
Enabled: false
|
20
|
+
RescueModifier:
|
21
|
+
Enabled: false
|
22
|
+
SpaceInsideStringInterpolation:
|
23
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright (c) 2016 Rapid7 Inc.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
this software and associated documentation files (the "Software"), to deal in the
|
6
|
+
Software without restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
8
|
+
Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
12
|
+
copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Dev::Consul
|
2
|
+
===========
|
3
|
+
|
4
|
+
`Dev::Consul` is a simple wrapper around the Consul binary for development and testing. It bundles all of the published Consul binaries at `Dev::Consul::VERSION` and runs the correct build for the local system.
|
5
|
+
|
6
|
+
Note that `Dev::Consul`'s version follows that of Consul.
|
7
|
+
|
8
|
+
Consul is maintained by Hashicorp. Please see https://www.consul.io/ for details.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'dev-consul'
|
16
|
+
```
|
17
|
+
|
18
|
+
Or Gemspec:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
spec.add_development_dependency 'dev-consul', '0.6.4'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle install
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install dev-consul
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Run `bundle exec rake` to launch a local instance of Consul.
|
35
|
+
|
36
|
+
To integrate into tests:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'dev/consul'
|
40
|
+
|
41
|
+
RSpec.configure do |config|
|
42
|
+
config.before(:suite) do
|
43
|
+
Dev::Consul.run
|
44
|
+
|
45
|
+
## Mute output once the consul server is running
|
46
|
+
Dev::Consul.output(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
config.after(:suite) do
|
50
|
+
Dev::Consul.stop
|
51
|
+
end
|
52
|
+
|
53
|
+
## ...
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rapid7/dev-consul.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative './lib/dev/consul/build'
|
2
|
+
|
3
|
+
## On interupt, wait fot the Consul process to shutdown
|
4
|
+
Signal.trap('INT') do
|
5
|
+
Dev::Consul.stop
|
6
|
+
end
|
7
|
+
|
8
|
+
task :fetch do
|
9
|
+
Dev::Consul::Build.fetch
|
10
|
+
end
|
11
|
+
|
12
|
+
task :run do
|
13
|
+
Dev::Consul.run
|
14
|
+
end
|
15
|
+
|
16
|
+
task :wait do
|
17
|
+
Dev::Consul.wait
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => [:run, :wait]
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/dev-consul.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dev/consul/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dev-consul'
|
8
|
+
spec.version = Dev::Consul::VERSION
|
9
|
+
spec.authors = ['John Manero']
|
10
|
+
spec.email = ['jmanero@rapid7.com']
|
11
|
+
|
12
|
+
spec.summary = 'Test/development wrapper for Consul by Hashicorp'
|
13
|
+
spec.description = "dev/consul bundles all of Hashicorp's platform-specific binaries "\
|
14
|
+
'for Consul and provides helpers to detect the local platform '\
|
15
|
+
'and run the right build.'
|
16
|
+
spec.homepage = 'https://github.com/rapid7/dev-consul'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = 'bin'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'zipruby', '~> 0.3'
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../consul'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'zipruby'
|
8
|
+
rescue LoadError
|
9
|
+
puts 'To use Dev::Consul::Build, you must install the zipruby gem!'
|
10
|
+
end
|
11
|
+
|
12
|
+
module Dev
|
13
|
+
module Consul
|
14
|
+
##
|
15
|
+
# Tools to fetch and extract Hashicorp's platform builds of Consul
|
16
|
+
##
|
17
|
+
module Build
|
18
|
+
REPOSITORY = "https://releases.hashicorp.com/consul/#{VERSION}".freeze
|
19
|
+
PACKAGES = [
|
20
|
+
"consul_#{VERSION}_darwin_386.zip",
|
21
|
+
"consul_#{VERSION}_darwin_amd64.zip",
|
22
|
+
"consul_#{VERSION}_freebsd_386.zip",
|
23
|
+
"consul_#{VERSION}_freebsd_amd64.zip",
|
24
|
+
"consul_#{VERSION}_freebsd_arm.zip",
|
25
|
+
"consul_#{VERSION}_linux_386.zip",
|
26
|
+
"consul_#{VERSION}_linux_amd64.zip",
|
27
|
+
"consul_#{VERSION}_linux_arm.zip",
|
28
|
+
"consul_#{VERSION}_solaris_amd64.zip"
|
29
|
+
].freeze
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def fetch
|
33
|
+
uri = URI.parse(REPOSITORY)
|
34
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
35
|
+
client.use_ssl = true if uri.scheme == 'https'
|
36
|
+
|
37
|
+
PACKAGES.each do |package|
|
38
|
+
puts "Fetch #{File.join(uri.path, package)}"
|
39
|
+
request = Net::HTTP::Get.new(File.join(uri.path, package))
|
40
|
+
|
41
|
+
client.request(request) do |response|
|
42
|
+
Zip::Archive.open_buffer(response.body) do |archive|
|
43
|
+
archive.each do |file|
|
44
|
+
next unless file.name == 'consul'
|
45
|
+
|
46
|
+
open(File.join(Consul.bindir, File.basename(package, '.zip')), 'wb', 00755) { |io| io.write(file.read) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/dev/consul.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative './consul/version'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Dev
|
6
|
+
##
|
7
|
+
# Helpers to fetch and run a development-instance of consul
|
8
|
+
##
|
9
|
+
module Consul
|
10
|
+
class << self
|
11
|
+
def bindir
|
12
|
+
File.expand_path('../../bin', __dir__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def architecture
|
16
|
+
case RUBY_PLATFORM
|
17
|
+
when /x86_64/ then 'amd64'
|
18
|
+
when /amd64/ then 'amd64'
|
19
|
+
when /386/ then '386'
|
20
|
+
when /arm/ then 'arm'
|
21
|
+
else raise NameError, "Unable to detect system architecture for #{RUBY_PLATFORM}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def platform
|
26
|
+
case RUBY_PLATFORM
|
27
|
+
when /darwin/ then 'darwin'
|
28
|
+
when /freebsd/ then 'freebsd'
|
29
|
+
when /linux/ then 'linux'
|
30
|
+
when /solaris/ then 'solaris'
|
31
|
+
else raise NameError, "Unable to detect system platfrom for #{RUBY_PLATFORM}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def bin
|
36
|
+
File.join(bindir, "consul_#{VERSION}_#{platform}_#{architecture}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def output(arg = nil)
|
40
|
+
@thread[:output] = arg unless @thread.nil? || arg.nil?
|
41
|
+
@thread[:output] unless @thread.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
puts "Starting #{bin}"
|
46
|
+
|
47
|
+
## Fork a child process for Consul from a thread
|
48
|
+
@thread = Thread.new do
|
49
|
+
IO.popen("#{bin} agent -dev -advertise=127.0.0.1", 'r+') do |io|
|
50
|
+
Thread.current[:process] = io.pid
|
51
|
+
puts "Started #{bin} (#{io.pid})"
|
52
|
+
|
53
|
+
## Stream output
|
54
|
+
loop do
|
55
|
+
break if io.eof?
|
56
|
+
chunk = io.readpartial(1024)
|
57
|
+
|
58
|
+
if Thread.current[:output]
|
59
|
+
Thread.current[:output].write(chunk)
|
60
|
+
Thread.current[:output].flush
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
@thread[:output] = $stdout
|
67
|
+
|
68
|
+
## Wait for the service to become ready
|
69
|
+
loop do
|
70
|
+
begin
|
71
|
+
leader = Net::HTTP.get('localhost', '/v1/status/leader', 8500)
|
72
|
+
|
73
|
+
if leader == '""'
|
74
|
+
puts 'Waiting for Consul HTTP API to be ready'
|
75
|
+
sleep 1
|
76
|
+
end
|
77
|
+
|
78
|
+
puts 'Consul HTTP API is ready!'
|
79
|
+
break
|
80
|
+
|
81
|
+
rescue Errno::ECONNREFUSED
|
82
|
+
puts 'Waiting for Consul HTTP API to be ready'
|
83
|
+
sleep 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def wait
|
89
|
+
@thread.join unless @thread.nil?
|
90
|
+
end
|
91
|
+
|
92
|
+
def stop
|
93
|
+
unless @thread.nil?
|
94
|
+
unless @thread[:process].nil?
|
95
|
+
puts "Stop #{bin} (#{@thread[:process]})"
|
96
|
+
Process.kill('INT', @thread[:process])
|
97
|
+
end
|
98
|
+
|
99
|
+
@thread.join
|
100
|
+
end
|
101
|
+
|
102
|
+
@thread = nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dev-consul
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Manero
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zipruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: dev/consul bundles all of Hashicorp's platform-specific binaries for
|
56
|
+
Consul and provides helpers to detect the local platform and run the right build.
|
57
|
+
email:
|
58
|
+
- jmanero@rapid7.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rubocop.yml
|
65
|
+
- .travis.yml
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/consul_0.6.4_darwin_386
|
71
|
+
- bin/consul_0.6.4_darwin_amd64
|
72
|
+
- bin/consul_0.6.4_freebsd_386
|
73
|
+
- bin/consul_0.6.4_freebsd_amd64
|
74
|
+
- bin/consul_0.6.4_freebsd_arm
|
75
|
+
- bin/consul_0.6.4_linux_386
|
76
|
+
- bin/consul_0.6.4_linux_amd64
|
77
|
+
- bin/consul_0.6.4_linux_arm
|
78
|
+
- bin/consul_0.6.4_solaris_amd64
|
79
|
+
- dev-consul.gemspec
|
80
|
+
- lib/dev/consul.rb
|
81
|
+
- lib/dev/consul/build.rb
|
82
|
+
- lib/dev/consul/version.rb
|
83
|
+
homepage: https://github.com/rapid7/dev-consul
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.0.14.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Test/development wrapper for Consul by Hashicorp
|
107
|
+
test_files: []
|