compote 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99486c3d153db32cab2c8d73aeef121c776763ac
4
+ data.tar.gz: 44dd7d9d41bbc8c55119b6a3e74ce7157b779d3c
5
+ SHA512:
6
+ metadata.gz: 50e82f05fe8bdab08574c1bb7f078cebe3212d2156cce0545c64213fdfad0601d23974ef72ca5ab6cfd18e94795d55d0a9e61c9986d3098b4f5cca6a6d2fc8f9
7
+ data.tar.gz: fa6c01b6059c0a6fa4b898f344aaf10b04855f09e04b496617bd579c8f9620be1aa67c057db03071f62fa1aab4d0c35acfd772f85eed622a3d6ea7d0794c6487
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+
3
+ /*.gem
4
+
5
+ Gemfile.lock
6
+
7
+ .rspec_status
8
+
9
+ /notes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dmitry Maganov
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.
@@ -0,0 +1,103 @@
1
+ # Compote
2
+
3
+ Compote is a wrapper for docker-compose. It extends compose in two ways.
4
+
5
+ Firstly, it adds additional fields in the config spec, main focus of those additions is to provide more flexibility with extending of services definitions.
6
+
7
+ Second, it adds abitility to specify custom commands as node's package.json "scripts" field do.
8
+
9
+
10
+ ## Installation
11
+
12
+ $ gem install compote
13
+
14
+
15
+ ## Usage
16
+
17
+ You use `compote` as you do `docker-compose` as all commands are redirected to it.
18
+
19
+ Compote will search for `docker-compote.yml` file in current directory. You also can specify a path to a compote's config with env variable `COMPOTE_FILE`.
20
+
21
+ Here are additions that compote brings.
22
+
23
+ ```yml
24
+ version: '2.1' # currently only version 2.1 supported
25
+
26
+ compote: # all additions live under compote key, here on top level and in a service definition
27
+
28
+ # extends
29
+ # allows to include definitions from other files
30
+ # it can be a single string, an array of strings
31
+ # it can also be a hash where keys are paths and values are objects with optional fields "except" and "only"
32
+ # only
33
+ # all paths resolved to a current compote config file
34
+ extends:
35
+ ../hello.yml: { only: [ 'volumes' ] }
36
+
37
+ # env_file
38
+ # can be a single string or array of strings
39
+ # if files specified they must exist
40
+ # if no file specified and there is .env file near config, it is used
41
+ env_file: .hello_env
42
+
43
+ # environment
44
+ # can be a hash or an array of definitions (like the environment field in a service definition)
45
+ environment:
46
+ COMPOSE_PROJECT_NAME: hello
47
+
48
+ # commands
49
+ # commands specified here will be available for invocation by "compote command KEY [ARGS...]"
50
+ # a resulted executed command will be "COMMAND [ARGS...]"
51
+ # commands executed in environment combined from shell ones, env_file and environment options.
52
+ # to list available commands call "compote commands"
53
+ commands:
54
+ hello: echo "hello"
55
+
56
+ services:
57
+
58
+ hello:
59
+ image: hello
60
+ compote:
61
+
62
+ # extends
63
+ # same as extends in top compote settings, but with a name of a extended service after a colon
64
+ # this is not the same as usual service extends, as it recursively merges everything and
65
+ # does not care about ignoring some fields like docker-compose does
66
+ # you can reproduce compose way using "except" or "only" options
67
+ extends:
68
+ - ../hello.yml:hello
69
+ - ../hello.yml:world
70
+
71
+ # volumes, networks
72
+ # allow you to specify volumes and networks inside a service defintion
73
+ # those fields will be merged in top level ones for docker-compose consumption
74
+ # having those here simplifies extending of services
75
+ volumes: {}
76
+ networks: {}
77
+
78
+ # commands
79
+ # commands specified here will be available for invocation by "compote command SERVICE:KEY [ARGS...]"
80
+ # a resulted executed command will be "compote run [OPTIONS] SERVICE [COMMAND] [ARGS]"
81
+ # a command specified will be splited into two parts - run's options and a service command
82
+ # a service command starts at first argument not starting with a dash
83
+ commands:
84
+ world: --rm bash # it will execute "docker-compose run --rm hello bash"
85
+ ```
86
+
87
+
88
+ ## TODO
89
+
90
+ - Tests with aruba.
91
+ - Interpolation of env variables in compote fields.
92
+ - Suggestions for misspelled commands.
93
+ - Add some power to `only` and `except` extend options for specifying nested paths.
94
+
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vonagam/compote.
99
+
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+
4
+ Dir.glob( 'config/gems/**/tasks.rake' ).each { | path | load path }
5
+
6
+
7
+ task default: 'gem:rspec'
data/bin/pry ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ ENV[ 'BUNDLE_GEMFILE' ] ||= File.expand_path( '../../Gemfile', Pathname.new( __FILE__ ).realpath )
6
+
7
+ require 'rubygems'
8
+
9
+ require 'bundler/setup'
10
+
11
+
12
+ require 'compote'
13
+
14
+
15
+ load Gem.bin_path 'pry', 'pry'
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ ENV[ 'BUNDLE_GEMFILE' ] ||= File.expand_path( '../../Gemfile', Pathname.new( __FILE__ ).realpath )
6
+
7
+ require 'rubygems'
8
+
9
+ require 'bundler/setup'
10
+
11
+
12
+ load Gem.bin_path 'rake', 'rake'
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ ENV[ 'BUNDLE_GEMFILE' ] ||= File.expand_path( '../../Gemfile', Pathname.new( __FILE__ ).realpath )
6
+
7
+ require 'rubygems'
8
+
9
+ require 'bundler/setup'
10
+
11
+
12
+ load Gem.bin_path 'rspec-core', 'rspec'
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path '../lib', __FILE__
4
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
5
+
6
+ require 'compote/version'
7
+
8
+
9
+ Gem::Specification.new do | spec |
10
+
11
+ spec.name = 'compote'
12
+ spec.version = Compote::VERSION
13
+ spec.authors = [ 'Dmitry Maganov' ]
14
+ spec.email = [ 'vonagam@gmail.com' ]
15
+
16
+ spec.summary = 'Wrapper for docker-compose with additional features.'
17
+ spec.homepage = 'https://github.com/vonagam/compote'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split( "\x0" ).reject { | path | path.match %r{^spec/} }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep( %r{^exe/} ) { | path | File.basename path }
23
+ spec.require_paths = [ 'lib' ]
24
+
25
+
26
+ spec.add_dependency 'thor', '~> 0.19' # cli builder - erikhuda/thor
27
+ spec.add_dependency 'json-schema', '~> 2.8' # json scheme validator - ruby-json-schema/json-schema
28
+ spec.add_dependency 'dotenv', '~> 2.2' # env variables from .env file - bkeepers/dotenv
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.14' # dependencies manager - bundler/bundler
31
+ spec.add_development_dependency 'rake', '~> 12.0' # tasks runner - ruby/rake
32
+ spec.add_development_dependency 'rspec', '~> 3.0' # test framework - rspec/rspec
33
+ spec.add_development_dependency 'aruba', '~> 0.14' # test framework - rspec/rspec
34
+
35
+ spec.add_development_dependency 'pry', '~> 0.10' # debug console - pry/pry
36
+ spec.add_development_dependency 'pry-rescue', '~> 1.4' # start debug on exception - conradirwin/pry-rescue
37
+ spec.add_development_dependency 'pry-stack_explorer', '~> 0.4' # moving in stack vertically - pry/pry-stack_explorer
38
+ spec.add_development_dependency 'pry-byebug', '~> 3.4' # moving in stack forward - deivid-rodriguez/pry-byebug
39
+ spec.add_development_dependency 'pry-inline', '~> 1.0' # view variables values inline - seikichi/pry-inline
40
+ spec.add_development_dependency 'pry-state', '~> 0.1' # view variables values - sudhagars/pry-state
41
+ spec.add_development_dependency 'pry-doc', '~> 0.10' # view ruby core classes documentation - pry/pry-doc
42
+
43
+ end
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,9 @@
1
+ namespace :gem do
2
+
3
+ task :rspec do
4
+
5
+ exec 'bin/rspec --options ./config/gems/rspec/.rspec'
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'compote/cli'
4
+
5
+
6
+ Compote::CLI.start
@@ -0,0 +1,22 @@
1
+ require 'json-schema'
2
+
3
+ require 'dotenv'
4
+
5
+ require 'yaml'
6
+
7
+ require 'tempfile'
8
+
9
+
10
+ module Compote
11
+
12
+ require 'compote/schema'
13
+
14
+ require 'compote/config'
15
+
16
+ require 'compote/service_config'
17
+
18
+ require 'compote/error'
19
+
20
+ require 'compote/version'
21
+
22
+ end
@@ -0,0 +1,74 @@
1
+ require 'compote'
2
+
3
+ require 'thor'
4
+
5
+ require 'shellwords'
6
+
7
+
8
+ module Compote
9
+
10
+ class CLI < Thor
11
+
12
+ require 'compote/cli/compose'
13
+
14
+ require 'compote/cli/command'
15
+
16
+ require 'compote/cli/commands'
17
+
18
+ require 'compote/cli/env'
19
+
20
+ require 'compote/cli/help'
21
+
22
+ require 'compote/cli/version'
23
+
24
+ protected
25
+
26
+ def load_config
27
+
28
+ path = ENV.fetch 'COMPOTE_FILE', './docker-compote.yml'
29
+
30
+ config = Config.load_config path
31
+
32
+ config
33
+
34
+ end
35
+
36
+ def run_compose ( command, *arguments )
37
+
38
+ compote_config = load_config
39
+
40
+ compose_environment = compote_config.compose_environment
41
+
42
+ compose_file = compote_config.compose_file
43
+
44
+ system compose_environment, 'docker-compose', '-f', compose_file.path, command, *arguments
45
+
46
+ exit_status = $?.exitstatus
47
+
48
+ compose_file.unlink
49
+
50
+ exit exit_status
51
+
52
+ rescue Error => error
53
+
54
+ compose_file&.unlink
55
+
56
+ exit_with_error error
57
+
58
+ ensure
59
+
60
+ compose_file&.unlink
61
+
62
+ end
63
+
64
+ def exit_with_error ( error )
65
+
66
+ say error.message, :red
67
+
68
+ exit 1
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,69 @@
1
+ module Compote
2
+
3
+ class CLI < Thor
4
+
5
+ desc 'command', 'Run command specified in docker-compote config'
6
+
7
+ def command ( key, *arguments )
8
+
9
+ config = load_config
10
+
11
+ commands = config.commands
12
+
13
+ command = commands[ key ]
14
+
15
+ service_name, command_name = key.include?( ':' ) ? key.split( ':' ) : [ nil, key ]
16
+
17
+ raise UndefinedCommandError.new service_name: service_name, command_name: command_name, config: config unless command
18
+
19
+ arguments = [ *Shellwords.split( command ), *arguments ]
20
+
21
+ say "Running compote command \"#{ key }\":"
22
+
23
+ if service_name
24
+
25
+ run_arguments, command_arguments = split_arguments arguments
26
+
27
+ arguments = [ 'run', *run_arguments, service_name, *command_arguments ]
28
+
29
+ say Shellwords.join [ 'compote', *arguments ]
30
+
31
+ run_compose *arguments
32
+
33
+ else
34
+
35
+ say Shellwords.join arguments
36
+
37
+ environment = config.compose_environment
38
+
39
+ exec environment, *arguments
40
+
41
+ end
42
+
43
+ rescue Error => error
44
+
45
+ exit_with_error error
46
+
47
+ end
48
+
49
+ protected
50
+
51
+ def split_arguments ( arguments )
52
+
53
+ is_run_option = true
54
+
55
+ run_arguments, command_arguments = arguments.partition do | argument |
56
+
57
+ is_run_option &&= argument.match? /\A-/
58
+
59
+ is_run_option
60
+
61
+ end
62
+
63
+ [ run_arguments, command_arguments ]
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,31 @@
1
+ module Compote
2
+
3
+ class CLI < Thor
4
+
5
+ desc 'commands', 'List commands specified in docker-compote config'
6
+
7
+ def commands
8
+
9
+ config = load_config
10
+
11
+ commands = config.commands
12
+
13
+ if commands.empty?
14
+
15
+ say 'No commands specified'
16
+
17
+ else
18
+
19
+ say commands.map { | key, command | "#{ key } -> #{ command }" }.join "\n"
20
+
21
+ end
22
+
23
+ rescue Error => error
24
+
25
+ exit_with_error error
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end