plat 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +25 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +0 -0
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +4 -0
- data/LICENSE.md +22 -0
- data/README.md +55 -0
- data/Rakefile +16 -0
- data/bin/plat +5 -0
- data/lib/plat.rb +3 -0
- data/lib/plat/layout.rb +15 -0
- data/lib/plat/layout/aws.rb +34 -0
- data/lib/plat/layout/configuration.rb +8 -0
- data/lib/plat/role.rb +64 -0
- data/lib/plat/role/basic.rb +50 -0
- data/lib/plat/role/cache.rb +9 -0
- data/lib/plat/role/cpu.rb +15 -0
- data/lib/plat/role/db.rb +9 -0
- data/lib/plat/role/files.rb +9 -0
- data/lib/plat/role/iam_role.rb +56 -0
- data/lib/plat/role/mail.rb +9 -0
- data/lib/plat/version.rb +3 -0
- data/plat.gemspec +34 -0
- data/spec/layout/aws_spec.rb +46 -0
- data/spec/layout/configuration_spec.rb +11 -0
- data/spec/plat_spec.rb +7 -0
- data/spec/role/basic_spec.rb +74 -0
- data/spec/role/cpu_spec.rb +11 -0
- data/spec/role/iam_role.rb +5 -0
- data/spec/role_spec.rb +95 -0
- data/spec/spec_helper.rb +36 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22aa294b39be25aa3af50dce5a548a997dae3aa2
|
4
|
+
data.tar.gz: 00ce314ddc57be79128f9d88f934ba7255f1f8f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ec467cb2a730bc6d8654c90a24e7a9abafe7530d94d4deacc3311fc815101e459707bc00e90ab7ca3828bd7450553f4b9bf22e80e84a77a1f419ef3a9c2f7ca
|
7
|
+
data.tar.gz: 5219323fef1e6930b3695acfef6c7afe7a90011c88ab95a1c5c4c0d4e88eace509cc4f9cf9b2a591fe9198d1b42a82c2fffdd79bfa1d1095b7f11892e9944c7a
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
.env
|
7
|
+
.rspec
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
*.bundle
|
21
|
+
*.so
|
22
|
+
*.o
|
23
|
+
*.a
|
24
|
+
mkmf.log
|
25
|
+
**/.DS_Store
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Andrey Pronin <moonfly.msk@gmail.com> aka moonfly (https://github.com/moonfly)
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 [CONTRIBUTORS.md](https://github.com/moonfly/plat/master/CONTRIBUTORS.md)
|
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,55 @@
|
|
1
|
+
# Plat
|
2
|
+
|
3
|
+
NOT FOR PUBLIC USE YET. ACTIVE INITIAL DEVELOPMENT IS IN PROGRESS.
|
4
|
+
|
5
|
+
DevOps platform management. Makes most deployment headaches go away and greatly speeds up the initial phase of a new app development.
|
6
|
+
|
7
|
+
TODO: Describe the problem & the solution
|
8
|
+
|
9
|
+
[![Build Status](https://travis-ci.org/moonfly/plat.svg?branch=master)](https://travis-ci.org/moonfly/plat)
|
10
|
+
[![Coverage Status](https://img.shields.io/coveralls/moonfly/plat.svg)](https://coveralls.io/r/moonfly/plat?branch=master)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'plat'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install plat
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Versioning
|
31
|
+
|
32
|
+
Semantic versioning (http://semver.org/spec/v2.0.0.html) is used.
|
33
|
+
|
34
|
+
For a version number MAJOR.MINOR.PATCH, unless MAJOR is 0:
|
35
|
+
|
36
|
+
1. MAJOR version is incremented when incompatible API changes are made,
|
37
|
+
2. MINOR version is incremented when functionality is added in a backwards-compatible manner,
|
38
|
+
3. PATCH version is incremented when backwards-compatible bug fixes are made.
|
39
|
+
|
40
|
+
Major version "zero" (0.y.z) is for initial development. Anything may change at any time.
|
41
|
+
The public API should not be considered stable.
|
42
|
+
Furthermore, version "double-zero" (0.0.x) is not intended for public use,
|
43
|
+
as even minimal functionality is not guaranteed to be implemented yet.
|
44
|
+
|
45
|
+
## Dependencies
|
46
|
+
|
47
|
+
TODO: List gem dependencies here
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/moonfly/plat/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'dotenv/tasks'
|
4
|
+
|
5
|
+
# Default directory to look in is `/specs`
|
6
|
+
# Run with `rake spec`
|
7
|
+
desc "Run RSpec tests (use rake spec SPEC_OPTS='...' to pass rspec options)"
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
desc "Run RSpec tests in Travis CI environment"
|
11
|
+
RSpec::Core::RakeTask.new(:travis) do |t|
|
12
|
+
t.rspec_opts = '--tag ~live_aws' # skip the tests that require connection to unstubbed live AWS
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => :spec
|
16
|
+
|
data/bin/plat
ADDED
data/lib/plat.rb
ADDED
data/lib/plat/layout.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'plat/layout/configuration'
|
2
|
+
require 'plat/layout/aws'
|
3
|
+
|
4
|
+
module Plat
|
5
|
+
class Layout
|
6
|
+
def initialize(options={},&block)
|
7
|
+
configure(options,&block)
|
8
|
+
configuration.lock
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
"<#{self.class} #{configuration.to_s}>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Plat
|
2
|
+
class Layout
|
3
|
+
%w(aws_access_key_id aws_secret_access_key).each do |name|
|
4
|
+
def_config_param name, make_string: true, lockable: true, not_empty: true, default: (ENV[name.upcase] || '???')
|
5
|
+
end
|
6
|
+
def_config_param :env, make_string: true, lockable: true, not_empty: true, default: '' # production, development, test, ...
|
7
|
+
def_config_param :name_prefix, make_string: true, lockable: true, default: ''
|
8
|
+
def_config_param :app_name, make_string: true, lockable: true, default: ''
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Plat
|
13
|
+
class Layout
|
14
|
+
def aws_options
|
15
|
+
@aws_options ||=
|
16
|
+
{
|
17
|
+
access_key_id: configuration.aws_access_key_id,
|
18
|
+
secret_access_key: configuration.aws_secret_access_key
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def aws_role_name_prefix(role)
|
23
|
+
@aws_role_name_prefix ||= {}
|
24
|
+
@aws_role_name_prefix[role] ||=
|
25
|
+
[ configuration.name_prefix,
|
26
|
+
configuration.app_name,
|
27
|
+
configuration.env,
|
28
|
+
role ].map(&:to_s).delete_if{|s| s==''}.join('-').gsub(/\s/,'_')
|
29
|
+
end
|
30
|
+
def aws_resource_name(role,id=0)
|
31
|
+
aws_role_name_prefix(role)+'-'+id.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/plat/role.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Plat
|
4
|
+
class Layout
|
5
|
+
def convert_roles(roles_def)
|
6
|
+
case roles_def
|
7
|
+
when Hash then roles_def
|
8
|
+
when Array
|
9
|
+
roles_def.inject({}) do |result,elem|
|
10
|
+
result.merge! convert_roles(elem)
|
11
|
+
end
|
12
|
+
when IO, StringIO, Tempfile then YAML.load(roles_def)
|
13
|
+
when String, Pathname
|
14
|
+
output = {}
|
15
|
+
File.open(roles_def,"r") { |f| output = YAML.load(f) }
|
16
|
+
output
|
17
|
+
else
|
18
|
+
raise ArgumentError.new("Wrong class for 'roles' value: #{roles_def.class}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def_config_param :roles, lockable: true, default: Hash.new, convert: :convert_roles
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Plat
|
26
|
+
class Layout
|
27
|
+
def roles
|
28
|
+
@roles ||= begin
|
29
|
+
configuration.roles.map do |role,options|
|
30
|
+
[ role, Plat::Role.create(self,role,options) ]
|
31
|
+
end.to_h
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Plat
|
38
|
+
module Role
|
39
|
+
def self.registered_types
|
40
|
+
@registered_types ||= {}
|
41
|
+
end
|
42
|
+
def self.register(type,cname)
|
43
|
+
registered_types[type] = cname
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.create(layout,role,options)
|
47
|
+
if type = options[:type]
|
48
|
+
raise ArgumentError.new "Wrong type for role #{@role}: #{options[:type]}" unless registered_types.member?(type)
|
49
|
+
else
|
50
|
+
rtype = role.downcase.to_sym
|
51
|
+
type = registered_types.member?(rtype) ? rtype : :cpu
|
52
|
+
end
|
53
|
+
registered_types[type].new(layout,role,options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
require 'plat/role/basic' # require first to make available for the rest
|
59
|
+
|
60
|
+
require 'plat/role/cpu'
|
61
|
+
require 'plat/role/db'
|
62
|
+
require 'plat/role/cache'
|
63
|
+
require 'plat/role/files'
|
64
|
+
require 'plat/role/mail'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'plat/role/iam_role'
|
3
|
+
|
4
|
+
module Plat
|
5
|
+
module Role
|
6
|
+
class Basic
|
7
|
+
extend Forwardable
|
8
|
+
attr_reader :layout, :role, :options
|
9
|
+
def_delegators :@layout, :configuration
|
10
|
+
def_delegators :configuration, :env
|
11
|
+
|
12
|
+
def initialize(layout,role,options)
|
13
|
+
@layout = layout
|
14
|
+
@role = role
|
15
|
+
@options = options.
|
16
|
+
merge(Hash(options[:default])).
|
17
|
+
merge(Hash(options["default"])).
|
18
|
+
merge(Hash(options[env.to_sym])).
|
19
|
+
merge(Hash(options[env.to_s]))
|
20
|
+
end
|
21
|
+
def count
|
22
|
+
@count ||= begin
|
23
|
+
value = options.fetch(:count) { 1 }.to_i
|
24
|
+
raise ArgumentError.new "Wrong count for role #{@role}: #{options[:count]}" if value < 1
|
25
|
+
value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def type
|
29
|
+
Plat::Role.registered_types.find(->{[nil]}) { |elem| elem[1] == self.class }.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def resource_name(id=0)
|
33
|
+
layout.aws_resource_name(role,id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
"<#{self.class} role='#{self.role}'>"
|
38
|
+
end
|
39
|
+
def to_s
|
40
|
+
{ role => Hash(options) }.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def allow_access(policy,access_type)
|
44
|
+
# TODO
|
45
|
+
# policy.allow
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Plat
|
2
|
+
module Role
|
3
|
+
class Cpu < Plat::Role::Basic
|
4
|
+
def ec2
|
5
|
+
@ec2 ||= AWS::EC2.new(layout.aws_options)
|
6
|
+
end
|
7
|
+
def iam_role
|
8
|
+
@iam_role ||= Plat::Role::IAMRole.new(self)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Plat::Role.register :cpu, Plat::Role::Cpu
|
15
|
+
|
data/lib/plat/role/db.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Plat
|
2
|
+
module Role
|
3
|
+
class IAMRole
|
4
|
+
extend Forwardable
|
5
|
+
attr_reader :cpu_role
|
6
|
+
def_delegators :@cpu_role, :layout, :options
|
7
|
+
|
8
|
+
ACCESS_TYPES = [ :read, :write, :full ]
|
9
|
+
|
10
|
+
def initialize(cpu_role)
|
11
|
+
@cpu_role = cpu_role
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_roles
|
15
|
+
@all_roles ||= layout.roles.keys
|
16
|
+
end
|
17
|
+
|
18
|
+
def accessible_roles
|
19
|
+
if access_options = options[:access]
|
20
|
+
if (access_options.keys & ACCESS_TYPES).empty?
|
21
|
+
roles_with_access access_options, :full
|
22
|
+
else
|
23
|
+
ACCESS_TYPES.map do |access_type|
|
24
|
+
access_options[access_type] ? roles_with_access(access_options[access_type],access_type) : {}
|
25
|
+
end.collect(&:+)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
roles_with_access all_roles, :full
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def roles_with_access(access_options,access_type)
|
32
|
+
roles = all_roles
|
33
|
+
if access_options.is_a? Hash
|
34
|
+
if access_options[:only]
|
35
|
+
roles &= Array(access_options[:only])
|
36
|
+
end
|
37
|
+
if access_options[:except]
|
38
|
+
roles -= Array(access_options[:except])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
roles &= Array(access_options)
|
42
|
+
end
|
43
|
+
roles.map { |role| [role,access_type] }.to_hash
|
44
|
+
end
|
45
|
+
|
46
|
+
def aws_policy
|
47
|
+
@aws_policy ||= AWS::IAM::Policy.new do |policy|
|
48
|
+
accessible_roles.each_pair do |role,access_type|
|
49
|
+
role.allow_access(policy,access_type)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/plat/version.rb
ADDED
data/plat.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'plat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'plat'
|
8
|
+
spec.version = Plat::VERSION
|
9
|
+
spec.authors = ['moonfly (Andrey Pronin)']
|
10
|
+
spec.email = ['moonfly.msk@gmail.com']
|
11
|
+
spec.summary = %q{DevOps platform management}
|
12
|
+
spec.description = %q{Makes most deployment headaches go away and greatly speeds up the initial phase of a new app development.}
|
13
|
+
spec.homepage = 'https://github.com/moonfly/plat'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.rdoc_options = ['--charset=UTF-8']
|
22
|
+
spec.extra_rdoc_files = %w[README.md CONTRIBUTORS.md LICENSE.md]
|
23
|
+
|
24
|
+
spec.required_ruby_version = '>= 2.1.0'
|
25
|
+
|
26
|
+
spec.add_dependency 'aws-sdk', '~> 1.51.0'
|
27
|
+
spec.add_dependency 'configuru'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '>= 1.6'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'coveralls'
|
33
|
+
spec.add_development_dependency 'dotenv'
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Plat::Layout do
|
4
|
+
it 'specifies options for AWS' do
|
5
|
+
layout = Plat::Layout.new do |config|
|
6
|
+
config.aws_access_key_id = "key-id"
|
7
|
+
config.aws_secret_access_key = "big-secret"
|
8
|
+
end
|
9
|
+
expect(layout.aws_options).to be_a Hash
|
10
|
+
expect(layout.aws_options.size).to eq 2
|
11
|
+
expect(layout.aws_options[:access_key_id]).to eq "key-id"
|
12
|
+
expect(layout.aws_options[:secret_access_key]).to eq "big-secret"
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'builds AWS resource names' do
|
16
|
+
layout1 = Plat::Layout.new do |config|
|
17
|
+
config.app_name = "Super App"
|
18
|
+
config.name_prefix = "ThePrefix"
|
19
|
+
config.env = "My Env"
|
20
|
+
end
|
21
|
+
expect(layout1.aws_resource_name("NumbersCruncher",997)).to eq "ThePrefix-Super_App-My_Env-NumbersCruncher-997"
|
22
|
+
|
23
|
+
layout2 = Plat::Layout.new # use defaults
|
24
|
+
expect(layout2.aws_resource_name("Database")).to eq "Database-0"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Plat::Layout do
|
29
|
+
let(:subject) { Plat::Layout.new }
|
30
|
+
it 'has required AWS configuration variables with correct default values' do
|
31
|
+
expect(subject.configuration.param_names).to include :aws_access_key_id, :aws_secret_access_key, :env, :name_prefix, :app_name
|
32
|
+
|
33
|
+
expect(subject.configuration.aws_access_key_id).to eq (ENV["AWS_ACCESS_KEY_ID"] || '???')
|
34
|
+
expect(subject.configuration.aws_secret_access_key).to eq (ENV["AWS_SECRET_ACCESS_KEY"] || '???')
|
35
|
+
expect(subject.configuration.env).to eq ''
|
36
|
+
expect(subject.configuration.name_prefix).to eq ''
|
37
|
+
expect(subject.configuration.app_name).to eq ''
|
38
|
+
end
|
39
|
+
it 'does not allow changing AWS configuration variables after initialization' do
|
40
|
+
expect{subject.configuration.aws_access_key_id="new-id"}.to raise_error
|
41
|
+
expect{subject.configuration.secret_access_key="new-secret"}.to raise_error
|
42
|
+
expect{subject.configuration.env="new-env"}.to raise_error
|
43
|
+
expect{subject.configuration.name_prefix="new-prefix"}.to raise_error
|
44
|
+
expect{subject.configuration.app_name="new-name"}.to raise_error
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Plat::Layout do
|
4
|
+
it 'can be configured (smoke test)' do
|
5
|
+
layout = Plat::Layout.new(env: :my_special_env) do |cfg|
|
6
|
+
cfg.app_name = 'someAwesomeApp'
|
7
|
+
end
|
8
|
+
expect(layout.configuration.env).to eq 'my_special_env'
|
9
|
+
expect(layout.configuration.app_name).to eq 'someAwesomeApp'
|
10
|
+
end
|
11
|
+
end
|
data/spec/plat_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Plat::Role::Basic do
|
6
|
+
before(:each) do
|
7
|
+
class TestRole < Plat::Role::Basic
|
8
|
+
end
|
9
|
+
Plat::Role.register :testtesttest, TestRole
|
10
|
+
end
|
11
|
+
let(:the_layout) { Plat::Layout.new( env: 'test') }
|
12
|
+
it 'stores passed parameters' do
|
13
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78 })
|
14
|
+
expect(role).to be_a TestRole
|
15
|
+
expect(role.type).to eq :testtesttest
|
16
|
+
expect(role.layout).to eq the_layout
|
17
|
+
expect(role.role).to eq "some role"
|
18
|
+
expect(role.options[:x]).to eq 78
|
19
|
+
end
|
20
|
+
it 'picks parameters for the right environment' do
|
21
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78, default: { x: 99 } })
|
22
|
+
expect(role.options[:x]).to eq 99
|
23
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78, "default" => { x: 93 } })
|
24
|
+
expect(role.options[:x]).to eq 93
|
25
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78, default: { x: 99 }, test: { x: 15 } })
|
26
|
+
expect(role.options[:x]).to eq 15
|
27
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78, "default" => { x: 93 }, "test" => { x: 21 } })
|
28
|
+
expect(role.options[:x]).to eq 21
|
29
|
+
end
|
30
|
+
it 'uses explicitly passed count' do
|
31
|
+
role = Plat::Role.create(the_layout, "testtesttest", { count: 732 })
|
32
|
+
expect(role.count).to eq 732
|
33
|
+
end
|
34
|
+
it 'converts count from strings and floats' do
|
35
|
+
[
|
36
|
+
Plat::Role.create(the_layout, "testtesttest", { count: "681" }),
|
37
|
+
Plat::Role.create(the_layout, "testtesttest", { count: 681.7 }),
|
38
|
+
Plat::Role.create(the_layout, "testtesttest", { count: "681.7" })
|
39
|
+
].each do |role|
|
40
|
+
expect(role.count).to eq 681
|
41
|
+
end
|
42
|
+
end
|
43
|
+
it 'sets count to 1 by default' do
|
44
|
+
role = Plat::Role.create(the_layout, "testtesttest", {})
|
45
|
+
expect(role.count).to eq 1
|
46
|
+
end
|
47
|
+
it 'does not allow incorrectly specified counts' do
|
48
|
+
[
|
49
|
+
Plat::Role.create(the_layout, "testtesttest", { count: 0 }),
|
50
|
+
Plat::Role.create(the_layout, "testtesttest", { count: -1 }),
|
51
|
+
Plat::Role.create(the_layout, "testtesttest", { count: Float::INFINITY }),
|
52
|
+
Plat::Role.create(the_layout, "testtesttest", { count: [] }),
|
53
|
+
Plat::Role.create(the_layout, "testtesttest", { count: {} }),
|
54
|
+
Plat::Role.create(the_layout, "testtesttest", { count: { value: 100 } }),
|
55
|
+
Plat::Role.create(the_layout, "testtesttest", { count: "one" }),
|
56
|
+
Plat::Role.create(the_layout, "testtesttest", { count: nil })
|
57
|
+
].each do |role|
|
58
|
+
expect{role.count}.to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
it 'prints role in inspect' do
|
62
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78 })
|
63
|
+
expect(role.inspect).to include "role='some role'"
|
64
|
+
end
|
65
|
+
it 'prints itself as hash in to_s' do
|
66
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78 })
|
67
|
+
template = { "some role" => { type: :testtesttest, x: 78 } }
|
68
|
+
expect(role.to_s).to eq template.to_s
|
69
|
+
end
|
70
|
+
it 'uses the correct resource name' do
|
71
|
+
role = Plat::Role.create(the_layout, "some role", { type: :testtesttest, x: 78 })
|
72
|
+
expect(role.resource_name(17)).to eq the_layout.aws_resource_name("some role",17)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Plat::Role::Cpu do
|
4
|
+
let(:default_options) { Hash.new }
|
5
|
+
let(:layout) { Plat::Layout.new }
|
6
|
+
let(:subject) { Plat::Role.create(layout,:cpu,default_options) }
|
7
|
+
|
8
|
+
it 'reaches AWS EC2 (smoke test)' do
|
9
|
+
expect{subject.ec2.instances.to_a}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
data/spec/role_spec.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe Plat::Role do
|
5
|
+
before(:each) do
|
6
|
+
class TestRole < Plat::Role::Basic
|
7
|
+
end
|
8
|
+
Plat::Role.register :testtesttest, TestRole
|
9
|
+
end
|
10
|
+
let(:the_layout) { Plat::Layout.new }
|
11
|
+
it 'allows registering role classes' do
|
12
|
+
expect(Plat::Role.registered_types[:testtesttest]).to eq TestRole
|
13
|
+
end
|
14
|
+
it 'creates correct role instances' do
|
15
|
+
{
|
16
|
+
"some role" => Plat::Role.create( the_layout, "some role", { type: :testtesttest }), # explicit type specification
|
17
|
+
"testtesttest" => Plat::Role.create( the_layout, "testtesttest", {}) # implicit type from role
|
18
|
+
}.each_pair do |role_name, role|
|
19
|
+
expect(role).to be_a TestRole
|
20
|
+
expect(role.type).to eq :testtesttest
|
21
|
+
expect(role.role).to eq role_name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
it 'creates CPU role instance by default' do
|
25
|
+
layout = Plat::Layout.new
|
26
|
+
role = Plat::Role.create layout, "some role", {}
|
27
|
+
expect(role.type).to eq :cpu
|
28
|
+
expect(role.role).to eq "some role"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Plat::Layout do
|
33
|
+
let(:roles_spec) { Hash("cpu" => { count: 10 }, "db" => { count: 20 }) }
|
34
|
+
let(:roles_sio) { StringIO.new(roles_spec.to_yaml) }
|
35
|
+
|
36
|
+
it 'allows loading roles from hash' do
|
37
|
+
layout = Plat::Layout.new( roles: roles_spec )
|
38
|
+
expect(layout.roles["cpu"]).to be_a Plat::Role::Cpu
|
39
|
+
expect(layout.roles["cpu"].count).to eq 10
|
40
|
+
expect(layout.roles["db"]).to be_a Plat::Role::Db
|
41
|
+
expect(layout.roles["db"].count).to eq 20
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'allows loading roles from StringIO' do
|
45
|
+
layout = Plat::Layout.new( roles: roles_sio )
|
46
|
+
expect(layout.roles["cpu"]).to be_a Plat::Role::Cpu
|
47
|
+
expect(layout.roles["cpu"].count).to eq 10
|
48
|
+
expect(layout.roles["db"]).to be_a Plat::Role::Db
|
49
|
+
expect(layout.roles["db"].count).to eq 20
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'allows loading roles from an array of sources, later sources take precendence' do
|
53
|
+
roles_spec1 = roles_spec.clone
|
54
|
+
roles_spec1.delete("cpu")
|
55
|
+
roles_spec1["db"][:count] = 40
|
56
|
+
|
57
|
+
layout = Plat::Layout.new( roles: [roles_sio, roles_spec1] )
|
58
|
+
expect(layout.roles["cpu"]).to be_a Plat::Role::Cpu
|
59
|
+
expect(layout.roles["cpu"].count).to eq 10
|
60
|
+
expect(layout.roles["db"]).to be_a Plat::Role::Db
|
61
|
+
expect(layout.roles["db"].count).to eq 40
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'allows loading roles from File/IO' do
|
65
|
+
layout1 = nil
|
66
|
+
layout2 = nil
|
67
|
+
layout3 = nil
|
68
|
+
f = Tempfile.new("test_roles.yaml")
|
69
|
+
begin
|
70
|
+
f << roles_spec.to_yaml
|
71
|
+
f.open
|
72
|
+
layout1 = Plat::Layout.new( roles: f )
|
73
|
+
layout2 = Plat::Layout.new( roles: f.path )
|
74
|
+
File.open( f.path ) do |real_f|
|
75
|
+
layout3 = Plat::Layout.new( roles: real_f )
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
f.close
|
79
|
+
f.unlink
|
80
|
+
end
|
81
|
+
expect(layout1).not_to be_nil
|
82
|
+
expect(layout2).not_to be_nil
|
83
|
+
expect(layout3).not_to be_nil
|
84
|
+
[
|
85
|
+
layout1,
|
86
|
+
layout2,
|
87
|
+
layout3
|
88
|
+
].each do |layout|
|
89
|
+
expect(layout.roles["cpu"]).to be_a Plat::Role::Cpu
|
90
|
+
expect(layout.roles["cpu"].count).to eq 10
|
91
|
+
expect(layout.roles["db"]).to be_a Plat::Role::Db
|
92
|
+
expect(layout.roles["db"].count).to eq 20
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'dotenv'
|
5
|
+
Dotenv.load
|
6
|
+
|
7
|
+
if ENV.has_key?("STUB_AWS") ||
|
8
|
+
!ENV.has_key?("AWS_ACCESS_KEY_ID") ||
|
9
|
+
!ENV.has_key?("AWS_SECRET_ACCESS_KEY")
|
10
|
+
# Test in the environment when AWS credentials are not provided
|
11
|
+
require 'aws-sdk'
|
12
|
+
puts "Stubbing AWS (#{ENV.has_key?("STUB_AWS") ? "forced" : "no keys"})"
|
13
|
+
|
14
|
+
RSpec.configure do |c|
|
15
|
+
c.filter_run_excluding :live_aws
|
16
|
+
end
|
17
|
+
|
18
|
+
AWS.stub! # see https://forums.aws.amazon.com/thread.jspa?threadID=114617
|
19
|
+
#
|
20
|
+
# Further capabilities:
|
21
|
+
# ec2.client.stub_for(:describe_instances)[:reservation_set] = 'my-data'
|
22
|
+
# resp = ec2.client.describe_instances
|
23
|
+
# #=> {:reservation_set=>'my-data', :reservation_index=>{}, :instance_index=>{}}
|
24
|
+
#
|
25
|
+
# resp1 = ec2.client.new_stub_for(:describe_instances)
|
26
|
+
# resp2 = ec2.client.new_stub_for(:describe_instances)
|
27
|
+
# resp1[:called] = 1
|
28
|
+
# resp2[:called] = 2
|
29
|
+
# ec2.client.stub(:describe_instances).and_return(resp1, resp2)
|
30
|
+
# ec2.describe_instances
|
31
|
+
# #=> {:reservation_set=>[], :reservation_index=>{}, :instance_index=>{}, :call => 1}
|
32
|
+
# ec2.describe_instances
|
33
|
+
# #=> {:reservation_set=>[], :reservation_index=>{}, :instance_index=>{}, :call => 2}
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'plat'
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- moonfly (Andrey Pronin)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.51.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.51.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: configuru
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Makes most deployment headaches go away and greatly speeds up the initial
|
112
|
+
phase of a new app development.
|
113
|
+
email:
|
114
|
+
- moonfly.msk@gmail.com
|
115
|
+
executables:
|
116
|
+
- plat
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files:
|
119
|
+
- README.md
|
120
|
+
- CONTRIBUTORS.md
|
121
|
+
- LICENSE.md
|
122
|
+
files:
|
123
|
+
- ".coveralls.yml"
|
124
|
+
- ".gitignore"
|
125
|
+
- ".travis.yml"
|
126
|
+
- CHANGELOG.md
|
127
|
+
- CONTRIBUTORS.md
|
128
|
+
- Gemfile
|
129
|
+
- LICENSE.md
|
130
|
+
- README.md
|
131
|
+
- Rakefile
|
132
|
+
- bin/plat
|
133
|
+
- lib/plat.rb
|
134
|
+
- lib/plat/layout.rb
|
135
|
+
- lib/plat/layout/aws.rb
|
136
|
+
- lib/plat/layout/configuration.rb
|
137
|
+
- lib/plat/role.rb
|
138
|
+
- lib/plat/role/basic.rb
|
139
|
+
- lib/plat/role/cache.rb
|
140
|
+
- lib/plat/role/cpu.rb
|
141
|
+
- lib/plat/role/db.rb
|
142
|
+
- lib/plat/role/files.rb
|
143
|
+
- lib/plat/role/iam_role.rb
|
144
|
+
- lib/plat/role/mail.rb
|
145
|
+
- lib/plat/version.rb
|
146
|
+
- plat.gemspec
|
147
|
+
- spec/layout/aws_spec.rb
|
148
|
+
- spec/layout/configuration_spec.rb
|
149
|
+
- spec/plat_spec.rb
|
150
|
+
- spec/role/basic_spec.rb
|
151
|
+
- spec/role/cpu_spec.rb
|
152
|
+
- spec/role/iam_role.rb
|
153
|
+
- spec/role_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
homepage: https://github.com/moonfly/plat
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options:
|
161
|
+
- "--charset=UTF-8"
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 2.1.0
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.2.2
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: DevOps platform management
|
180
|
+
test_files:
|
181
|
+
- spec/layout/aws_spec.rb
|
182
|
+
- spec/layout/configuration_spec.rb
|
183
|
+
- spec/plat_spec.rb
|
184
|
+
- spec/role/basic_spec.rb
|
185
|
+
- spec/role/cpu_spec.rb
|
186
|
+
- spec/role/iam_role.rb
|
187
|
+
- spec/role_spec.rb
|
188
|
+
- spec/spec_helper.rb
|