rundock-plugin-hook-serverspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27b9d875602ceb256142cf34d9d906c09bf89362
4
+ data.tar.gz: 6cf85b353465c3114bdf5ec955d95a8d0cc9dff9
5
+ SHA512:
6
+ metadata.gz: 97b2665988ddf5bd997572bc18f7fe9cc8d6531709730eb1dae178c201c917778e377af89d190b9c55194a2d84512d08e4d065189b1165b9d921e0d3a721b043
7
+ data.tar.gz: c6b51da4c66c26e8d9c990dfd6e5d901181b90ec4a739a688edc19ac0431f0587c20ca666ae1984a7f3fdccbf1d355e040ef08f61452718044d8e5efa2d14b44
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ Gemfile.lock
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rundock-plugin-hook-serverspec.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 hiracy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Rundock::Plugin::Hook::Serverspec
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rundock/plugin/hook/serverspec`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rundock-plugin-hook-serverspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rundock-plugin-hook-serverspec
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rundock-plugin-hook-serverspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => [:spec]
6
+
7
+ desc 'Run all tests.'
8
+ task :spec => ['clean', 'rundock']
9
+
10
+ desc 'Cleaning environments'
11
+
12
+ task :clean do
13
+ Bundler.with_clean_env do
14
+ system 'rm -f /var/tmp/hello_rundock*'
15
+ end
16
+ end
17
+
18
+ desc "Run rundock-serverspec plugin"
19
+
20
+ task :rundock do
21
+ cmd = 'bundle exec rundock do ./spec/integration/scenario.yml -k ./spec/integration/hooks.yml -l debug'
22
+ puts "[EXEC: ] #{cmd}"
23
+ system cmd
24
+ end
25
+
26
+ task :serverspec do
27
+ RSpec::Core::RakeTask.new(:serverspec) do |rt|
28
+ rt.ruby_opts = "-I #{File.expand_path(File.dirname(__FILE__))}"
29
+ rt.pattern = ENV['PATTERN'].split(',')
30
+ end
31
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rundock/plugin/hook/serverspec"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,7 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.0.0-p195
4
+
5
+ test:
6
+ override:
7
+ - bundle exec rake spec
@@ -0,0 +1,9 @@
1
+ module Rundock
2
+ module Plugin
3
+ module Hook
4
+ module Serverspec
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,85 @@
1
+ require "rundock/plugin/hook/serverspec/version"
2
+ require 'rake'
3
+
4
+ module Rundock
5
+ module Hook
6
+ # You can use this sample as following yaml files for example.
7
+ #
8
+ # rundock do scenario.yml -k hook.yml
9
+ #
10
+ # [hook.yml]
11
+ # check_os:
12
+ # hook_type: serverspec
13
+ # pattern: /path/to/check_os/*_spec.rb
14
+ # check_nginx:
15
+ # hook_type: serverspec
16
+ # pattern: /path/to/nginx/*_spec.rb
17
+ # host_properties: /path/to/properties.yml
18
+ #
19
+ # [scenario.yml]
20
+ # - node: anyhost-01
21
+ # hook:
22
+ # - check_os
23
+ # - node: anyhost-02
24
+ # deploy:
25
+ # - src: /path/to/nginx.conf.local
26
+ # dst: /etc/nginx/nginx.conf
27
+ # command:
28
+ # - 'sudo /etc/init.d/nginx reload'
29
+ # hook:
30
+ # - check_os
31
+ # - check_nginx
32
+ # ---
33
+ # anyhost-01:
34
+ # host: 192.168.1.11
35
+ # # inherit from ./defautl_ssh.yml
36
+ # anyhost-02:
37
+ # host: 192.168.1.12
38
+ # ssh_opts:
39
+ # port: 22
40
+ # user: anyuser
41
+ # key: ~/.ssh/id_rsa
42
+ # ---
43
+ #
44
+ # [properties.yml]
45
+ # anyhost-02:
46
+ # anykey1: value1
47
+ # anykey2: value2
48
+
49
+ class Serverspec < Base
50
+ def hook(log_buffer, node_info)
51
+ setenv(node_info, @contents)
52
+ load "#{::File.expand_path(::File.dirname(__FILE__))}/../../../../Rakefile"
53
+ Logger.info("serverspec started: #{node_info[:nodename]}(#{node_info[:host]})")
54
+ Rake.application[:serverspec].invoke
55
+ Rake.application[:serverspec].reenable
56
+ end
57
+
58
+ private
59
+
60
+ def setenv(nodeinfo, contents)
61
+ ENV['PATTERN'] = Array(@contents[:pattern]).join(',')
62
+ ENV['TARGET_HOST'] = nodeinfo[:nodename]
63
+ ENV['TARGET_SSH_HOST'] = nodeinfo[:host]
64
+ ENV['HOST_PROPERTIES'] = contents[:host_properties]
65
+ ENV['SSH_CONFIG'] = nodeinfo[:ssh_config]
66
+ ENV['KEYS'] = nodeinfo[:keys].join(',') if nodeinfo.key?(:keys)
67
+ ENV['KEYS'] = nodeinfo[:key] if nodeinfo.key?(:key)
68
+ ENV['PASSWORD'] = nodeinfo[:password] if nodeinfo.key?(:password)
69
+ ENV['PROXY'] = nodeinfo[:proxy] if nodeinfo.key?(:proxy)
70
+ ENV['USER'] = nodeinfo[:user] if nodeinfo.key?(:user)
71
+ ENV['PORT'] = nodeinfo[:port].to_s if nodeinfo.key?(:port)
72
+ ENV['USER_KNOWN_HOSTS_FILE'] = nodeinfo[:user_known_hosts_file] if nodeinfo.key?(:user_known_hosts_file)
73
+ ENV['ENCRIPTION'] = nodeinfo[:encryption] if nodeinfo.key?(:encryption)
74
+ ENV['COMPRESSION'] = nodeinfo[:compression] if nodeinfo.key?(:compression)
75
+ ENV['COMPRESSION_LEVEL'] = nodeinfo[:compression_level] if nodeinfo.key?(:compression_level)
76
+ ENV['TIMEOUT'] = nodeinfo[:timeout].to_s if nodeinfo.key?(:timeout)
77
+ ENV['FORWARD_AGENT'] = nodeinfo[:forward_agent] if nodeinfo.key?(:forward_agent)
78
+ ENV['GLOBAL_KNOWN_HOSTS_FILE'] = nodeinfo[:global_known_hosts_file] if nodeinfo.key?(:global_known_hosts_file)
79
+ ENV['AUTH_METHODS'] = nodeinfo[:auth_methods].join(',') if nodeinfo.key?(:auth_methods)
80
+ ENV['HMAC'] = nodeinfo[:hmac] if nodeinfo.key?(:hmac)
81
+ ENV['REKEY_LIMIT'] = nodeinfo[:rekey_limit].to_s if nodeinfo.key?(:rekey_limit)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rundock/plugin/hook/serverspec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rundock-plugin-hook-serverspec"
8
+ spec.version = Rundock::Plugin::Hook::Serverspec::VERSION
9
+ spec.authors = ["hiracy"]
10
+ spec.email = ["leizhen@mbr.nifty.com"]
11
+
12
+ spec.summary = %q{rundock plugin for serverspec hook}
13
+ spec.homepage = 'https://github.com/hiracy/rundock-plugin-hook-serverspec'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency "rundock"
24
+ spec.add_runtime_dependency "net-ssh"
25
+ spec.add_runtime_dependency "serverspec"
26
+ end
data/spec_helper.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'serverspec'
2
+ require 'net/ssh'
3
+ require 'yaml'
4
+
5
+ def ssh_opts
6
+ if ENV['SSH_CONFIG'] && FileTest.exists?(ENV['SSH_CONFIG'])
7
+ opts = Net::SSH::Config.for(ENV['TARGET_HOST'] , [ENV['SSH_CONFIG']])
8
+ else
9
+ opts = Net::SSH::Config.for(ENV['TARGET_HOST'])
10
+ end
11
+
12
+ opts[:host_name] = ENV['TARGET_SSH_HOST']
13
+ opts[:user] = ENV['USER'] || Etc.getlogin
14
+ opts[:keys] = ENV['KEYS'].split(',') if ENV['KEYS']
15
+ opts[:password] = ENV['PASSWORD'] if ENV['PASSWORD']
16
+ opts[:proxy] = Kernel.eval(ENV['PROXY']) if ENV['PROXY']
17
+ opts[:port] = ENV['PORT'] if ENV['PORT']
18
+ opts[:user_known_hosts_file] = ENV['USER_KNOWN_HOSTS_FILE'] if ENV['USER_KNOWN_HOSTS_FILE']
19
+ opts[:encryption] = ENV['ENCRIPTION'] if ENV['ENCRIPTION']
20
+ opts[:compression] = ENV['COMPRESSION'] if ENV['COMPRESSION']
21
+ opts[:compression_level] = ENV['COMPRESSION_LEVEL'] if ENV['COMPRESSION_LEVEL']
22
+ opts[:timeout] = ENV['TIMEOUT'] if ENV['TIMEOUT']
23
+ opts[:forward_agent] = ENV['FORWARD_AGENT'] if ENV['FORWARD_AGENT']
24
+ opts[:global_known_hosts_file] = ENV['GLOBAL_KNOWN_HOSTS_FILE'] if ENV['GLOBAL_KNOWN_HOSTS_FILE']
25
+ opts[:auth_methods] = ENV['AUTH_METHODS'].split(',') if ENV['AUTH_METHODS']
26
+ opts[:hmac] = ENV['HMAC'] if ENV['HMAC']
27
+ opts[:rekey_limit] = ENV['REKEY_LIMIT'] if ENV['REKEY_LIMIT']
28
+
29
+ opts
30
+ end
31
+
32
+ set_property(YAML.load_file(ENV['HOST_PROPERTIES'])[ENV['TARGET_HOST']]) if ENV['HOST_PROPERTIES']
33
+
34
+ if ENV['TARGET_SSH_HOST'] != 'localhost'&&
35
+ ENV['TARGET_SSH_HOST'] != '127.0.0.1'
36
+
37
+ set :ssh_options, ssh_opts
38
+ set :backend, :ssh
39
+ else
40
+ set :backend, :exec
41
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rundock-plugin-hook-serverspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hiracy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rundock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ssh
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: serverspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - leizhen@mbr.nifty.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - circle.yml
100
+ - lib/rundock/plugin/hook/serverspec.rb
101
+ - lib/rundock/plugin/hook/serverspec/version.rb
102
+ - rundock-plugin-hook-serverspec.gemspec
103
+ - spec_helper.rb
104
+ homepage: https://github.com/hiracy/rundock-plugin-hook-serverspec
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: rundock plugin for serverspec hook
128
+ test_files: []