kaigara 0.0.1
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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/app/controllers/sysops.rb +58 -0
- data/app/models/sysops/context.rb +62 -0
- data/app/models/sysops/environment.rb +14 -0
- data/app/models/sysops/kaigara_package.rb +28 -0
- data/app/models/sysops/package.rb +56 -0
- data/app/models/sysops/spec.rb +30 -0
- data/app/templates/sysops/Vagrantfile.erb +32 -0
- data/app/templates/sysops/metadata.rb.erb +8 -0
- data/app/templates/sysops/operation.rb.erb +2 -0
- data/bin/console +14 -0
- data/bin/kaish +10 -0
- data/bin/setup +7 -0
- data/kaigara.gemspec +29 -0
- data/kaigara.yml +11 -0
- data/lib/kaigara.rb +12 -0
- data/lib/kaigara/application.rb +12 -0
- data/lib/kaigara/base_controller.rb +27 -0
- data/lib/kaigara/baseops.rb +8 -0
- data/lib/kaigara/client.rb +16 -0
- data/lib/kaigara/sysops.rb +59 -0
- data/lib/kaigara/sysops/context.rb +56 -0
- data/lib/kaigara/sysops/environment.rb +14 -0
- data/lib/kaigara/sysops/kaigara_package.rb +28 -0
- data/lib/kaigara/sysops/package.rb +69 -0
- data/lib/kaigara/sysops/spec.rb +30 -0
- data/lib/kaigara/sysops/templates/Vagrantfile.erb +32 -0
- data/lib/kaigara/sysops/templates/metadata.rb.erb +8 -0
- data/lib/kaigara/sysops/templates/operation.rb.erb +2 -0
- data/lib/kaigara/version.rb +4 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a885b64939dc7a292636f93048a8a7039d75a04
|
4
|
+
data.tar.gz: ab2063b2bd2c2b7df81921806ee6c0645837fc28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a91108175bf25984d89b0c047242c0cf071f2dd7423d17847b0496c7999494301d7a33c62424d6b030e61be9b3cb610dfca1a26508542aabc25cb1366c86d11b
|
7
|
+
data.tar.gz: 10283b83233635d609b304d6ce01529895dc991f1d7e61490a436b70f58709c34db834cec5bd44f62743ca68075eb93cb0da28134cf87ed4a7831639aadbff11
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kaigara
|
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,52 @@
|
|
1
|
+
# Kaigara
|
2
|
+
|
3
|
+
Kaigara is an extendable shell command line for managing simple devops tasks.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'kaigara'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kaigara
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Basic commands are
|
24
|
+
```
|
25
|
+
# Prepare ruby runtime on a remote host
|
26
|
+
$> kaish remote bootstrap USER@SERVER
|
27
|
+
|
28
|
+
# Creates a system operation package (sysops)
|
29
|
+
$> kaish sysops create NAME
|
30
|
+
|
31
|
+
# Generate an operation. Creates an empty file in folder operations
|
32
|
+
$> kaish sysops generate NAME
|
33
|
+
|
34
|
+
# Execute all operations of the current working directory
|
35
|
+
$> 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
|
+
```
|
43
|
+
|
44
|
+
You can use `kaish help` any time to get help.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/helios-technologies/kaigara.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'models/sysops/package'
|
2
|
+
require 'models/sysops/kaigara_package'
|
3
|
+
|
4
|
+
module Kaigara
|
5
|
+
class Sysops < BaseController
|
6
|
+
|
7
|
+
desc 'create NAME', 'Create a new sysops project'
|
8
|
+
def create(name)
|
9
|
+
package = Package.new(name)
|
10
|
+
package.name = name
|
11
|
+
package.version = '1.0.0'
|
12
|
+
empty_directory(name)
|
13
|
+
empty_directory(File.join(name, 'operations'))
|
14
|
+
empty_directory(File.join(name, 'resources'))
|
15
|
+
#in_destination(name) do
|
16
|
+
# render('metadata.rb')
|
17
|
+
# render('Vagrantfile')
|
18
|
+
#end
|
19
|
+
template('metadata.rb.erb', File.join(name, 'metadata.rb'))
|
20
|
+
template('Vagrantfile.erb', File.join(name, 'Vagrantfile'))
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'generate <name>', 'Generate a new operation'
|
24
|
+
def generate(label)
|
25
|
+
package = Package.new
|
26
|
+
package.load!
|
27
|
+
filename = File.join(package.operations_dir, package.operation_name(label))
|
28
|
+
template('operation.rb.erb', filename)
|
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
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Kaigara
|
4
|
+
class Context
|
5
|
+
class ThorShell
|
6
|
+
|
7
|
+
include Thor::Base
|
8
|
+
include Thor::Actions
|
9
|
+
include Thor::Shell
|
10
|
+
|
11
|
+
no_commands do
|
12
|
+
def inject(opts = {})
|
13
|
+
opts.each do |k,v|
|
14
|
+
instance_eval { class << self; self end }.send(:attr_accessor, k)
|
15
|
+
send("#{k}=", v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :work_dir
|
22
|
+
attr_accessor :name
|
23
|
+
attr_accessor :environment
|
24
|
+
|
25
|
+
def initialize(path)
|
26
|
+
@shell = ThorShell.new
|
27
|
+
@name = File.basename(path)
|
28
|
+
@content = File.read(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def apply!
|
32
|
+
@shell.say "Applying #{@name}\n--------------------", :yellow
|
33
|
+
instance_eval @content
|
34
|
+
end
|
35
|
+
|
36
|
+
def execute(cmd)
|
37
|
+
@shell.say "Running: #{cmd}", :yellow
|
38
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(@environment.variables, cmd)
|
39
|
+
@shell.say stdout.read(), :green
|
40
|
+
@shell.say stderr.read(), :red
|
41
|
+
stdin.close
|
42
|
+
stdout.close
|
43
|
+
stderr.close
|
44
|
+
|
45
|
+
exit_status = wait_thr.value
|
46
|
+
raise 'Non zero result' if exit_status != 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def template(name, target = nil)
|
50
|
+
tpl_file = name + '.erb'
|
51
|
+
destination = target
|
52
|
+
destination = "/#{tpl_file}" if destination.nil?
|
53
|
+
destination.gsub!(/\.erb$/,'')
|
54
|
+
|
55
|
+
@shell.say "Rendering template #{tpl_file} to #{destination}", :yellow
|
56
|
+
@shell.inject(@environment.variables)
|
57
|
+
ThorShell.source_root(File.join(@work_dir, 'resources'))
|
58
|
+
@shell.template(tpl_file, destination)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'spec'
|
2
|
+
require_relative 'context'
|
3
|
+
|
4
|
+
module Kaigara
|
5
|
+
class Package
|
6
|
+
|
7
|
+
METADATA_FILE_NAME = 'metadata.rb'
|
8
|
+
VAGRANT_FILE_NAME = 'Vagrantfile'
|
9
|
+
OPERATIONS_DIR_NAME = 'operations'
|
10
|
+
RESOURCES_DIR_NAME = 'resources'
|
11
|
+
|
12
|
+
attr_accessor :work_dir
|
13
|
+
attr_accessor :operations_dir
|
14
|
+
attr_accessor :script_path
|
15
|
+
attr_accessor :dependencies
|
16
|
+
attr_accessor :version
|
17
|
+
attr_accessor :name
|
18
|
+
|
19
|
+
def initialize(path = '.')
|
20
|
+
@options = {}
|
21
|
+
@work_dir = path ? File.expand_path(path) : '.'
|
22
|
+
#self.destination_root = @work_dir
|
23
|
+
|
24
|
+
@operations_dir = File.join(@work_dir, OPERATIONS_DIR_NAME)
|
25
|
+
@script_path = File.expand_path(File.join(@work_dir, METADATA_FILE_NAME))
|
26
|
+
@spec = Spec.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Read and execute metadata.rb
|
30
|
+
def load!
|
31
|
+
script = File.read(@script_path)
|
32
|
+
@spec.instance_eval(script)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Create an empty operation in ./operations
|
36
|
+
def operation_name(name)
|
37
|
+
ts = DateTime.now.strftime('%Y%m%d%H%M%S')
|
38
|
+
return "%s_%s.rb" % [ts, name]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Execute operations in the operations directory one by one
|
42
|
+
def run!
|
43
|
+
Dir[File.join(@operations_dir, '*.rb')].each do |x|
|
44
|
+
execute_operation!(x)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute_operation!(path)
|
49
|
+
context = Context.new path
|
50
|
+
context.work_dir = @work_dir
|
51
|
+
context.environment = @spec.environment
|
52
|
+
context.apply!
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,30 @@
|
|
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
|
+
|
@@ -0,0 +1,32 @@
|
|
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
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kaigara"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/kaish
ADDED
data/bin/setup
ADDED
data/kaigara.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kaigara/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kaigara"
|
8
|
+
spec.version = Kaigara::VERSION
|
9
|
+
spec.authors = ["Helios Technologies"]
|
10
|
+
spec.email = ["contact@heliostech.fr"]
|
11
|
+
|
12
|
+
spec.summary = %q{Kaigara is a swiss army knife for Devops}
|
13
|
+
spec.description = %q{Kaigara is an extensible shell command line for managing simple system operations.}
|
14
|
+
spec.homepage = "https://github.com/helios-technologies/kaigara"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.executables = ["kaish","console","setup"]
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "thor", "~> 0.19.1"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
data/kaigara.yml
ADDED
data/lib/kaigara.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
app_path = File.expand_path('../../app', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(app_path) unless $LOAD_PATH.include?(app_path)
|
6
|
+
|
7
|
+
require 'kaigara/version'
|
8
|
+
require 'kaigara/base_controller'
|
9
|
+
require 'kaigara/application'
|
10
|
+
|
11
|
+
require 'controllers/sysops'
|
12
|
+
require 'kaigara/client'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Kaigara
|
2
|
+
class BaseController < Thor
|
3
|
+
include Thor::Base
|
4
|
+
include Thor::Actions
|
5
|
+
include Thor::Shell
|
6
|
+
|
7
|
+
no_commands do
|
8
|
+
def self.source_root
|
9
|
+
Application.root.join('app','templates','sysops')
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(source, destination = nil)
|
13
|
+
template(source + '.erb')
|
14
|
+
end
|
15
|
+
|
16
|
+
def in_destination(path, &block)
|
17
|
+
previous_path = destination_root
|
18
|
+
destination_root = File.join(previous_path, path)
|
19
|
+
p destination_root
|
20
|
+
block.call
|
21
|
+
destination_root = previous_path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kaigara
|
2
|
+
class Client < Thor
|
3
|
+
|
4
|
+
def self.exit_on_failure?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'sysops COMMAND ARGS', 'System operations'
|
9
|
+
subcommand 'sysops', Sysops
|
10
|
+
|
11
|
+
desc 'version', 'Kaish version'
|
12
|
+
def version
|
13
|
+
say VERSION
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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
|
+
|
@@ -0,0 +1,56 @@
|
|
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
|
+
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,69 @@
|
|
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
|
+
|
@@ -0,0 +1,30 @@
|
|
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
|
+
|
@@ -0,0 +1,32 @@
|
|
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
|
+
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kaigara
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Helios Technologies
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Kaigara is an extensible shell command line for managing simple system
|
70
|
+
operations.
|
71
|
+
email:
|
72
|
+
- contact@heliostech.fr
|
73
|
+
executables:
|
74
|
+
- console
|
75
|
+
- kaish
|
76
|
+
- setup
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- ".rspec"
|
82
|
+
- ".travis.yml"
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- app/controllers/sysops.rb
|
88
|
+
- app/models/sysops/context.rb
|
89
|
+
- app/models/sysops/environment.rb
|
90
|
+
- app/models/sysops/kaigara_package.rb
|
91
|
+
- app/models/sysops/package.rb
|
92
|
+
- app/models/sysops/spec.rb
|
93
|
+
- app/templates/sysops/Vagrantfile.erb
|
94
|
+
- app/templates/sysops/metadata.rb.erb
|
95
|
+
- app/templates/sysops/operation.rb.erb
|
96
|
+
- bin/console
|
97
|
+
- bin/kaish
|
98
|
+
- bin/setup
|
99
|
+
- kaigara.gemspec
|
100
|
+
- kaigara.yml
|
101
|
+
- lib/kaigara.rb
|
102
|
+
- lib/kaigara/application.rb
|
103
|
+
- lib/kaigara/base_controller.rb
|
104
|
+
- lib/kaigara/baseops.rb
|
105
|
+
- lib/kaigara/client.rb
|
106
|
+
- lib/kaigara/sysops.rb
|
107
|
+
- lib/kaigara/sysops/context.rb
|
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
|
115
|
+
- lib/kaigara/version.rb
|
116
|
+
homepage: https://github.com/helios-technologies/kaigara
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.5.1
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Kaigara is a swiss army knife for Devops
|
140
|
+
test_files: []
|