bedouin 0.1.0
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 +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bedouin.gemspec +26 -0
- data/bin/bedouin +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/environments/child.rb +3 -0
- data/examples/environments/simple.rb +3 -0
- data/examples/templates/echo.erb +14 -0
- data/lib/bedouin.rb +16 -0
- data/lib/bedouin/cli.rb +16 -0
- data/lib/bedouin/environment.rb +48 -0
- data/lib/bedouin/job.rb +37 -0
- data/lib/bedouin/runner.rb +18 -0
- data/lib/bedouin/template.rb +17 -0
- data/lib/bedouin/version.rb +3 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b732f736f968c8b5224eaf5ec37fa40fa9bd468
|
4
|
+
data.tar.gz: eb16b4224fb4d08e8bc69474008c5ed347581936
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37f647dc61bb830eb35f30686dad9f51841cef097f32cdaec06ef7840207928d0dc8a6d7ab4a7c501243e5bb3321b3356986d6ccfce758ec377fc2b993460348
|
7
|
+
data.tar.gz: bba9697666dd65306dd6c0824163deb497763b9f31a0508a2bd461b16261fef98937dcc7bc5fc137ae9cf356419de11add563da6a91bc3899019a445635ac209
|
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 Compellon
|
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,72 @@
|
|
1
|
+
# Bedouin
|
2
|
+
|
3
|
+
Bedouin is a tool for templatizing job files for Hashicorp Nomad.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bedouin'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bedouin
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Create one or more environment files and one or more ERB job templates, and then execute:
|
24
|
+
|
25
|
+
$ bedouin <environment file> <template1> <template2> ...
|
26
|
+
|
27
|
+
Bedouin will evaluate each template with any attributes from the environment file available as instance variables. Bedouin will then run the results of each with "nomad run".
|
28
|
+
|
29
|
+
### Environment Files
|
30
|
+
|
31
|
+
Environment files should contain any environment-specific information needed to templatize the Nomad job definitions.
|
32
|
+
|
33
|
+
In the file myname.rb
|
34
|
+
```ruby
|
35
|
+
environment "myname" do |e|
|
36
|
+
e.foo = "bar"
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
This would make an environment file which injects the value "bar" for @foo in any template files. @name is also available with the value "myname".
|
41
|
+
|
42
|
+
Environments are also able to inherit from other environments. Simply specify the path of the parent environment file as a second argument to the environment method:
|
43
|
+
|
44
|
+
In the file mydir/mychild.rb
|
45
|
+
```ruby
|
46
|
+
environment "mychild", "../myname.rb" do |e|
|
47
|
+
e.bar = "baz"
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
As these files are pure ruby, there is a vast amount of possibilities for how to use them. All they must do is return an object which converts to a Hash.
|
52
|
+
|
53
|
+
### Template Files
|
54
|
+
|
55
|
+
Template files are just ERuby files that output a valid nomad job file. For information about ERuby, see https://en.wikipedia.org/wiki/ERuby.
|
56
|
+
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/compellon/bedouin.
|
67
|
+
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
72
|
+
|
data/Rakefile
ADDED
data/bedouin.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bedouin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bedouin"
|
8
|
+
spec.version = Bedouin::VERSION
|
9
|
+
spec.authors = ["David Bresson"]
|
10
|
+
spec.email = ["dbresson@compellon.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Bedouin provides a templating system for Hashicorp Nomad.}
|
13
|
+
spec.homepage = "https://github.com/compellon/bedouin"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "bin"
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "erubis", "~> 2.7"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
data/bin/bedouin
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bedouin"
|
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/setup
ADDED
data/lib/bedouin.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bedouin/version"
|
2
|
+
require "bedouin/template"
|
3
|
+
require "bedouin/environment"
|
4
|
+
require "bedouin/job"
|
5
|
+
require "bedouin/runner"
|
6
|
+
require "bedouin/cli"
|
7
|
+
|
8
|
+
module Bedouin
|
9
|
+
def self.template_for(template_path)
|
10
|
+
Template.new(File.open(template_path))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.environment_for(environment_path)
|
14
|
+
Environment.parse(environment_path)
|
15
|
+
end
|
16
|
+
end
|
data/lib/bedouin/cli.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bedouin
|
2
|
+
class CLI
|
3
|
+
def execute(env_path, *template_paths)
|
4
|
+
e = Bedouin.environment_for(env_path)
|
5
|
+
|
6
|
+
template_paths.lazy.map do |path|
|
7
|
+
t = Bedouin.template_for(path)
|
8
|
+
j = Bedouin::Job.new(e, t)
|
9
|
+
Bedouin::Runner.new.run(j)
|
10
|
+
end.reduce(0) do |m,j|
|
11
|
+
puts j.to_s
|
12
|
+
j.status == 0 ? m : 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module Bedouin
|
3
|
+
class Environment < OpenStruct
|
4
|
+
def self.parse(filename)
|
5
|
+
DSL.new(filename).evaluate
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(n,base={})
|
9
|
+
super(base)
|
10
|
+
self.name = n
|
11
|
+
end
|
12
|
+
|
13
|
+
class DSL
|
14
|
+
def initialize(filename)
|
15
|
+
@filename=filename
|
16
|
+
end
|
17
|
+
|
18
|
+
def evaluate
|
19
|
+
self.instance_eval(File.read(@filename), @filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
def resolve_parent(parent)
|
23
|
+
parent_hash = case parent
|
24
|
+
when String
|
25
|
+
parent_path = File.expand_path(parent, File.dirname(@filename))
|
26
|
+
Environment.parse(parent_path)
|
27
|
+
when NilClass
|
28
|
+
nil
|
29
|
+
else
|
30
|
+
parent
|
31
|
+
end
|
32
|
+
|
33
|
+
unless parent_hash.respond_to? :to_h
|
34
|
+
raise ArgumentError.new "#{parent.class} not a valid type for environment parent"
|
35
|
+
end
|
36
|
+
|
37
|
+
parent_hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def environment(name,parent=nil,&block)
|
41
|
+
parent_hash = resolve_parent(parent)
|
42
|
+
e = Environment.new(name,parent_hash)
|
43
|
+
e.instance_eval &block if block_given?
|
44
|
+
return e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/bedouin/job.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
module Bedouin
|
3
|
+
class Job
|
4
|
+
attr_accessor :status, :stdout, :stderr
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(environment,template)
|
8
|
+
@name = (template.name + '_' + environment.name).freeze
|
9
|
+
@environment = environment
|
10
|
+
@template = template
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_path
|
14
|
+
tempfile.path
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
[stdout, stderr].map do |output|
|
19
|
+
output.each_line.map do |l|
|
20
|
+
@name + ": " + l
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def tempfile
|
27
|
+
unless @tempfile
|
28
|
+
@tempfile = Tempfile.new(@name)
|
29
|
+
f = @tempfile.open
|
30
|
+
f.write @template.run(@environment)
|
31
|
+
f.close
|
32
|
+
end
|
33
|
+
|
34
|
+
@tempfile
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'open3'
|
2
|
+
module Bedouin
|
3
|
+
class Runner
|
4
|
+
def initialize(cfg = { nomad: "nomad" })
|
5
|
+
@cfg = cfg
|
6
|
+
end
|
7
|
+
|
8
|
+
def run(job)
|
9
|
+
Open3.popen3(@cfg[:nomad], "run", job.file_path) do |stdin, stdout, stderr, wait_thr|
|
10
|
+
job.status = wait_thr.value
|
11
|
+
job.stdout = stdout.read
|
12
|
+
job.stderr = stderr.read
|
13
|
+
end
|
14
|
+
|
15
|
+
job
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
module Bedouin
|
3
|
+
class Template
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(template_file)
|
7
|
+
@template_file = template_file
|
8
|
+
@name = File.basename(@template_file.path).sub(/\.[^.]*$/, '').freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(environment)
|
12
|
+
@eruby ||= Erubis::Eruby.new(@template_file.read)
|
13
|
+
@template_file.close
|
14
|
+
@eruby.evaluate(environment.to_h)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bedouin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Bresson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: erubis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
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.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
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:
|
70
|
+
email:
|
71
|
+
- dbresson@compellon.com
|
72
|
+
executables:
|
73
|
+
- bedouin
|
74
|
+
- console
|
75
|
+
- setup
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bedouin.gemspec
|
87
|
+
- bin/bedouin
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- examples/environments/child.rb
|
91
|
+
- examples/environments/simple.rb
|
92
|
+
- examples/templates/echo.erb
|
93
|
+
- lib/bedouin.rb
|
94
|
+
- lib/bedouin/cli.rb
|
95
|
+
- lib/bedouin/environment.rb
|
96
|
+
- lib/bedouin/job.rb
|
97
|
+
- lib/bedouin/runner.rb
|
98
|
+
- lib/bedouin/template.rb
|
99
|
+
- lib/bedouin/version.rb
|
100
|
+
homepage: https://github.com/compellon/bedouin
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.5.1
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Bedouin provides a templating system for Hashicorp Nomad.
|
124
|
+
test_files: []
|