kaigara 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -9
- data/app/controllers/sysops.rb +3 -23
- data/app/models/sysops/environment.rb +7 -9
- data/app/models/sysops/{context.rb → operation.rb} +13 -4
- data/app/models/sysops/package.rb +1 -5
- data/app/models/sysops/spec.rb +0 -6
- data/app/templates/sysops/Vagrantfile.erb +4 -22
- data/app/templates/sysops/metadata.rb.erb +3 -8
- data/lib/kaigara.rb +1 -1
- data/lib/kaigara/deephash.rb +3 -0
- data/lib/kaigara/metadata.rb +35 -0
- data/lib/kaigara/version.rb +1 -1
- metadata +5 -15
- data/app/models/sysops/kaigara_package.rb +0 -28
- data/kaigara.yml +0 -11
- data/lib/kaigara/baseops.rb +0 -8
- data/lib/kaigara/sysops.rb +0 -59
- data/lib/kaigara/sysops/context.rb +0 -56
- data/lib/kaigara/sysops/environment.rb +0 -14
- data/lib/kaigara/sysops/kaigara_package.rb +0 -28
- data/lib/kaigara/sysops/package.rb +0 -69
- data/lib/kaigara/sysops/spec.rb +0 -30
- data/lib/kaigara/sysops/templates/Vagrantfile.erb +0 -32
- data/lib/kaigara/sysops/templates/metadata.rb.erb +0 -8
- data/lib/kaigara/sysops/templates/operation.rb.erb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e0a7546c9c6a70c5d81bd6f4caa93af7fcb21d9
|
4
|
+
data.tar.gz: dabf75ee6daa3970a01581132710badf1ff27f11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 136c3a11b6c01f2bc47392ac5e3d58159505c7c235be1eed28967fc0e33fd27c25e4442c53014d7beb33c69955a6c951d021a171f58c4de555149a68b855abca
|
7
|
+
data.tar.gz: 72794ea2047d69fd377ecfde7a00af314fc385a690db1c8faeae8661acc38d67c97878db677a9d87697b2abab9e46c53bc7f24db1a189ce2ce81ff1cd2be1548
|
data/README.md
CHANGED
@@ -22,9 +22,6 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
Basic commands are
|
24
24
|
```
|
25
|
-
# Prepare ruby runtime on a remote host
|
26
|
-
$> kaish remote bootstrap USER@SERVER
|
27
|
-
|
28
25
|
# Creates a system operation package (sysops)
|
29
26
|
$> kaish sysops create NAME
|
30
27
|
|
@@ -33,12 +30,6 @@ $> kaish sysops generate NAME
|
|
33
30
|
|
34
31
|
# Execute all operations of the current working directory
|
35
32
|
$> kaish sysops exec [DIRECTORY]
|
36
|
-
|
37
|
-
# Install a kaigara sysops package from github or a private git repository
|
38
|
-
$> kaish sysops install USER/NAME
|
39
|
-
|
40
|
-
# list all kaigara sysops package located in ~/.kaigara/sysops
|
41
|
-
$> kaish sysops list
|
42
33
|
```
|
43
34
|
|
44
35
|
You can use `kaish help` any time to get help.
|
data/app/controllers/sysops.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'models/sysops/package'
|
2
|
-
require 'models/sysops/
|
2
|
+
require 'models/sysops/operation'
|
3
|
+
require 'models/sysops/environment'
|
4
|
+
require 'models/sysops/spec'
|
3
5
|
|
4
6
|
module Kaigara
|
5
7
|
class Sysops < BaseController
|
@@ -12,10 +14,6 @@ module Kaigara
|
|
12
14
|
empty_directory(name)
|
13
15
|
empty_directory(File.join(name, 'operations'))
|
14
16
|
empty_directory(File.join(name, 'resources'))
|
15
|
-
#in_destination(name) do
|
16
|
-
# render('metadata.rb')
|
17
|
-
# render('Vagrantfile')
|
18
|
-
#end
|
19
17
|
template('metadata.rb.erb', File.join(name, 'metadata.rb'))
|
20
18
|
template('Vagrantfile.erb', File.join(name, 'Vagrantfile'))
|
21
19
|
end
|
@@ -36,23 +34,5 @@ module Kaigara
|
|
36
34
|
package.load!
|
37
35
|
package.run!
|
38
36
|
end
|
39
|
-
|
40
|
-
desc 'install <(github login)/(operation name)>', 'Install a kaigara operation'
|
41
|
-
def install(name)
|
42
|
-
pkg = KaigaraPackage.new(name)
|
43
|
-
begin
|
44
|
-
config = YAML.load_file(File.dirname(__FILE__) + '/../../kaigara.yml')
|
45
|
-
pkg.read_config! config
|
46
|
-
rescue Exception => ex
|
47
|
-
say("Failed to load node configuration! #{ex}", :red)
|
48
|
-
end
|
49
|
-
|
50
|
-
if pkg.is_installed?
|
51
|
-
say('The package is already installed', :green)
|
52
|
-
else
|
53
|
-
say("Installing #{name}...")
|
54
|
-
pkg.install()
|
55
|
-
end
|
56
|
-
end
|
57
37
|
end
|
58
38
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module Kaigara
|
2
2
|
class Environment
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@variables[method_sym.to_s] = arguments[0] rescue nil
|
3
|
+
def self.load_variables()
|
4
|
+
package = Package.new
|
5
|
+
@vars = package.load!
|
6
|
+
@vars.data.each_pair do |k, v|
|
7
|
+
Operation.send(:define_method, k.to_sym, Proc.new {v})
|
8
|
+
Operation::ThorShell.send(:define_method, k.to_sym, Proc.new {v})
|
9
|
+
end unless @vars.empty?
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'open3'
|
2
2
|
|
3
3
|
module Kaigara
|
4
|
-
class
|
4
|
+
class Operation
|
5
5
|
class ThorShell
|
6
|
-
|
7
6
|
include Thor::Base
|
8
7
|
include Thor::Actions
|
9
8
|
include Thor::Shell
|
@@ -34,8 +33,9 @@ module Kaigara
|
|
34
33
|
end
|
35
34
|
|
36
35
|
def execute(cmd)
|
36
|
+
Environment.load_variables
|
37
37
|
@shell.say "Running: #{cmd}", :yellow
|
38
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3(
|
38
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3({}, cmd)
|
39
39
|
@shell.say stdout.read(), :green
|
40
40
|
@shell.say stderr.read(), :red
|
41
41
|
stdin.close
|
@@ -47,15 +47,24 @@ module Kaigara
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def template(name, target = nil)
|
50
|
+
Environment.load_variables
|
50
51
|
tpl_file = name + '.erb'
|
51
52
|
destination = target
|
52
53
|
destination = "/#{tpl_file}" if destination.nil?
|
53
54
|
destination.gsub!(/\.erb$/,'')
|
54
55
|
|
55
56
|
@shell.say "Rendering template #{tpl_file} to #{destination}", :yellow
|
56
|
-
@shell.inject(@environment.variables)
|
57
57
|
ThorShell.source_root(File.join(@work_dir, 'resources'))
|
58
58
|
@shell.template(tpl_file, destination)
|
59
|
+
|
60
|
+
return destination
|
61
|
+
end
|
62
|
+
|
63
|
+
def script(name, path = nil)
|
64
|
+
target = template(name, File.join( (path.nil? ? "" : path), name))
|
65
|
+
@shell.chmod(target, 0755)
|
66
|
+
target.prepend('./') unless target.match(/^\//)
|
67
|
+
execute("#{target}")
|
59
68
|
end
|
60
69
|
end
|
61
70
|
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require_relative 'spec'
|
2
|
-
require_relative 'context'
|
3
|
-
|
4
1
|
module Kaigara
|
5
2
|
class Package
|
6
3
|
|
@@ -19,7 +16,6 @@ module Kaigara
|
|
19
16
|
def initialize(path = '.')
|
20
17
|
@options = {}
|
21
18
|
@work_dir = path ? File.expand_path(path) : '.'
|
22
|
-
#self.destination_root = @work_dir
|
23
19
|
|
24
20
|
@operations_dir = File.join(@work_dir, OPERATIONS_DIR_NAME)
|
25
21
|
@script_path = File.expand_path(File.join(@work_dir, METADATA_FILE_NAME))
|
@@ -46,7 +42,7 @@ module Kaigara
|
|
46
42
|
end
|
47
43
|
|
48
44
|
def execute_operation!(path)
|
49
|
-
context =
|
45
|
+
context = Operation.new path
|
50
46
|
context.work_dir = @work_dir
|
51
47
|
context.environment = @spec.environment
|
52
48
|
context.apply!
|
data/app/models/sysops/spec.rb
CHANGED
@@ -3,30 +3,12 @@
|
|
3
3
|
|
4
4
|
Vagrant.configure(2) do |config|
|
5
5
|
config.vm.box = "ubuntu/trusty64"
|
6
|
-
|
6
|
+
|
7
7
|
config.vm.provider "virtualbox" do |vb|
|
8
|
-
vb.cpus = "
|
9
|
-
vb.memory = "
|
8
|
+
vb.cpus = "1"
|
9
|
+
vb.memory = "1024"
|
10
10
|
end
|
11
11
|
|
12
|
-
<% if @project_name -%>
|
13
|
-
config.vm.hostname = "<%= @project_name -%>"
|
14
|
-
<%- else -%>
|
15
12
|
config.vm.hostname = "vm"
|
16
|
-
|
17
|
-
|
18
|
-
# config.berkshelf.enabled = true
|
19
|
-
# node_json = JSON.parse(Pathname(__FILE__).dirname.join('nodes', 'rails.json').read)
|
20
|
-
# config.vm.provision :chef_solo do |chef|
|
21
|
-
# chef.node_name = "rails"
|
22
|
-
# chef.nodes_path = "./nodes"
|
23
|
-
# chef.environments_path = "./environments"
|
24
|
-
# chef.cookbooks_path = "./cookbooks"
|
25
|
-
# chef.data_bags_path = "./data_bags"
|
26
|
-
# chef.provisioning_path = "/tmp/vagrant-chef"
|
27
|
-
# chef.run_list = node_json.delete('run_list') if node_json['run_list']
|
28
|
-
# chef.json = node_json
|
29
|
-
# end
|
30
|
-
|
13
|
+
config.vm.provision :kaigara
|
31
14
|
end
|
32
|
-
|
data/lib/kaigara.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Kaigara
|
5
|
+
class Metadata
|
6
|
+
|
7
|
+
class DeepHash < Hash
|
8
|
+
def method_missing(name, *args, &block)
|
9
|
+
if name[-1] == '='
|
10
|
+
key = name[0...-1]
|
11
|
+
self[key] = args.first
|
12
|
+
return self[key]
|
13
|
+
|
14
|
+
elsif !has_key?(name)
|
15
|
+
self[name] = DeepHash.new
|
16
|
+
end
|
17
|
+
|
18
|
+
return self[name]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :data
|
23
|
+
|
24
|
+
def initialize(&block)
|
25
|
+
hash = DeepHash.new
|
26
|
+
block.call(hash)
|
27
|
+
json = hash.to_json
|
28
|
+
@data = JSON.parse(json, object_class: OpenStruct)
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(name, *args, &block)
|
32
|
+
return @data.send(name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/kaigara/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaigara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Helios Technologies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -85,9 +85,8 @@ files:
|
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
87
87
|
- app/controllers/sysops.rb
|
88
|
-
- app/models/sysops/context.rb
|
89
88
|
- app/models/sysops/environment.rb
|
90
|
-
- app/models/sysops/
|
89
|
+
- app/models/sysops/operation.rb
|
91
90
|
- app/models/sysops/package.rb
|
92
91
|
- app/models/sysops/spec.rb
|
93
92
|
- app/templates/sysops/Vagrantfile.erb
|
@@ -97,21 +96,12 @@ files:
|
|
97
96
|
- bin/kaish
|
98
97
|
- bin/setup
|
99
98
|
- kaigara.gemspec
|
100
|
-
- kaigara.yml
|
101
99
|
- lib/kaigara.rb
|
102
100
|
- lib/kaigara/application.rb
|
103
101
|
- lib/kaigara/base_controller.rb
|
104
|
-
- lib/kaigara/baseops.rb
|
105
102
|
- lib/kaigara/client.rb
|
106
|
-
- lib/kaigara/
|
107
|
-
- lib/kaigara/
|
108
|
-
- lib/kaigara/sysops/environment.rb
|
109
|
-
- lib/kaigara/sysops/kaigara_package.rb
|
110
|
-
- lib/kaigara/sysops/package.rb
|
111
|
-
- lib/kaigara/sysops/spec.rb
|
112
|
-
- lib/kaigara/sysops/templates/Vagrantfile.erb
|
113
|
-
- lib/kaigara/sysops/templates/metadata.rb.erb
|
114
|
-
- lib/kaigara/sysops/templates/operation.rb.erb
|
103
|
+
- lib/kaigara/deephash.rb
|
104
|
+
- lib/kaigara/metadata.rb
|
115
105
|
- lib/kaigara/version.rb
|
116
106
|
homepage: https://github.com/helios-technologies/kaigara
|
117
107
|
licenses:
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Kaigara
|
4
|
-
class KaigaraPackage
|
5
|
-
include Thor::Shell
|
6
|
-
|
7
|
-
attr_accessor :name
|
8
|
-
attr_accessor :package_repository
|
9
|
-
|
10
|
-
def initialize(name)
|
11
|
-
@name = name.split('/')
|
12
|
-
end
|
13
|
-
|
14
|
-
def install()
|
15
|
-
# "cd $HOME/.kaish/packages && git clone #{@package_repository}" % @name
|
16
|
-
Dir.mkdir("#{Dir.home}/.kaigara/pkgops/#{@name.last}") # This one's for test
|
17
|
-
end
|
18
|
-
|
19
|
-
def read_config! config
|
20
|
-
conf = config['default']['operation'] || {}
|
21
|
-
@package_repository = conf['package_repository']
|
22
|
-
end
|
23
|
-
|
24
|
-
def is_installed?()
|
25
|
-
Dir.entries(Dir.home + '/.kaigara/pkgops').include? @name.last
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/kaigara.yml
DELETED
data/lib/kaigara/baseops.rb
DELETED
data/lib/kaigara/sysops.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require_relative 'sysops/package'
|
2
|
-
require_relative 'sysops/kaigara_package'
|
3
|
-
|
4
|
-
module Kaigara
|
5
|
-
class Sysops < Baseops
|
6
|
-
no_commands do
|
7
|
-
def self.source_root
|
8
|
-
File.expand_path('sysops/templates', __FILE__)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
desc 'create', 'Creates a folder hierarchy'
|
13
|
-
method_option :name, aliases: '-n', desc: 'Project name'
|
14
|
-
method_option :version, aliases: '-v', desc: 'Project version', default: '1.0.0'
|
15
|
-
method_option :path, aliases: '-p', desc: 'Project path', default: '.'
|
16
|
-
def create
|
17
|
-
package = Package.new(options[:path])
|
18
|
-
package.name = options[:name]
|
19
|
-
package.version = options[:version]
|
20
|
-
package.create!
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'generate <name>', 'Generate a new operation'
|
24
|
-
method_option :path, aliases: '-p', desc: 'Project path', default: '.'
|
25
|
-
def generate(name)
|
26
|
-
package = Package.new(options[:path])
|
27
|
-
package.load!
|
28
|
-
package.create_operation!(name)
|
29
|
-
end
|
30
|
-
|
31
|
-
desc 'exec', 'Execute a package'
|
32
|
-
method_option :path, aliases: '-p', desc: 'Project path', default: '.'
|
33
|
-
def exec
|
34
|
-
package = Package.new(options[:path])
|
35
|
-
say "Executing #{package.name}#{"/#{package.version}" if package.version}...", :yellow
|
36
|
-
package.load!
|
37
|
-
package.run!
|
38
|
-
end
|
39
|
-
|
40
|
-
desc 'install <(github login)/(operation name)>', 'Install a kaigara operation'
|
41
|
-
def install(name)
|
42
|
-
pkg = KaigaraPackage.new(name)
|
43
|
-
begin
|
44
|
-
config = YAML.load_file(File.dirname(__FILE__) + '/../../kaigara.yml')
|
45
|
-
pkg.read_config! config
|
46
|
-
rescue Exception => ex
|
47
|
-
say("Failed to load node configuration! #{ex}", :red)
|
48
|
-
end
|
49
|
-
|
50
|
-
if pkg.is_installed?
|
51
|
-
say('The package is already installed', :green)
|
52
|
-
else
|
53
|
-
say("Installing #{name}...")
|
54
|
-
pkg.install()
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
|
-
module Kaigara
|
4
|
-
class Context
|
5
|
-
class ThorShell < Baseops
|
6
|
-
|
7
|
-
no_commands do
|
8
|
-
def inject(opts = {})
|
9
|
-
opts.each do |k,v|
|
10
|
-
instance_eval { class << self; self end }.send(:attr_accessor, k)
|
11
|
-
send("#{k}=", v)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_accessor :work_dir
|
18
|
-
attr_accessor :name
|
19
|
-
attr_accessor :environment
|
20
|
-
|
21
|
-
def initialize(path)
|
22
|
-
@shell = ThorShell.new
|
23
|
-
@name = File.basename(path)
|
24
|
-
@content = File.read(path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def apply!
|
28
|
-
@shell.say "Applying #{@name}\n--------------------", :yellow
|
29
|
-
instance_eval @content
|
30
|
-
end
|
31
|
-
|
32
|
-
def execute(cmd)
|
33
|
-
@shell.say "Running: #{cmd}", :yellow
|
34
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3(@environment.variables, cmd)
|
35
|
-
@shell.say stdout.read(), :green
|
36
|
-
@shell.say stderr.read(), :red
|
37
|
-
stdin.close
|
38
|
-
stdout.close
|
39
|
-
stderr.close
|
40
|
-
|
41
|
-
exit_status = wait_thr.value
|
42
|
-
raise 'Non zero result' if exit_status != 0
|
43
|
-
end
|
44
|
-
|
45
|
-
def template(template, target = nil)
|
46
|
-
destination = target
|
47
|
-
destination = "/#{template}" if destination.nil?
|
48
|
-
destination.gsub!(/\.erb$/,'')
|
49
|
-
|
50
|
-
@shell.say "Rendering template #{template} to #{destination}", :yellow
|
51
|
-
@shell.inject(@environment.variables)
|
52
|
-
@shell.template(File.join(@work_dir, 'tpl', template), destination)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Kaigara
|
4
|
-
class KaigaraPackage
|
5
|
-
include Thor::Shell
|
6
|
-
|
7
|
-
attr_accessor :name
|
8
|
-
attr_accessor :package_repository
|
9
|
-
|
10
|
-
def initialize(name)
|
11
|
-
@name = name.split('/')
|
12
|
-
end
|
13
|
-
|
14
|
-
def install()
|
15
|
-
# "cd $HOME/.kaish/packages && git clone #{@package_repository}" % @name
|
16
|
-
Dir.mkdir("#{Dir.home}/.kaigara/pkgops/#{@name.last}") # This one's for test
|
17
|
-
end
|
18
|
-
|
19
|
-
def read_config! config
|
20
|
-
conf = config['default']['operation'] || {}
|
21
|
-
@package_repository = conf['package_repository']
|
22
|
-
end
|
23
|
-
|
24
|
-
def is_installed?()
|
25
|
-
Dir.entries(Dir.home + '/.kaigara/pkgops').include? @name.last
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require_relative 'spec'
|
2
|
-
require_relative 'context'
|
3
|
-
|
4
|
-
module Kaigara
|
5
|
-
class Package
|
6
|
-
include Thor::Base
|
7
|
-
include Thor::Actions
|
8
|
-
|
9
|
-
source_root File.expand_path('../templates', __FILE__)
|
10
|
-
|
11
|
-
METADATA_FILE_NAME = 'metadata.rb'
|
12
|
-
VAGRANT_FILE_NAME = 'Vagrantfile'
|
13
|
-
OPERATIONS_DIR_NAME = 'operations'
|
14
|
-
RESOURCES_DIR_NAME = 'resources'
|
15
|
-
|
16
|
-
attr_accessor :work_dir
|
17
|
-
attr_accessor :operations_dir
|
18
|
-
attr_accessor :script_path
|
19
|
-
attr_accessor :dependencies
|
20
|
-
attr_accessor :version
|
21
|
-
attr_accessor :name
|
22
|
-
|
23
|
-
def initialize(path)
|
24
|
-
path ||= '.'
|
25
|
-
@options = {}
|
26
|
-
@work_dir = File.expand_path(path)
|
27
|
-
self.destination_root = @work_dir
|
28
|
-
|
29
|
-
@operations_dir = File.join(@work_dir, OPERATIONS_DIR_NAME)
|
30
|
-
@script_path = File.expand_path(File.join(@work_dir, METADATA_FILE_NAME))
|
31
|
-
@spec = Spec.new(self)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Read and execute metadata.rb
|
35
|
-
def load!
|
36
|
-
script = File.read(@script_path)
|
37
|
-
@spec.instance_eval(script)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Create an empty project structure
|
41
|
-
def create!
|
42
|
-
template('metadata.rb.erb', File.join(@work_dir, METADATA_FILE_NAME))
|
43
|
-
template('Vagrantfile.erb', File.join(@work_dir, VAGRANT_FILE_NAME))
|
44
|
-
empty_directory(File.join(@work_dir, OPERATIONS_DIR_NAME))
|
45
|
-
empty_directory(File.join(@work_dir, RESOURCES_DIR_NAME))
|
46
|
-
end
|
47
|
-
|
48
|
-
# Create an empty operation in ./operations
|
49
|
-
def create_operation!(name)
|
50
|
-
prefix = DateTime.now.strftime('%Y%m%d%H%M%S')
|
51
|
-
template('operation.rb.erb', File.join(@operations_dir, "#{prefix}_#{name}.rb"))
|
52
|
-
end
|
53
|
-
|
54
|
-
# Execute operations in the operations directory one by one
|
55
|
-
def run!
|
56
|
-
Dir[File.join(@operations_dir, '*.rb')].each do |x|
|
57
|
-
execute_operation!(x)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def execute_operation!(path)
|
62
|
-
context = Context.new path
|
63
|
-
context.work_dir = @work_dir
|
64
|
-
context.environment = @spec.environment
|
65
|
-
context.apply!
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
data/lib/kaigara/sysops/spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require_relative 'environment'
|
2
|
-
|
3
|
-
class Spec
|
4
|
-
attr_accessor :environment
|
5
|
-
def initialize(parent)
|
6
|
-
@environment = Kaigara::Environment.new
|
7
|
-
@parent = parent
|
8
|
-
end
|
9
|
-
|
10
|
-
def name(value)
|
11
|
-
@parent.name = value
|
12
|
-
end
|
13
|
-
|
14
|
-
def version(value)
|
15
|
-
@parent.version = value
|
16
|
-
end
|
17
|
-
|
18
|
-
def dep(name, version: nil, source: nil)
|
19
|
-
@parent.dependencies ||= {}
|
20
|
-
@parent.dependencies[name] = {
|
21
|
-
version: version,
|
22
|
-
source: source
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def vars
|
27
|
-
yield environment
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# -*- mode: ruby -*-
|
2
|
-
# vi: set ft=ruby :
|
3
|
-
|
4
|
-
Vagrant.configure(2) do |config|
|
5
|
-
config.vm.box = "ubuntu/trusty64"
|
6
|
-
|
7
|
-
config.vm.provider "virtualbox" do |vb|
|
8
|
-
vb.cpus = "2"
|
9
|
-
vb.memory = "2048"
|
10
|
-
end
|
11
|
-
|
12
|
-
<% if @project_name -%>
|
13
|
-
config.vm.hostname = "<%= @project_name -%>"
|
14
|
-
<%- else -%>
|
15
|
-
config.vm.hostname = "vm"
|
16
|
-
<%- end -%>
|
17
|
-
|
18
|
-
# config.berkshelf.enabled = true
|
19
|
-
# node_json = JSON.parse(Pathname(__FILE__).dirname.join('nodes', 'rails.json').read)
|
20
|
-
# config.vm.provision :chef_solo do |chef|
|
21
|
-
# chef.node_name = "rails"
|
22
|
-
# chef.nodes_path = "./nodes"
|
23
|
-
# chef.environments_path = "./environments"
|
24
|
-
# chef.cookbooks_path = "./cookbooks"
|
25
|
-
# chef.data_bags_path = "./data_bags"
|
26
|
-
# chef.provisioning_path = "/tmp/vagrant-chef"
|
27
|
-
# chef.run_list = node_json.delete('run_list') if node_json['run_list']
|
28
|
-
# chef.json = node_json
|
29
|
-
# end
|
30
|
-
|
31
|
-
end
|
32
|
-
|