docker-compose 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docker-compose.gemspec +1 -1
- data/lib/docker/compose/rake_tasks.rb +39 -37
- data/lib/docker/compose/session.rb +10 -8
- data/lib/docker/compose/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb2ef064c4d01432c98af7db3070fe1c95a3b5aa
|
4
|
+
data.tar.gz: a97e18e24ae122cb9cd2f26b6e5cfd049a9d6b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 313cad2a5fb2ceea44f02d24742368387e02e001a5b6005e0ee537675dd5408bb63c2a2a1e43c30f3f3eeeceacb4a4cf8a5afacc989b41f70b36eae5e3953c21
|
7
|
+
data.tar.gz: 5612260908f7a23b17fb90433d76eff56384242cde969a1d58ac8b2aa1b27c954d6815c846fc1be66e921927b9596ac9dd89edf90b41aaa92d5408e22bb5d680
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This is a Ruby OOP wrapper for the [docker-compose](https://github.com/docker/co
|
|
4
4
|
container orchestration tool from Docker Inc.
|
5
5
|
|
6
6
|
In addition to wrapping the CLI, this gem provides an environment-variable mapping
|
7
|
-
|
7
|
+
feature that allows you to export environment variables into your _host_ that point
|
8
8
|
to network services exposed by containers. This allows you to run an application on
|
9
9
|
your host for quicker and easier development, but run all of its architectural
|
10
10
|
dependencies -- database, cache, adjacent microservices -- in containers. The
|
data/docker-compose.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "backticks", "~> 0.
|
22
|
+
spec.add_dependency "backticks", "~> 0.3"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -43,6 +43,9 @@ module Docker::Compose
|
|
43
43
|
# depends on them and is properly linked to them.
|
44
44
|
attr_accessor :server
|
45
45
|
|
46
|
+
# Namespace to define the rake tasks under. Defaults to "docker:compose'.
|
47
|
+
attr_accessor :rake_namespace
|
48
|
+
|
46
49
|
# Construct Rake wrapper tasks for docker-compose. If a block is given,
|
47
50
|
# yield self to the block before defining any tasks so their behavior
|
48
51
|
# can be configured by calling #server_env=, #file= and so forth.
|
@@ -51,6 +54,7 @@ module Docker::Compose
|
|
51
54
|
self.file = 'docker-compose.yml'
|
52
55
|
self.server_env = {}
|
53
56
|
self.extra_server_env = {}
|
57
|
+
self.rake_namespace = 'docker:compose'
|
54
58
|
yield self if block_given?
|
55
59
|
|
56
60
|
@shell = Backticks::Runner.new
|
@@ -63,48 +67,46 @@ module Docker::Compose
|
|
63
67
|
end
|
64
68
|
|
65
69
|
private def define
|
66
|
-
namespace
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
else
|
80
|
-
|
81
|
-
|
82
|
-
export_env(print:false)
|
83
|
-
end
|
84
|
-
|
85
|
-
@shell.interactive = true
|
70
|
+
namespace self.rake_namespace do
|
71
|
+
desc 'Print bash exports with IP/ports of running services'
|
72
|
+
task :env do
|
73
|
+
@shell.interactive = false # suppress useless 'port' output
|
74
|
+
|
75
|
+
if Rake.application.top_level_tasks.include? 'docker:compose:env'
|
76
|
+
# This task is being run as top-level task; set process
|
77
|
+
# environment _and_ print bash export commands to stdout.
|
78
|
+
# Also print usage hints if user invoked rake directly vs.
|
79
|
+
# eval'ing it's output
|
80
|
+
print_usage
|
81
|
+
export_env(print:true)
|
82
|
+
else
|
83
|
+
# This task is a dependency of something else; just export the
|
84
|
+
# environment variables for use in-process by other Rake tasks.
|
85
|
+
export_env(print:false)
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
only = (ENV['ONLY'] || '').split(',').compact.uniq
|
91
|
-
@session.up(*only, detached:true)
|
92
|
-
end
|
88
|
+
@shell.interactive = true
|
89
|
+
end
|
93
90
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
91
|
+
desc 'Launch services (ONLY=a,b,...)'
|
92
|
+
task :up do
|
93
|
+
only = (ENV['ONLY'] || '').split(',').compact.uniq
|
94
|
+
@session.up(*only, detached:true)
|
95
|
+
end
|
98
96
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
desc 'Tail logs of all running services'
|
98
|
+
task :logs do
|
99
|
+
@session.logs
|
100
|
+
end
|
103
101
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
102
|
+
desc 'Stop services'
|
103
|
+
task :stop do
|
104
|
+
@session.stop
|
105
|
+
end
|
106
|
+
|
107
|
+
desc 'Run application on the host, linked to services in containers'
|
108
|
+
task :server => ['docker:compose:up', 'docker:compose:env'] do
|
109
|
+
exec(self.server)
|
108
110
|
end
|
109
111
|
end
|
110
112
|
end
|
@@ -15,7 +15,7 @@ module Docker::Compose
|
|
15
15
|
class Session
|
16
16
|
attr_reader :dir, :file
|
17
17
|
|
18
|
-
def initialize(shell=Backticks::Runner.new,
|
18
|
+
def initialize(shell=Backticks::Runner.new(interactive:true),
|
19
19
|
dir:Dir.pwd, file:'docker-compose.yml')
|
20
20
|
@shell = shell
|
21
21
|
@dir = dir
|
@@ -25,7 +25,7 @@ module Docker::Compose
|
|
25
25
|
# Monitor the logs of one or more containers.
|
26
26
|
# @param [Array] services list of String service names to show logs for
|
27
27
|
# @return [true] always returns true
|
28
|
-
# @raise [
|
28
|
+
# @raise [Error] if command fails
|
29
29
|
def logs(*services)
|
30
30
|
run!('logs', services)
|
31
31
|
true
|
@@ -41,7 +41,7 @@ module Docker::Compose
|
|
41
41
|
# @param [Boolean] no_deps if true, just run specified services without
|
42
42
|
# running the services that they depend on
|
43
43
|
# @return [true] always returns true
|
44
|
-
# @raise [
|
44
|
+
# @raise [Error] if command fails
|
45
45
|
def up(*services,
|
46
46
|
detached:false, timeout:10, no_build:false, no_deps:false)
|
47
47
|
run!('up',
|
@@ -53,6 +53,7 @@ module Docker::Compose
|
|
53
53
|
# Stop running services.
|
54
54
|
# @param [Array] services list of String service names to stop
|
55
55
|
# @param [Integer] timeout how long to wait for each service to stop
|
56
|
+
# @raise [Error] if command fails
|
56
57
|
def stop(*services, timeout:10)
|
57
58
|
run!('stop', {timeout:timeout}, services)
|
58
59
|
end
|
@@ -62,6 +63,7 @@ module Docker::Compose
|
|
62
63
|
# @param [Integer] port number of port
|
63
64
|
# @param [String] protocol 'tcp' or 'udp'
|
64
65
|
# @param [Integer] index of container (if multiple instances running)
|
66
|
+
# @raise [Error] if command fails
|
65
67
|
def port(service, port, protocol:'tcp', index:1)
|
66
68
|
run!('port', {protocol:protocol, index:index}, service, port)
|
67
69
|
end
|
@@ -69,15 +71,15 @@ module Docker::Compose
|
|
69
71
|
# Determine the installed version of docker-compose.
|
70
72
|
# @param [Boolean] short whether to return terse version information
|
71
73
|
# @return [String, Hash] if short==true, returns a version string;
|
72
|
-
# otherwise, returns a Hash of component
|
73
|
-
# @raise [
|
74
|
+
# otherwise, returns a Hash of component-name strings to version strings
|
75
|
+
# @raise [Error] if command fails
|
74
76
|
def version(short:false)
|
75
77
|
result = run!('version', short:short, file:false, dir:false)
|
76
78
|
|
77
79
|
if short
|
78
80
|
result.strip
|
79
81
|
else
|
80
|
-
lines = result.split(
|
82
|
+
lines = result.split(/[\r\n]+/)
|
81
83
|
lines.inject({}) do |h, line|
|
82
84
|
kv = line.split(/: +/, 2)
|
83
85
|
h[kv.first] = kv.last
|
@@ -94,7 +96,7 @@ module Docker::Compose
|
|
94
96
|
# @param [Array] args command-line arguments in the format accepted by
|
95
97
|
# Backticks::Runner#command
|
96
98
|
# @return [String] output of the command
|
97
|
-
# @raise [
|
99
|
+
# @raise [Error] if command fails
|
98
100
|
def run!(*args)
|
99
101
|
project_opts = {
|
100
102
|
file: @file
|
@@ -102,7 +104,7 @@ module Docker::Compose
|
|
102
104
|
|
103
105
|
Dir.chdir(@dir) do
|
104
106
|
cmd = @shell.command('docker-compose', project_opts, *args).join
|
105
|
-
status, out, err= cmd.status, cmd.captured_output, cmd.captured_error
|
107
|
+
status, out, err = cmd.status, cmd.captured_output, cmd.captured_error
|
106
108
|
status.success? || raise(Error.new(args.first, status, err))
|
107
109
|
out
|
108
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Spataro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backticks
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|