quaker 0.2.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 +11 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/docker/services/all.yml +10 -0
- data/examples/docker/services/infra.yml +6 -0
- data/exe/quaker +3 -0
- data/lib/quaker.rb +40 -0
- data/lib/quaker/compose_file.rb +10 -0
- data/lib/quaker/git_resolver.rb +31 -0
- data/lib/quaker/include.rb +15 -0
- data/lib/quaker/tag_filter.rb +30 -0
- data/lib/quaker/version.rb +3 -0
- data/quaker.gemspec +38 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c6f507ffc151a13c530eb0d710511914c5ebced2
|
4
|
+
data.tar.gz: 9fbce7e2eb41682c7252bda5ae11c54a53676a32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23f156e7a9a000aa30278fe92454e8e96b3700100df926784ac7310d955602a4e2fa55bc3a0b48363b1d701b47722fd983691e2fd7aae14c90409a54213c068b
|
7
|
+
data.tar.gz: 98750922a7348e1a2747410821cccefc5187f994b74fbbb5daf25a0e6c70f6a1557a3d6773ac1d1a0515c03de9c338a5e26b41b58cf3934513ecfd4d36552557
|
data/.gitignore
ADDED
data/.gitmodules
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 Igor Shapiro
|
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,63 @@
|
|
1
|
+
[](https://codeclimate.com/github/igorshapiro/quaker)
|
2
|
+
|
3
|
+
# Quaker
|
4
|
+
|
5
|
+
Extend docker-compose by adding support to:
|
6
|
+
- include files
|
7
|
+
- run services (and their dependencies) by tag
|
8
|
+
- automatically detect service directories by git repository
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```
|
13
|
+
gem install quaker
|
14
|
+
```
|
15
|
+
|
16
|
+
## Example
|
17
|
+
|
18
|
+
### Given:
|
19
|
+
|
20
|
+
```
|
21
|
+
# docker/services/infra.yml
|
22
|
+
redis:
|
23
|
+
image: redis
|
24
|
+
links:
|
25
|
+
- mongo
|
26
|
+
mongo:
|
27
|
+
image: mongo
|
28
|
+
postgres:
|
29
|
+
image: postgres
|
30
|
+
```
|
31
|
+
|
32
|
+
```
|
33
|
+
# docker/services/all.yml
|
34
|
+
include:
|
35
|
+
- infra.yml
|
36
|
+
svc1:
|
37
|
+
depends_on:
|
38
|
+
- redis
|
39
|
+
tags:
|
40
|
+
- svc1
|
41
|
+
svc2:
|
42
|
+
depends_on:
|
43
|
+
- mongo
|
44
|
+
tags:
|
45
|
+
- svc2
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
### Generating docker-compose file
|
50
|
+
|
51
|
+
```
|
52
|
+
quaker -t svc1
|
53
|
+
```
|
54
|
+
|
55
|
+
will generate a docker compose consisting only of `svc1` and `redis`.
|
56
|
+
|
57
|
+
`Note:` generated docker-compose will be written to stdout
|
58
|
+
|
59
|
+
### Using the generated docker-compose.yml
|
60
|
+
|
61
|
+
```
|
62
|
+
quaker -t svc1 | docker-compose -f - up(/down)
|
63
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quaker"
|
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/exe/quaker
ADDED
data/lib/quaker.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "quaker/version"
|
2
|
+
require "quaker/include"
|
3
|
+
require "quaker/tag_filter"
|
4
|
+
require "quaker/git_resolver"
|
5
|
+
require "quaker/compose_file"
|
6
|
+
|
7
|
+
module Quaker
|
8
|
+
require 'clamp'
|
9
|
+
|
10
|
+
Clamp do
|
11
|
+
parameter "[SPEC_FILE]", "Extended docker-compose file"
|
12
|
+
option %w(--tags -t), "TAGS", "Filter services (and dependencies) by tag", multivalued: true
|
13
|
+
option %w(--dir -d), "DIR", "Specify base directory"
|
14
|
+
|
15
|
+
def default_spec_file
|
16
|
+
File.expand_path('docker/services/all.yml', dir)
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_dir
|
20
|
+
Dir.pwd
|
21
|
+
end
|
22
|
+
|
23
|
+
def dump_params
|
24
|
+
puts "Spec: #{spec_file}"
|
25
|
+
puts "Dir: #{dir}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute
|
29
|
+
dump_params
|
30
|
+
|
31
|
+
Dir.chdir dir
|
32
|
+
|
33
|
+
spec = Include.new.process spec_file
|
34
|
+
spec = TagFilter.new.filter spec, tags_list
|
35
|
+
spec = GitResolver.new.resolve spec
|
36
|
+
spec = ComposeFile.new.build spec
|
37
|
+
puts spec
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
class GitResolver
|
4
|
+
def find_dir_for_repo repo
|
5
|
+
dir = Dir.glob('*')
|
6
|
+
.select {|f| File.directory? f}
|
7
|
+
.select {|dir|
|
8
|
+
stdin, stdout, stderr = Open3.popen3("cd #{dir} && git remote -v")
|
9
|
+
out = stdout.gets
|
10
|
+
out && out.include?(repo)
|
11
|
+
}
|
12
|
+
.first
|
13
|
+
return nil unless dir
|
14
|
+
"./#{dir}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def resolve services_map
|
18
|
+
for name, spec in services_map
|
19
|
+
puts spec
|
20
|
+
git_repo = spec.delete("git")
|
21
|
+
next unless git_repo
|
22
|
+
|
23
|
+
dir = find_dir_for_repo git_repo
|
24
|
+
|
25
|
+
puts "ERROR: Unable to find dir for repo #{git_repo}" and return unless dir
|
26
|
+
|
27
|
+
spec["build"] = dir
|
28
|
+
end
|
29
|
+
services_map
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Include
|
4
|
+
INCLUDE_KEY = 'include'
|
5
|
+
def process filepath
|
6
|
+
dir = File.join(filepath, '..')
|
7
|
+
spec = YAML.load(File.read(filepath))
|
8
|
+
return spec unless spec.has_key?(INCLUDE_KEY)
|
9
|
+
|
10
|
+
spec
|
11
|
+
.delete(INCLUDE_KEY)
|
12
|
+
.map {|file| File.expand_path(file, dir) }
|
13
|
+
.inject(spec) { |acc, file| acc.merge(process file) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class TagFilter
|
2
|
+
def dependencies services_map, name
|
3
|
+
spec = services_map[name]
|
4
|
+
depends_on = spec["depends_on"] || []
|
5
|
+
links = (spec["links"] || []).map{|l| l.split(':')[0]}
|
6
|
+
deps = links + depends_on
|
7
|
+
deps + deps.map{|d| dependencies(services_map, d)}.flatten
|
8
|
+
end
|
9
|
+
|
10
|
+
def is_tagged_service spec, tags_list
|
11
|
+
svc_tags = spec.delete("tags") || []
|
12
|
+
|
13
|
+
# Skip service if no common tags
|
14
|
+
common = svc_tags & tags_list
|
15
|
+
common && !common.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def filter services_map, tags_list
|
19
|
+
return services_map if !tags_list || tags_list.empty?
|
20
|
+
|
21
|
+
services_map.inject({}){|acc, (name, spec)|
|
22
|
+
return acc unless is_tagged_service(spec, tags_list)
|
23
|
+
|
24
|
+
acc[name] = spec
|
25
|
+
|
26
|
+
dependencies(services_map, name)
|
27
|
+
.inject(acc){|acc, d| acc.update(d => services_map[d])}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
data/quaker.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quaker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quaker"
|
8
|
+
spec.version = Quaker::VERSION
|
9
|
+
spec.authors = ["Igor Shapiro"]
|
10
|
+
spec.email = ["shapigor@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Preprocessor for docker-compose}
|
13
|
+
spec.description = %q{
|
14
|
+
Extend docker-compose by adding support to:
|
15
|
+
- include files
|
16
|
+
- run services (and their dependencies) by tag
|
17
|
+
- automatically detect service directories by git repository
|
18
|
+
}
|
19
|
+
spec.homepage = "https://igorshapiro.github.io/quaker/"
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
23
|
+
# delete this section to allow pushing this gem to any host.
|
24
|
+
if spec.respond_to?(:metadata)
|
25
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
26
|
+
else
|
27
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Shapiro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "\n Extend docker-compose by adding support to:\n - include files\n
|
56
|
+
\ - run services (and their dependencies) by tag\n - automatically detect service
|
57
|
+
directories by git repository\n "
|
58
|
+
email:
|
59
|
+
- shapigor@gmail.com
|
60
|
+
executables:
|
61
|
+
- quaker
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- ".gitmodules"
|
67
|
+
- ".rspec"
|
68
|
+
- ".travis.yml"
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- examples/docker/services/all.yml
|
76
|
+
- examples/docker/services/infra.yml
|
77
|
+
- exe/quaker
|
78
|
+
- lib/quaker.rb
|
79
|
+
- lib/quaker/compose_file.rb
|
80
|
+
- lib/quaker/git_resolver.rb
|
81
|
+
- lib/quaker/include.rb
|
82
|
+
- lib/quaker/tag_filter.rb
|
83
|
+
- lib/quaker/version.rb
|
84
|
+
- quaker.gemspec
|
85
|
+
homepage: https://igorshapiro.github.io/quaker/
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
allowed_push_host: https://rubygems.org
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Preprocessor for docker-compose
|
110
|
+
test_files: []
|