orchparty 0.3.1 → 1.0.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 +4 -4
- data/.dockerignore +1 -0
- data/Dockerfile +14 -0
- data/README.md +103 -1
- data/Rakefile +4 -3
- data/docker-entrypoint +2 -0
- data/exe/orchparty +1 -14
- data/lib/orchparty/cli.rb +33 -0
- data/lib/orchparty/plugin.rb +24 -0
- data/lib/orchparty/plugins/docker_compose_v1.rb +34 -0
- data/lib/orchparty/{generators → plugins}/docker_compose_v2.rb +22 -9
- data/lib/orchparty/version.rb +1 -1
- data/lib/orchparty.rb +16 -7
- data/orchparty.gemspec +1 -2
- metadata +12 -28
- data/lib/orchparty/generators/docker_compose_v1.rb +0 -20
- data/lib/orchparty/generators.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2ccdea8159a378436eaf3a11787bacf9535f8ad
|
4
|
+
data.tar.gz: 3dba4a2eefd4c7939dff7a96a27b4fb3b04d19d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7754f19348534203cf89552abbd3dd8288380770e1e5045e1735ec1196b4ab49caadc4c96cd7c9f93d3da302b240bd60e15e00ff19015224f9e4c2eb4a3e78bc
|
7
|
+
data.tar.gz: f770f266217b8131e7cfff17952ab49f3a1d54cf19af52465d57dd8942fbcd6710a4798cfad6222683f28d295ea407b596ce580d9916bdc0474f6af012162df0
|
data/.dockerignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dockerfile
|
data/Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
FROM ruby:2.3.1-slim
|
2
|
+
RUN apt-get update && apt-get install -y git
|
3
|
+
RUN mkdir /orchparty
|
4
|
+
WORKDIR /orchparty
|
5
|
+
ADD Gemfile .
|
6
|
+
ADD Gemfile.lock .
|
7
|
+
ADD orchparty.gemspec .
|
8
|
+
ADD lib lib
|
9
|
+
ADD .git .git
|
10
|
+
RUN bundle install --without development test
|
11
|
+
ADD . .
|
12
|
+
RUN rake install
|
13
|
+
COPY docker-entrypoint /usr/local/bin/
|
14
|
+
ENTRYPOINT ["/bin/sh", "docker-entrypoint"]
|
data/README.md
CHANGED
@@ -83,6 +83,8 @@ Maybe for the future it is possible to run the gem in a docker container, so no
|
|
83
83
|
|
84
84
|
## Usage
|
85
85
|
|
86
|
+
### CLI
|
87
|
+
|
86
88
|
See the commandline usage instrucution by running:
|
87
89
|
|
88
90
|
$ orchparty help
|
@@ -90,7 +92,41 @@ See the commandline usage instrucution by running:
|
|
90
92
|
For generating eg. use:
|
91
93
|
|
92
94
|
|
93
|
-
$ orchparty
|
95
|
+
$ orchparty generate docker_compose_v2 -f stack.rb -o docker-compose.yml -a my-cool-app
|
96
|
+
|
97
|
+
### In your own piece of code
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
require 'orchparty'
|
101
|
+
|
102
|
+
# load the generator plugin you want to use
|
103
|
+
Orchparty.plugin :docker_compose_v1
|
104
|
+
|
105
|
+
Orchparty.generate(:docker_compose_v1,
|
106
|
+
# all options that are needed for orchparty to transform
|
107
|
+
# your input to a plain hash for generating
|
108
|
+
{filename: "path/to/input_file.rb",
|
109
|
+
application: "application_name_to_generate" },
|
110
|
+
# all options that are needed for the plugin
|
111
|
+
{output: "path/to/output_file.yml"})
|
112
|
+
```
|
113
|
+
|
114
|
+
### In your own piece of code
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
require 'orchparty'
|
118
|
+
|
119
|
+
# load the generator plugin you want to use
|
120
|
+
Orchparty.plugin :docker_compose_v1
|
121
|
+
|
122
|
+
Orchparty.generate(:docker_compose_v1,
|
123
|
+
# all options that are needed for orchparty to transform
|
124
|
+
# your input to a plain hash for generating
|
125
|
+
{filename: "path/to/input_file.rb",
|
126
|
+
application: "application_name_to_generate" },
|
127
|
+
# all options that are needed for the plugin
|
128
|
+
{output: "path/to/output_file.yml"})
|
129
|
+
```
|
94
130
|
|
95
131
|
## DSL spec
|
96
132
|
|
@@ -341,6 +377,72 @@ application 'app_perf-prod' do
|
|
341
377
|
end
|
342
378
|
```
|
343
379
|
|
380
|
+
## Plugins
|
381
|
+
|
382
|
+
Orchparty allows you to write own generators via a Plugin system. Also the
|
383
|
+
buildin generators like docker_compose_v1 and docker_compose_v2 generators are
|
384
|
+
only plugins.
|
385
|
+
|
386
|
+
To build your own plugin create a ruby gem with a Plugin
|
387
|
+
configuration under lib/orchparty/plugin/#{plugin_name}.rb
|
388
|
+
|
389
|
+
### Example Plugin:
|
390
|
+
```ruby
|
391
|
+
|
392
|
+
module Orchparty
|
393
|
+
module Plugin
|
394
|
+
class DockerComposeV1
|
395
|
+
|
396
|
+
def self.desc
|
397
|
+
# this description is shown in the cli
|
398
|
+
"generate docker-compose v1 file"
|
399
|
+
end
|
400
|
+
|
401
|
+
def self.define_flags(c)
|
402
|
+
# give add all flags that your Generator needs
|
403
|
+
# see [davetron5000/gli](https://github.com/davetron5000/gli) for
|
404
|
+
# documentatino of flags
|
405
|
+
c.flag [:output,:o], required: true, :desc => 'Set the output file'
|
406
|
+
end
|
407
|
+
|
408
|
+
def self.generate(application, options)
|
409
|
+
# Orchparty will pass the compiled application hash and all options
|
410
|
+
# that you required in define_flags.
|
411
|
+
# Here is the place where you can write your generation logic
|
412
|
+
File.write(options[:output], output(application))
|
413
|
+
end
|
414
|
+
|
415
|
+
private
|
416
|
+
def self.output(ast)
|
417
|
+
ast.services.map do |name, service|
|
418
|
+
service = service.to_h
|
419
|
+
service.delete(:mix)
|
420
|
+
[service.delete(:name), HashUtils.deep_stringify_keys(service.to_h)]
|
421
|
+
end.to_h.to_yaml
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
# register your plugin
|
429
|
+
Orchparty::Plugin.register_plugin(:docker_compose_v1, Orchparty::Plugin::DockerComposeV1)
|
430
|
+
```
|
431
|
+
|
432
|
+
### Plugin Usage:
|
433
|
+
|
434
|
+
#### CLI
|
435
|
+
The CLI tries to load all plugins that you have installed as gem by using
|
436
|
+
Gem::Specification.
|
437
|
+
|
438
|
+
|
439
|
+
#### Code
|
440
|
+
|
441
|
+
If you use orchparty as part of a own application load a plugin via:
|
442
|
+
|
443
|
+
```ruby
|
444
|
+
Orchparty.plugin(:docker_compose_v1)
|
445
|
+
```
|
344
446
|
|
345
447
|
## Development
|
346
448
|
|
data/Rakefile
CHANGED
data/docker-entrypoint
ADDED
data/exe/orchparty
CHANGED
@@ -1,15 +1,2 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require "
|
3
|
-
require "orchparty"
|
4
|
-
|
5
|
-
class OrchPartyCommand < Thor
|
6
|
-
desc "generate INPUT_FILE OUTPUT_FILE APPLICATION_NAME", "generates a configuration file for an application"
|
7
|
-
method_option :generator, :aliases => "-g", default: "docker_compose_v1", :desc => "Which generator to take"
|
8
|
-
method_option :aliases => "g"
|
9
|
-
def generate(input_file, output_file, application_name)
|
10
|
-
generator = options[:generator] || "docker_compose_v1"
|
11
|
-
File.write(output_file, Orchparty.send(generator.to_sym, input_file, application_name))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
OrchPartyCommand.start
|
2
|
+
require "orchparty/cli"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'orchparty'
|
2
|
+
require 'gli'
|
3
|
+
|
4
|
+
Orchparty.load_all_available_plugins
|
5
|
+
|
6
|
+
class OrchPartyApp
|
7
|
+
extend GLI::App
|
8
|
+
|
9
|
+
program_desc 'Write your orchestration configuration with a Ruby DSL that allows you to have mixins, imports and variables.'
|
10
|
+
version Orchparty::VERSION
|
11
|
+
|
12
|
+
subcommand_option_handling :normal
|
13
|
+
|
14
|
+
desc "Compiles a Orchparty input file to a orchestration framework configuration"
|
15
|
+
command :generate do |com|
|
16
|
+
Orchparty.plugins.each do |name, plugin|
|
17
|
+
com.desc plugin.desc
|
18
|
+
com.command(name) do |plugin_command|
|
19
|
+
plugin_command.flag [:filename,:f,'file-name'], required: true, :desc => 'The Orchparty input file'
|
20
|
+
plugin_command.flag [:application,:a], required: true, :desc => 'The application that should be compiled'
|
21
|
+
plugin.define_flags(plugin_command)
|
22
|
+
plugin_command.action do |global_options,plugin_options,args|
|
23
|
+
options = plugin_options.delete(GLI::Command::PARENT)
|
24
|
+
options[:application] = plugin_options[:application]
|
25
|
+
options[:filename] = plugin_options[:filename]
|
26
|
+
Orchparty.generate(name, options, plugin_options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
exit OrchPartyApp.run(ARGV)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Orchparty
|
2
|
+
module Plugin
|
3
|
+
@plugins = {}
|
4
|
+
|
5
|
+
def self.load_plugin(name)
|
6
|
+
begin
|
7
|
+
require "orchparty/plugins/#{name}"
|
8
|
+
raise "Plugin didn't correctly register itself" unless @plugins[name]
|
9
|
+
@plugins[name]
|
10
|
+
rescue LoadError
|
11
|
+
puts "could not load the plugin #{name}, you might install it as a gem or you need to write it by your self ;)"
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.plugins
|
17
|
+
@plugins
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.register_plugin(name, mod)
|
21
|
+
@plugins[name] = mod
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Orchparty
|
2
|
+
module Plugin
|
3
|
+
class DockerComposeV1
|
4
|
+
|
5
|
+
def self.desc
|
6
|
+
"generate docker-compose v1 file"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.define_flags(c)
|
10
|
+
c.flag [:output,:o], :desc => 'Set the output file'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.generate(ast, options)
|
14
|
+
output = output(ast)
|
15
|
+
if options[:output]
|
16
|
+
File.write(options[:output], output)
|
17
|
+
else
|
18
|
+
puts output
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.output(ast)
|
23
|
+
ast.services.map do |name, service|
|
24
|
+
service = service.to_h
|
25
|
+
service.delete(:mix)
|
26
|
+
[service.delete(:name), HashUtils.deep_stringify_keys(service.to_h)]
|
27
|
+
end.to_h.to_yaml
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Orchparty::Plugin.register_plugin(:docker_compose_v1, Orchparty::Plugin::DockerComposeV1)
|
@@ -1,19 +1,31 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
module Orchparty
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
def
|
7
|
-
|
3
|
+
module Plugin
|
4
|
+
module DockerComposeV2
|
5
|
+
|
6
|
+
def self.desc
|
7
|
+
"generate docker-compose v2 file"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.define_flags(c)
|
11
|
+
c.flag [:output,:o], :desc => 'Set the output file'
|
8
12
|
end
|
9
13
|
|
10
|
-
def
|
14
|
+
def self.generate(ast, options)
|
15
|
+
output = output(ast)
|
16
|
+
if options[:output]
|
17
|
+
File.write(options[:output], output)
|
18
|
+
else
|
19
|
+
puts output
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.transform_to_yaml(hash)
|
11
24
|
hash = hash.deep_transform_values{|v| v.is_a?(Hash) ? v.to_h : v }
|
12
25
|
HashUtils.deep_stringify_keys(hash)
|
13
26
|
end
|
14
27
|
|
15
|
-
def output(
|
16
|
-
application = ast.applications[application_name]
|
28
|
+
def self.output(application)
|
17
29
|
{"version" => "2",
|
18
30
|
"services" =>
|
19
31
|
application.services.map do |name,service|
|
@@ -24,7 +36,8 @@ module Orchparty
|
|
24
36
|
"networks" => transform_to_yaml(application.networks),
|
25
37
|
}.to_yaml
|
26
38
|
end
|
27
|
-
|
28
39
|
end
|
29
40
|
end
|
30
41
|
end
|
42
|
+
|
43
|
+
Orchparty::Plugin.register_plugin(:docker_compose_v2, Orchparty::Plugin::DockerComposeV2)
|
data/lib/orchparty/version.rb
CHANGED
data/lib/orchparty.rb
CHANGED
@@ -3,22 +3,31 @@ require "orchparty/version"
|
|
3
3
|
require "orchparty/ast"
|
4
4
|
require "orchparty/context"
|
5
5
|
require "orchparty/transformations"
|
6
|
-
require "orchparty/generators"
|
7
6
|
require "orchparty/dsl_parser"
|
7
|
+
require "orchparty/plugin"
|
8
8
|
require "hash"
|
9
9
|
|
10
10
|
module Orchparty
|
11
11
|
|
12
|
+
def self.load_all_available_plugins
|
13
|
+
Gem::Specification.map {|f| f.matches_for_glob("orchparty/plugins/*.rb") }.flatten.map{|file_name| File.basename(file_name, ".*").to_sym }.each do |plugin_name|
|
14
|
+
plugin(plugin_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.plugins
|
19
|
+
Orchparty::Plugin.plugins
|
20
|
+
end
|
12
21
|
|
13
|
-
def self.
|
14
|
-
|
22
|
+
def self.plugin(name)
|
23
|
+
Orchparty::Plugin.load_plugin(name)
|
15
24
|
end
|
16
25
|
|
17
|
-
def self.
|
18
|
-
Orchparty::
|
26
|
+
def self.ast(filename: , application:)
|
27
|
+
Transformations.transform(Orchparty::DSLParser.new(filename).parse).applications[application]
|
19
28
|
end
|
20
29
|
|
21
|
-
def self.
|
22
|
-
|
30
|
+
def self.generate(plugin_name, options, plugin_options)
|
31
|
+
plugins[plugin_name].generate(ast(filename: options[:filename], application: options[:application]), plugin_options)
|
23
32
|
end
|
24
33
|
end
|
data/orchparty.gemspec
CHANGED
@@ -25,8 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
27
|
spec.add_dependency "hashie", "~> 3.5.6"
|
28
|
-
spec.add_dependency "
|
29
|
-
spec.add_dependency 'psych', '~> 2.2', '>= 2.2.4'
|
28
|
+
spec.add_dependency "gli", "~> 2.16.0"
|
30
29
|
spec.add_development_dependency "bundler", "~> 1.13"
|
31
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orchparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jannis Huebl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -25,39 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.5.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: gli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.16.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: psych
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.2'
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 2.2.4
|
51
|
-
type: :runtime
|
52
|
-
prerelease: false
|
53
|
-
version_requirements: !ruby/object:Gem::Requirement
|
54
|
-
requirements:
|
55
|
-
- - "~>"
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '2.2'
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 2.2.4
|
40
|
+
version: 2.16.0
|
61
41
|
- !ruby/object:Gem::Dependency
|
62
42
|
name: bundler
|
63
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,11 +90,13 @@ executables:
|
|
110
90
|
extensions: []
|
111
91
|
extra_rdoc_files: []
|
112
92
|
files:
|
93
|
+
- ".dockerignore"
|
113
94
|
- ".gitignore"
|
114
95
|
- ".rspec"
|
115
96
|
- ".travis.yml"
|
116
97
|
- CNAME
|
117
98
|
- CODE_OF_CONDUCT.md
|
99
|
+
- Dockerfile
|
118
100
|
- Gemfile
|
119
101
|
- LICENSE
|
120
102
|
- README.md
|
@@ -122,16 +104,18 @@ files:
|
|
122
104
|
- _config.yml
|
123
105
|
- bin/console
|
124
106
|
- bin/setup
|
107
|
+
- docker-entrypoint
|
125
108
|
- exe/orchparty
|
126
109
|
- lib/deep_merge.rb
|
127
110
|
- lib/hash.rb
|
128
111
|
- lib/orchparty.rb
|
129
112
|
- lib/orchparty/ast.rb
|
113
|
+
- lib/orchparty/cli.rb
|
130
114
|
- lib/orchparty/context.rb
|
131
115
|
- lib/orchparty/dsl_parser.rb
|
132
|
-
- lib/orchparty/
|
133
|
-
- lib/orchparty/
|
134
|
-
- lib/orchparty/
|
116
|
+
- lib/orchparty/plugin.rb
|
117
|
+
- lib/orchparty/plugins/docker_compose_v1.rb
|
118
|
+
- lib/orchparty/plugins/docker_compose_v2.rb
|
135
119
|
- lib/orchparty/transformations.rb
|
136
120
|
- lib/orchparty/transformations/all.rb
|
137
121
|
- lib/orchparty/transformations/mixin.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'psych'
|
2
|
-
module Orchparty
|
3
|
-
module Generators
|
4
|
-
class DockerComposeV1
|
5
|
-
attr_reader :ast
|
6
|
-
def initialize(ast)
|
7
|
-
@ast = ast
|
8
|
-
end
|
9
|
-
|
10
|
-
def output(application_name)
|
11
|
-
Psych.dump(ast.applications[application_name].services.map do |name, service|
|
12
|
-
service = service.to_h
|
13
|
-
service.delete(:mix)
|
14
|
-
[service.delete(:name), HashUtils.deep_stringify_keys(service.to_h)]
|
15
|
-
end.to_h)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|