serverspec_launcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/serverspec_launcher +6 -0
- data/lib/serverspec_launcher.rb +28 -0
- data/lib/serverspec_launcher/generators/properties_generator.rb +20 -0
- data/lib/serverspec_launcher/generators/rakefile_generator.rb +27 -0
- data/lib/serverspec_launcher/generators/spec_helper_generator.rb +31 -0
- data/lib/serverspec_launcher/helpers/example_helper.rb +36 -0
- data/lib/serverspec_launcher/rake_tasks.rb +85 -0
- data/lib/serverspec_launcher/spec_helper.rb +138 -0
- data/lib/serverspec_launcher/version.rb +4 -0
- data/serverspec_launcher.gemspec +32 -0
- data/templates/Rakefile.erb +4 -0
- data/templates/properties.yaml.erb +29 -0
- data/templates/spec_helper.rb.erb +3 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54df11a8e83985bf1b74d55deb896aaf745b1bdc
|
4
|
+
data.tar.gz: f24d8a347c715aa6a482572f1b2fc5019e3f1f0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbbb6c3ab6bd5fb632c45681b1248ca89b6cdb63a4256e52c34a6829fd2c6cda4e0151fc61b01d6671c481d5f32f88b721fa15b322b86b0c40c045236e727c97
|
7
|
+
data.tar.gz: aada362882b7d3f74e93829c3e19563df09c79c34a640a57105ca4f8f6944bd5493a6a41b1f395c32a9501cf513e2b68e55c79e7b044c7a7d3ade760ee70c461
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at andrew.g.wardrobe@googlemail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Andrew Wardrobe
|
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
|
+
# serverspec_launcher
|
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/serverspec_launcher`. 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 'serverspec_launcher'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install serverspec_launcher
|
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 spec` 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/andrewwardrobe/serverspec_launcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://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
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'serverspec_launcher'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'serverspec_launcher/version'
|
3
|
+
require 'serverspec_launcher/generators/properties_generator'
|
4
|
+
require 'serverspec_launcher/generators/rakefile_generator'
|
5
|
+
require 'serverspec_launcher/generators/spec_helper_generator'
|
6
|
+
|
7
|
+
# Main Class
|
8
|
+
module ServerspecLauncher
|
9
|
+
def self.generate_properties
|
10
|
+
properties = PropertiesGenerator.new
|
11
|
+
properties.generate
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.check_args(args)
|
15
|
+
if args.length.zero?
|
16
|
+
puts 'Usage: serverspec_launcher init'
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.process_command(args)
|
22
|
+
check_args args
|
23
|
+
command = args.shift
|
24
|
+
parameters = args
|
25
|
+
|
26
|
+
generate_properties if command == 'init'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Generates the propetires.yml to be used in tests
|
5
|
+
class PropertiesGenerator
|
6
|
+
def initialize(root_path = nil)
|
7
|
+
path = root_path ? "#{root_path}/" : ''
|
8
|
+
@template_path = File.expand_path('../../../../templates', __FILE__)
|
9
|
+
@properties_file = "#{path}properties.yaml"
|
10
|
+
end
|
11
|
+
|
12
|
+
def properties_template
|
13
|
+
File.read "#{@template_path}/properties.yaml.erb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
renderer = ERB.new properties_template
|
18
|
+
File.open(@properties_file, 'w') { |file| file.write renderer.result }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Generates the rakefile that will bring in the serverspec tasks
|
5
|
+
class RakefileGenerator
|
6
|
+
def initialize(root_path = nil)
|
7
|
+
path = root_path ? "#{root_path}/" : ''
|
8
|
+
@template_path = File.expand_path('../../../../templates', __FILE__)
|
9
|
+
@rakefile = "#{path}Rakefile"
|
10
|
+
end
|
11
|
+
|
12
|
+
def rakefile_template
|
13
|
+
File.read "#{@template_path}/Rakefile.erb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
if File.exist? @rakefile
|
18
|
+
str = File.read(@rakefile)
|
19
|
+
str.sub!(/((require .*\n)+)/, "\\1require 'serverspec_launcher/rake_tasks'\n")
|
20
|
+
File.open(@rakefile, 'w') { |file| file.write str }
|
21
|
+
else
|
22
|
+
renderer = ERB.new rakefile_template
|
23
|
+
File.open(@rakefile, 'w') { |file| file.write renderer.result }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Generate the spec_helpr.rb file
|
5
|
+
class SpecHelperGenerator
|
6
|
+
def initialize(root_path = nil)
|
7
|
+
path = root_path ? "#{root_path}/" : ''
|
8
|
+
@template_path = File.expand_path('../../../../templates', __FILE__)
|
9
|
+
@spec_helper = "#{path}spec/spec_helper.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def rakefile_template
|
13
|
+
File.read "#{@template_path}/spec_helper.rb.erb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_spec_dir
|
17
|
+
Dir.mkdir File.dirname(@spec_helper) unless File.exist?(File.dirname(@spec_helper))
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate
|
21
|
+
if File.exist?(@spec_helper)
|
22
|
+
str = File.read(@spec_helper)
|
23
|
+
str.sub!(/((require .*\n)+)/, "\\1require 'serverspec_launcher/spec_helper'\n")
|
24
|
+
File.open(@spec_helper, 'w') { |file| file.write str }
|
25
|
+
else
|
26
|
+
create_spec_dir
|
27
|
+
renderer = ERB.new rakefile_template
|
28
|
+
File.open(@spec_helper, 'w') { |file| file.write renderer.result }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
# Helper to load and list shared_examples loaded in to RSpec
|
7
|
+
module ExampleHelper
|
8
|
+
def shared_examples
|
9
|
+
groups = RSpec.world.shared_example_group_registry.send(:shared_example_groups)
|
10
|
+
examples = groups[:main].map do |example, _details|
|
11
|
+
example
|
12
|
+
end
|
13
|
+
examples
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_shared_examples(shared_example_gems = [], project_root = Dir.pwd)
|
17
|
+
load_bundled_examples(shared_example_gems)
|
18
|
+
Dir.glob("#{project_root}/**/*.rb") do |path|
|
19
|
+
require path if File.open(path).grep(/shared_examples/).any?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def load_bundled_examples(shared_example_gems)
|
24
|
+
Bundler.load.specs.map(&:name).each do |dep|
|
25
|
+
next unless shared_example_gems.include? dep
|
26
|
+
load_examples_from_gem(dep)
|
27
|
+
load_examples_from_gem(dep.tr('-', '/'))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_examples_from_gem(dep)
|
32
|
+
Gem.find_files("#{dep}/**/*.rb").each do |path|
|
33
|
+
require path if File.open(path).grep(/shared_examples/).any?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
8
|
+
require 'serverspec_launcher/helpers/example_helper'
|
9
|
+
|
10
|
+
# loads up the rake tasks
|
11
|
+
class ServerspecLauncherRakeTasks
|
12
|
+
include ::Rake::DSL if defined?(::Rake::DSL)
|
13
|
+
include ExampleHelper
|
14
|
+
|
15
|
+
def initialize(properties = nil)
|
16
|
+
@properties = properties ? properties : YAML.load_file('properties.yml')
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_tasks
|
20
|
+
task serverspec: 'serverspec:all'
|
21
|
+
|
22
|
+
debug_tasks
|
23
|
+
|
24
|
+
namespace :serverspec do
|
25
|
+
task all: @properties[:targets].keys.map { |key| 'serverspec:' + key.split('.')[0] }
|
26
|
+
@properties[:targets].keys.each do |key|
|
27
|
+
target = @properties[:targets][key]
|
28
|
+
spec_type = target[:spec_type] || 'default'
|
29
|
+
if target[:hosts].is_a?(Array)
|
30
|
+
|
31
|
+
task_array(key, spec_type, target)
|
32
|
+
elsif target[:hosts]
|
33
|
+
host = target[:hosts]
|
34
|
+
task_name = (key || target[:name]).to_s
|
35
|
+
rake_task(host, key, task_name, spec_type)
|
36
|
+
else
|
37
|
+
task_name = (key || target[:name]).to_s
|
38
|
+
rake_task(key, key, task_name, spec_type)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def task_array(key, spec_type, target)
|
45
|
+
desc "Run serverspec to #{key}"
|
46
|
+
task key.to_sym => "serverspec:#{key}:all"
|
47
|
+
namespace key.to_sym do
|
48
|
+
task all: target[:hosts].map { |host| "serverspec:#{key}:#{host.split('.')[0].to_sym}" }
|
49
|
+
target[:hosts].each do |host|
|
50
|
+
task_name = "#{key}:#{host || target[:name]}"
|
51
|
+
rake_task(host, key, task_name, spec_type)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def rake_task(host, key, task_name, spec_type)
|
57
|
+
desc "Run serverspec to #{key}"
|
58
|
+
RSpec::Core::RakeTask.new(host.split('.')[0].to_sym) do |t|
|
59
|
+
ENV['TARGET_HOST'] = host
|
60
|
+
ENV['TARGET'] = key
|
61
|
+
ENV['TASK_NAME'] = task_name
|
62
|
+
t.pattern = "spec/#{spec_type}_spec.rb"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def debug_tasks
|
67
|
+
namespace :debug do
|
68
|
+
desc 'View loaded Shared examples'
|
69
|
+
task :shared_examples do
|
70
|
+
puts 'Loaded Shared Examples:\n======================='
|
71
|
+
load_shared_examples @properties[:shared_example_gems] || []
|
72
|
+
shared_examples.each do |ex|
|
73
|
+
puts "\t#{ex}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.load(properties = nil)
|
80
|
+
tasks = ServerspecLauncherRakeTasks.new properties
|
81
|
+
tasks.load_tasks
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
ServerspecLauncherRakeTasks.load unless $dont_load_rake_tasks
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'serverspec'
|
5
|
+
require 'rspec'
|
6
|
+
|
7
|
+
require 'net/ssh'
|
8
|
+
require 'tempfile'
|
9
|
+
require 'yaml'
|
10
|
+
require 'rubygems'
|
11
|
+
require 'docker'
|
12
|
+
require 'bundler'
|
13
|
+
require 'specinfra'
|
14
|
+
|
15
|
+
require 'serverspec_launcher/helpers/example_helper'
|
16
|
+
|
17
|
+
# Does all the setup fo r the serverspec tests
|
18
|
+
class SpecHelper
|
19
|
+
include ExampleHelper
|
20
|
+
|
21
|
+
attr_reader :properties
|
22
|
+
def initialize(host = ENV['TARGET_HOST'], target = ENV['TARGET'], properties = nil)
|
23
|
+
@host = host
|
24
|
+
@target = target
|
25
|
+
|
26
|
+
load_properties properties
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_properties(properties = nil)
|
30
|
+
@properties = properties ? properties : YAML.load_file('properties.yml')
|
31
|
+
@target_properties = @properties[:targets][@target]
|
32
|
+
@backend = @target_properties[:backend] || 'ssh'
|
33
|
+
@target_properties[:target] = ENV['TASK_NAME']
|
34
|
+
set_property @target_properties
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_backend
|
38
|
+
if @backend == 'exec'
|
39
|
+
set :backend, :exec
|
40
|
+
elsif @backend == 'docker'
|
41
|
+
docker_backend
|
42
|
+
else
|
43
|
+
ssh_backend
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def ssh_backend
|
48
|
+
set :backend, :ssh
|
49
|
+
|
50
|
+
sudo_checks
|
51
|
+
|
52
|
+
ssh_user = @target_properties[:user] || Etc.getlogin
|
53
|
+
|
54
|
+
options = if @backend == 'vagrant'
|
55
|
+
vagrant_backend
|
56
|
+
else
|
57
|
+
Net::SSH::Config.for(@host)
|
58
|
+
end
|
59
|
+
|
60
|
+
options[:user] ||= ssh_user
|
61
|
+
|
62
|
+
set :host, options[:host_name] || @host
|
63
|
+
set :ssh_options, options
|
64
|
+
|
65
|
+
# Disable sudo
|
66
|
+
# set :disable_sudo, true
|
67
|
+
|
68
|
+
# Set environment variables
|
69
|
+
return unless @target_properties[:environment]
|
70
|
+
|
71
|
+
env = @target_properties[:environment].map do |en|
|
72
|
+
variable, value = en.split('=')
|
73
|
+
{ variable.to_sym => value }
|
74
|
+
end.reduce({}, :merge)
|
75
|
+
set :env, env
|
76
|
+
set :env, 'LEEK' => 'SHEEK'
|
77
|
+
puts env
|
78
|
+
end
|
79
|
+
|
80
|
+
def sudo_checks
|
81
|
+
if ENV['ASK_SUDO_PASSWORD']
|
82
|
+
begin
|
83
|
+
require 'highline/import'
|
84
|
+
rescue LoadError
|
85
|
+
raise 'highline is not available. Try installing it.'
|
86
|
+
end
|
87
|
+
set :sudo_password, ask('Enter sudo password: ') { |q| q.echo = false }
|
88
|
+
else
|
89
|
+
set :sudo_password, ENV['SUDO_PASSWORD']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def vagrant_backend
|
94
|
+
@host = @target_properties[:vagrant_host] || 'default'
|
95
|
+
vagrant_dir = @target_properties[:vagrant_host]
|
96
|
+
|
97
|
+
old_dir = Dir.pwd
|
98
|
+
Dir.chdir(vagrant_dir) if vagrant_dir
|
99
|
+
`vagrant up #{@host}`
|
100
|
+
|
101
|
+
config = Tempfile.new('', Dir.tmpdir)
|
102
|
+
config.write(`vagrant ssh-config #{@host}`)
|
103
|
+
config.close
|
104
|
+
Dir.chdir old_dir
|
105
|
+
Net::SSH::Config.for(host, [config.path])
|
106
|
+
end
|
107
|
+
|
108
|
+
def docker_backend
|
109
|
+
set :backend, :docker
|
110
|
+
|
111
|
+
set_docker_image
|
112
|
+
set_docker_container
|
113
|
+
set :docker_url, @target_properties[:docker_url] if @target_properties[:docker_url]
|
114
|
+
end
|
115
|
+
|
116
|
+
def set_docker_container
|
117
|
+
set :docker_container, @target_properties[:docker_container] if @target_properties[:docker_container]
|
118
|
+
set :docker_container_create_options, @target_properties[:docker_options] if @target_properties[:docker_options]
|
119
|
+
end
|
120
|
+
|
121
|
+
def set_docker_image
|
122
|
+
if @target_properties[:docker_build_dir]
|
123
|
+
image = Docker::Image.build_from_dir(@target_properties[:docker_build_dir])
|
124
|
+
set :docker_image, image.id
|
125
|
+
end
|
126
|
+
set :docker_image, @target_properties[:docker_image] if @target_properties[:docker_image]
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.load(host = ENV['TARGET_HOST'], target = ENV['TARGET'], properties = nil)
|
130
|
+
helper = SpecHelper.new host, target, properties
|
131
|
+
props = helper.properties[:shared_example_gems] || []
|
132
|
+
helper.load_shared_examples props
|
133
|
+
helper.setup_backend
|
134
|
+
helper
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
SpecHelper.load unless $dont_load_spec_helper
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'serverspec_launcher/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'serverspec_launcher'
|
9
|
+
spec.version = ServerspecLauncher::VERSION
|
10
|
+
spec.authors = ['Andrew Wardrobe']
|
11
|
+
spec.email = ['andrew.g.wardrobe@googlemail.com']
|
12
|
+
|
13
|
+
spec.summary = 'A utility to manage serverspec scripts'
|
14
|
+
spec.description = 'A utility to manage serverspec scripts'
|
15
|
+
spec.homepage = "https://github.com/andrewwardrobe/serverspec_launcher"
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
30
|
+
spec.add_runtime_dependency 'serverspec'
|
31
|
+
spec.add_runtime_dependency 'docker'
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
:targets:
|
3
|
+
# ssh-example:
|
4
|
+
# :hosts:
|
5
|
+
# - raspberrypi
|
6
|
+
# - blueberrypi
|
7
|
+
# :user: pi
|
8
|
+
# :roles:
|
9
|
+
# - development::docker
|
10
|
+
# exec-example:
|
11
|
+
# :backend: exec
|
12
|
+
# :roles:
|
13
|
+
# - :name: development::ruby
|
14
|
+
# :description: Ruby Development
|
15
|
+
# - development::docker
|
16
|
+
# docker-image-example:
|
17
|
+
# :backend: docker
|
18
|
+
# :docker_image: mongo
|
19
|
+
# :roles:
|
20
|
+
# - database::mongo
|
21
|
+
# docker-container-examples:
|
22
|
+
# :backend: docker
|
23
|
+
# :docker_container: jenkins
|
24
|
+
# :roles:
|
25
|
+
# - build_tools::jenkins
|
26
|
+
# vagrant-example:
|
27
|
+
# :backend: vagrant
|
28
|
+
# :roles:
|
29
|
+
# - debug::environment_vars
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: serverspec_launcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Wardrobe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-12 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: docker
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A utility to manage serverspec scripts
|
98
|
+
email:
|
99
|
+
- andrew.g.wardrobe@googlemail.com
|
100
|
+
executables:
|
101
|
+
- serverspec_launcher
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/serverspec_launcher
|
117
|
+
- lib/serverspec_launcher.rb
|
118
|
+
- lib/serverspec_launcher/generators/properties_generator.rb
|
119
|
+
- lib/serverspec_launcher/generators/rakefile_generator.rb
|
120
|
+
- lib/serverspec_launcher/generators/spec_helper_generator.rb
|
121
|
+
- lib/serverspec_launcher/helpers/example_helper.rb
|
122
|
+
- lib/serverspec_launcher/rake_tasks.rb
|
123
|
+
- lib/serverspec_launcher/spec_helper.rb
|
124
|
+
- lib/serverspec_launcher/version.rb
|
125
|
+
- serverspec_launcher.gemspec
|
126
|
+
- templates/Rakefile.erb
|
127
|
+
- templates/properties.yaml.erb
|
128
|
+
- templates/spec_helper.rb.erb
|
129
|
+
homepage: https://github.com/andrewwardrobe/serverspec_launcher
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.6.10
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: A utility to manage serverspec scripts
|
153
|
+
test_files: []
|