itamae-spec 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +47 -0
- data/bin/itamae-spec +4 -0
- data/itamae-spec.gemspec +36 -0
- data/lib/itamae-spec.rb +10 -0
- data/lib/itamae-spec/cli.rb +19 -0
- data/lib/itamae-spec/generators.rb +20 -0
- data/lib/itamae-spec/generators/cookbook.rb +10 -0
- data/lib/itamae-spec/generators/project.rb +10 -0
- data/lib/itamae-spec/generators/templates/cookbook/attributes/.keep +0 -0
- data/lib/itamae-spec/generators/templates/cookbook/recipes/default.rb +0 -0
- data/lib/itamae-spec/generators/templates/cookbook/recipes/files/.keep +0 -0
- data/lib/itamae-spec/generators/templates/cookbook/recipes/templates/.keep +0 -0
- data/lib/itamae-spec/generators/templates/cookbook/spec/default_spec.rb +0 -0
- data/lib/itamae-spec/generators/templates/project/.rspec +2 -0
- data/lib/itamae-spec/generators/templates/project/Gemfile +3 -0
- data/lib/itamae-spec/generators/templates/project/Project.json +1 -0
- data/lib/itamae-spec/generators/templates/project/Rakefile +9 -0
- data/lib/itamae-spec/generators/templates/project/cookbooks/sample/attributes/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/cookbooks/sample/attributes/default.json +5 -0
- data/lib/itamae-spec/generators/templates/project/cookbooks/sample/recipes/default.rb +7 -0
- data/lib/itamae-spec/generators/templates/project/cookbooks/sample/recipes/files/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/cookbooks/sample/recipes/templates/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/cookbooks/sample/spec/default_spec.rb +9 -0
- data/lib/itamae-spec/generators/templates/project/environments/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/environments/sample.json +7 -0
- data/lib/itamae-spec/generators/templates/project/keys/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/nodes/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/nodes/sample.json +10 -0
- data/lib/itamae-spec/generators/templates/project/roles/.keep +0 -0
- data/lib/itamae-spec/generators/templates/project/roles/sample.json +5 -0
- data/lib/itamae-spec/generators/templates/project/spec/spec_helper.rb +41 -0
- data/lib/itamae-spec/generators/templates/project/tmp-nodes/.keep +0 -0
- data/lib/itamae-spec/logger.rb +76 -0
- data/lib/itamae-spec/resource.rb +2 -0
- data/lib/itamae-spec/resource/http_request.rb +71 -0
- data/lib/itamae-spec/resource/s3_file.rb +31 -0
- data/lib/itamae-spec/task/base.rb +90 -0
- data/lib/itamae-spec/task/base_task.rb +148 -0
- data/lib/itamae-spec/task/itamae_task.rb +112 -0
- data/lib/itamae-spec/task/local_itamae_task.rb +84 -0
- data/lib/itamae-spec/task/local_serverspec_task.rb +125 -0
- data/lib/itamae-spec/task/serverspec_task.rb +111 -0
- data/lib/itamae-spec/version.rb +3 -0
- data/lib/itamae-spec/version.txt +1 -0
- data/spec/integration/Vagrantfile +35 -0
- data/spec/integration/default_spec.rb +226 -0
- data/spec/integration/recipes/default.rb +423 -0
- data/spec/integration/recipes/default2.rb +6 -0
- data/spec/integration/recipes/define/default.rb +6 -0
- data/spec/integration/recipes/define/files/remote_file_in_definition +1 -0
- data/spec/integration/recipes/dry_run.rb +6 -0
- data/spec/integration/recipes/files/remote_file_auto +1 -0
- data/spec/integration/recipes/hello.erb +6 -0
- data/spec/integration/recipes/hello.txt +1 -0
- data/spec/integration/recipes/included.rb +9 -0
- data/spec/integration/recipes/node.json +3 -0
- data/spec/integration/recipes/redefine.rb +20 -0
- data/spec/integration/recipes/templates/template_auto.erb +6 -0
- data/spec/integration/spec_helper.rb +42 -0
- data/spec/unit/lib/itamae/backend_spec.rb +95 -0
- data/spec/unit/lib/itamae/handler/base_spec.rb +34 -0
- data/spec/unit/lib/itamae/handler/fluentd_spec.rb +19 -0
- data/spec/unit/lib/itamae/handler_proxy_spec.rb +38 -0
- data/spec/unit/lib/itamae/handler_spec.rb +11 -0
- data/spec/unit/lib/itamae/node_spec.rb +14 -0
- data/spec/unit/lib/itamae/recipe_spec.rb +6 -0
- data/spec/unit/lib/itamae/resource/base_spec.rb +127 -0
- data/spec/unit/lib/itamae/resource_spec.rb +23 -0
- data/spec/unit/lib/itamae/runner_spec.rb +32 -0
- data/spec/unit/spec_helper.rb +23 -0
- metadata +315 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 32c0a5e4298c6d97786f447e64e6edea3071ed874f8f347532e33bfa92330fdf
|
4
|
+
data.tar.gz: d69af9290654e7d104d9decb50ff9f6c8afb80587af0189ab1e933264abec152
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1234cfda80bca59a5e53251046f7c743587d692097f80a63033c9bbe150eb18dcc161b703bd3019d416527c327703e02ea8065b486f0f7ab44beca652f46343a
|
7
|
+
data.tar.gz: a3a82b93122ab5b95eddb874f09b14fb0c919e888008b834d32e501a6bb7ad070cefb88bdc11fb2cee752c75b5cda54174d7ec394cc8824cce32442de312c4c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 kammy1231
|
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,42 @@
|
|
1
|
+
[](http://badge.fury.io/rb/itamae-spec)
|
2
|
+
|
3
|
+
Customized version of Itamae
|
4
|
+
|
5
|
+
## Concept
|
6
|
+
|
7
|
+
- Integration with Serverspec
|
8
|
+
- Attributes are defined by: Nodes, Environments, and Recipes
|
9
|
+
- Support for some AWS Resources
|
10
|
+
- Running on the RakeTask
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
```
|
15
|
+
$ gem install itamae-spec
|
16
|
+
$ itamae-spec init your-project-name
|
17
|
+
```
|
18
|
+
|
19
|
+
## If you want to use the AWS Resources
|
20
|
+
```
|
21
|
+
$ aws configure
|
22
|
+
```
|
23
|
+
|
24
|
+
## Getting Started
|
25
|
+
- [Getting Started](https://github.com/kammy1231/itamae-spec/wiki/Getting-Started)
|
26
|
+
|
27
|
+
## Usage AWS Resource
|
28
|
+
- [Customized Resources](https://github.com/kammy1231/itamae-spec/wiki/Customized-Resources)
|
29
|
+
|
30
|
+
## Reference
|
31
|
+
- [itamae](https://github.com/itamae-kitchen/itamae)
|
32
|
+
- [Serverspec](https://github.com/mizzy/serverspec)
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
If you have a problem, please [create an issue](https://github.com/kammy1231/itamae-spec) or a pull request.
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
require 'rake/extensiontask'
|
6
|
+
require 'rake/packagetask'
|
7
|
+
begin
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
rescue LoadError
|
10
|
+
puts 'If you want to create gem, You must install Bundler'
|
11
|
+
end
|
12
|
+
|
13
|
+
require './lib/itamae-spec/version.rb'
|
14
|
+
def version
|
15
|
+
ItamaeSpec::VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::ExtensionTask.new do |ext|
|
19
|
+
ext.name = 'itamae-spec'
|
20
|
+
ext.ext_dir = 'ext/'
|
21
|
+
ext.lib_dir = 'lib/'
|
22
|
+
end
|
23
|
+
|
24
|
+
Rake::PackageTask.new('itamae-spec', "#{version}") do |t|
|
25
|
+
t.need_tar_gz = true
|
26
|
+
t.package_files.include `git ls-files`.split("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :release do
|
30
|
+
desc "Bump up version and commit"
|
31
|
+
task :version_up do
|
32
|
+
version_file = File.expand_path("lib/itamae-spec/version.txt")
|
33
|
+
current_version = File.read(version_file).strip
|
34
|
+
|
35
|
+
if /\A(.+?)(\d+)\z/ =~ current_version
|
36
|
+
next_version = "#{$1}#{$2.to_i + 1}"
|
37
|
+
else
|
38
|
+
raise "Invalid version"
|
39
|
+
end
|
40
|
+
|
41
|
+
open(version_file, "w") do |f|
|
42
|
+
f.write next_version
|
43
|
+
end
|
44
|
+
system "git add #{version_file}"
|
45
|
+
system "git commit -m 'Bump up version'"
|
46
|
+
end
|
47
|
+
end
|
data/bin/itamae-spec
ADDED
data/itamae-spec.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'itamae-spec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "itamae-spec"
|
8
|
+
spec.version = ItamaeSpec::VERSION
|
9
|
+
spec.authors = ["kammy1231"]
|
10
|
+
spec.email = ["akihiro.vamps@gmail.com"]
|
11
|
+
spec.summary = %q{Customized version of Itamae.
|
12
|
+
Integration with Serverspec.
|
13
|
+
It can be provisioning using itamae's some AWS resources.}
|
14
|
+
spec.homepage = "https://github.com/kammy1231/itamae-spec"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
22
|
+
|
23
|
+
spec.add_runtime_dependency "aws-sdk", "~> 2"
|
24
|
+
spec.add_runtime_dependency "serverspec", "~> 2.1"
|
25
|
+
spec.add_runtime_dependency "itamae", "1.9.11"
|
26
|
+
spec.add_runtime_dependency "rake"
|
27
|
+
spec.add_runtime_dependency "multi_json"
|
28
|
+
spec.add_runtime_dependency "bundler"
|
29
|
+
spec.add_runtime_dependency "highline"
|
30
|
+
|
31
|
+
spec.add_development_dependency "rake-compiler"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "pry-byebug"
|
34
|
+
spec.add_development_dependency "docker-api", "~> 1.20"
|
35
|
+
spec.add_development_dependency "fakefs"
|
36
|
+
end
|
data/lib/itamae-spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'itamae-spec'
|
2
|
+
|
3
|
+
module ItamaeSpec
|
4
|
+
class CLI < Itamae::CLI
|
5
|
+
# Support for password authentication
|
6
|
+
option :password, type: :string, desc: 'input ssh password'
|
7
|
+
|
8
|
+
def initialize(*)
|
9
|
+
super
|
10
|
+
|
11
|
+
Itamae.logger.level = ::Logger.const_get(options[:log_level].upcase) if options[:log_level]
|
12
|
+
Itamae.logger.formatter.colored = options[:color] if options[:color]
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
puts "Itamae-Spec v#{ItamaeSpec::VERSION}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "itamae-spec/generators/project"
|
2
|
+
require "itamae-spec/generators/cookbook"
|
3
|
+
|
4
|
+
module Itamae
|
5
|
+
module Generators
|
6
|
+
def self.find(target)
|
7
|
+
case target
|
8
|
+
when 'cookbook'
|
9
|
+
Cookbook
|
10
|
+
when 'project'
|
11
|
+
Project
|
12
|
+
when 'role'
|
13
|
+
puts 'Not support generate role. Do nothing.'
|
14
|
+
exit 1
|
15
|
+
else
|
16
|
+
raise "Unexpected target: #{target}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"project":"."}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'serverspec'
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'specinfra/helper/set'
|
4
|
+
require 'json'
|
5
|
+
include Specinfra::Helper::Set
|
6
|
+
|
7
|
+
if ENV['LOCAL_MODE']
|
8
|
+
set :backend, :exec
|
9
|
+
else
|
10
|
+
set :backend, :ssh
|
11
|
+
end
|
12
|
+
|
13
|
+
if ENV['ASK_SUDO_PASSWORD']
|
14
|
+
begin
|
15
|
+
require 'highline/import'
|
16
|
+
rescue LoadError
|
17
|
+
fail "highline is not available. Try installing it."
|
18
|
+
end
|
19
|
+
set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
|
20
|
+
else
|
21
|
+
set :sudo_password, ENV['SUDO_PASSWORD']
|
22
|
+
end
|
23
|
+
|
24
|
+
host = ENV['TARGET_HOST']
|
25
|
+
node_file = ENV['NODE_FILE']
|
26
|
+
attributes = JSON.parse(File.read(node_file), symbolize_names: true)
|
27
|
+
set_property attributes
|
28
|
+
|
29
|
+
unless ENV['LOCAL_MODE']
|
30
|
+
options = Net::SSH::Config.for(host)
|
31
|
+
options[:user] = ENV['SSH_USER']
|
32
|
+
options[:password] = ENV['SSH_PASSWORD']
|
33
|
+
options[:keys] = ENV['SSH_KEY']
|
34
|
+
options[:port] = ENV['SSH_PORT']
|
35
|
+
|
36
|
+
set :host, options[:host_name] || host
|
37
|
+
set :shell, '/bin/bash'
|
38
|
+
set :ssh_options, options
|
39
|
+
end
|
40
|
+
|
41
|
+
set :request_pty, true
|
File without changes
|
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
module Itamae
|
3
|
+
module Logger
|
4
|
+
class FileFormatter < Formatter
|
5
|
+
def call(severity, datetime, progname, msg)
|
6
|
+
log = "%s : %s" % ["%5s" % severity, msg2str(msg)]
|
7
|
+
Time.now.strftime('%F %T %z').to_s + log + "\n"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.broadcast(logger)
|
12
|
+
Module.new do
|
13
|
+
define_method(:add) do |*args, &block|
|
14
|
+
logger.add(*args, &block)
|
15
|
+
super(*args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method(:<<) do |x|
|
19
|
+
logger << x
|
20
|
+
super(x)
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method(:close) do
|
24
|
+
logger.close
|
25
|
+
super()
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method(:progname=) do |name|
|
29
|
+
logger.progname = name
|
30
|
+
super(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
define_method(:formatter=) do |formatter|
|
34
|
+
logger.formatter = formatter
|
35
|
+
super(formatter)
|
36
|
+
end
|
37
|
+
|
38
|
+
define_method(:level=) do |level|
|
39
|
+
logger.level = level
|
40
|
+
super(level)
|
41
|
+
end
|
42
|
+
|
43
|
+
define_method(:local_level=) do |level|
|
44
|
+
logger.local_level = level if logger.respond_to?(:local_level=)
|
45
|
+
super(level) if respond_to?(:local_level=)
|
46
|
+
end
|
47
|
+
|
48
|
+
define_method(:silence) do |level = Logger::ERROR, &block|
|
49
|
+
if logger.respond_to?(:silence)
|
50
|
+
logger.silence(level) do
|
51
|
+
if defined?(super)
|
52
|
+
super(level, &block)
|
53
|
+
else
|
54
|
+
block.call(self)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
if defined?(super)
|
59
|
+
super(level, &block)
|
60
|
+
else
|
61
|
+
block.call(self)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if Dir.exist?('logs')
|
70
|
+
@file_logger = ::Logger.new('logs/itamae.log', 'daily').tap do |l|
|
71
|
+
l.formatter = Itamae::Logger::FileFormatter.new
|
72
|
+
end.extend(Itamae::Logger::Helper)
|
73
|
+
|
74
|
+
@logger.extend Itamae::Logger.broadcast(@file_logger)
|
75
|
+
end
|
76
|
+
end
|