docker-compose 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5307fb75ebdc1b6f79b326c6d31ff1ba3e08e1d
4
- data.tar.gz: 5df6cd398d2238151ad063545ba94a5f3a4d32f5
3
+ metadata.gz: d0fd6f058df23b81e91fb41201f8e8f6c0b46a1f
4
+ data.tar.gz: 2b4fa470ffa68b8ede08591129e0135d548effe8
5
5
  SHA512:
6
- metadata.gz: 0a17412a0364656f01e2ff5efe203d5a961f156ad09c699155e11255560d6c0fd2d600c5cbbb08fb5fdde688e71939940dbefcee0aaad472af7a99a7331da8e6
7
- data.tar.gz: d7a046c4c39b75fe2fb5a3b69264324debc58571f5a72d090b54896c03ca40ce80017c27b15eb636bc3dae6f3f71f79c176ba201b4084c5651202e3a3304f589
6
+ metadata.gz: 708ea8165969cf7b7e6b91b8707ff4b89ba1af98101a6d7bfb43e8d3f6dbbf85607159e1b20f29a4af9615ea90409292d0df830c7915b4de2dbfd011ce69eb47
7
+ data.tar.gz: 17793d4f5899fbc76c238965f5990609b12cad7fb5a7866d6ac8c8d402dd43c61cc245642f3eb39b5894634450b0156c388fc131075a1fbc3354d9cdcd813153
data/README.md CHANGED
@@ -1,18 +1,16 @@
1
1
  # Docker::Compose
2
2
 
3
3
  This is a Ruby OOP wrapper for the [docker-compose](https://github.com/docker/compose)
4
- container orchestration tool from Docker Inc. It also contains some features that
5
- layer nicely on top of docker-compose to enhance your productivity.
4
+ container orchestration tool from Docker Inc.
6
5
 
7
- Distinctive features of this gem:
8
-
9
- 1) Simulates environment-variable substitution in the style of docker-compose
10
- 1.5; sequences such as ${FOO} in your YML will be replaced with the
11
- corresponding environment variable. (This feature will go away once 1.5
12
- is released.)
13
-
14
- 2) Environment-variable mapping that allows you to export environment variables
15
- into your _host_ that point to network services published by containers.
6
+ In addition to wrapping the CLI, this gem provides an environment-variable mapping
7
+ featurie that allows you to export environment variables into your _host_ that point
8
+ to network services exposed by containers. This allows you to run an application on
9
+ your host for quicker and easier development, but run all of its architectural
10
+ dependencies -- database, cache, adjacent microservices -- in containers. The
11
+ dependencies can even be running on another machine, e.g. a cloud instance or a
12
+ container cluster, provided your development machine has TCP connectivity on every
13
+ port exposed by a container.
16
14
 
17
15
  Throughout this documentation we will refer to this gem as `Docker::Compose`
18
16
  as opposed to the `docker-compose` tool that this gem wraps.
@@ -40,8 +38,8 @@ Or install it yourself as:
40
38
  ```ruby
41
39
  require 'docker/compose'
42
40
 
43
- # Create a new session in Dir.pwd using the file "docker-compose.yml"
44
- # for fine-grained control over options, see Docker::Compose::Session#new
41
+ # Create a new session in Dir.pwd using the file "docker-compose.yml".
42
+ # For fine-grained control over options, see Docker::Compose::Session#new
45
43
  compose = Docker::Compose.new
46
44
 
47
45
  compose.version
@@ -59,11 +59,41 @@ module Docker::Compose
59
59
  # @example map just the port of MySQL on local docker host
60
60
  # map("[db]:3306") # => "13847"
61
61
  #
62
- # @param [String] value a URI or a host:port pair
62
+ # @example map an array of database hosts
63
+ # map(["[db1]:3306", "[db2]:3306"])
64
+ #
65
+ # @param [String,#map] value a URI, host:port pair, or an array of either
66
+ #
67
+ # @return [String,Array] the mapped value with container-names and ports substituted
63
68
  #
64
69
  # @raise [BadSubstitution] if a substitution string can't be parsed
65
70
  # @raise [NoService] if service is not up or does not publish port
66
71
  def map(value)
72
+ if value.respond_to?(:map)
73
+ value.map { |e| map_scalar(e) }
74
+ else
75
+ map_scalar(value)
76
+ end
77
+ end
78
+
79
+ # Figure out which host port a given service's port has been published to,
80
+ # and/or whether that service is running. Cannot distinguish between the
81
+ # "service not running" case and the "container port not published" case!
82
+ #
83
+ # @raise [NoService] if service is not up or does not publish port
84
+ # @return [Integer] host port number, or nil if port not published
85
+ def published_port(service, port)
86
+ result = @session.port(service, port)
87
+ Integer(result.split(':').last.gsub("\n", ""))
88
+ rescue RuntimeError
89
+ raise NoService, "Service '#{service}' not running, or does not publish port '#{port}'"
90
+ end
91
+
92
+ # Map a single string, replacing service names with IPs and container ports
93
+ # with the host ports that they have been mapped to.
94
+ # @param [String] value
95
+ # @return [String]
96
+ private def map_scalar(value)
67
97
  uri = URI.parse(value) rescue nil
68
98
  pair = value.split(':')
69
99
 
@@ -97,18 +127,5 @@ module Docker::Compose
97
127
  return value
98
128
  end
99
129
  end
100
-
101
- # Figure out which host port a given service's port has been published to,
102
- # and/or whether that service is running. Cannot distinguish between the
103
- # "service not running" case and the "container port not published" case!
104
- #
105
- # @raise [NoService] if service is not up or does not publish port
106
- # @return [Integer] host port number, or nil if port not published
107
- def published_port(service, port)
108
- result = @session.port(service, port)
109
- Integer(result.split(':').last.gsub("\n", ""))
110
- rescue RuntimeError
111
- raise NoService, "Service '#{service}' not running, or does not publish port '#{port}'"
112
- end
113
130
  end
114
131
  end
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'rake/tasklib'
2
3
 
3
4
  # In case this file is required directly
@@ -115,7 +116,7 @@ module Docker::Compose
115
116
  Docker::Compose::Mapper.map(self.server_env,
116
117
  session:@session,
117
118
  net_info:@net_info) do |k, v|
118
- ENV[k] = v
119
+ ENV[k] = serialize_for_env(v)
119
120
  print_env(k, v) if print
120
121
  end
121
122
 
@@ -123,11 +124,25 @@ module Docker::Compose
123
124
  strict:false,
124
125
  session:@session,
125
126
  net_info:@net_info) do |k, v|
126
- ENV[k] = v
127
+ ENV[k] = serialize_for_env(v)
127
128
  print_env(k, v) if print
128
129
  end
129
130
  end
130
131
 
132
+ # Transform a Ruby value into a String that can be stored in the
133
+ # environment. This accepts nil, String, or Array and returns nil, String
134
+ # or JSON-serialized Array.
135
+ private def serialize_for_env(v)
136
+ case v
137
+ when String, NilClass
138
+ v
139
+ when Array
140
+ JSON.dump(v)
141
+ else
142
+ raise ArgumentError, "Can't represent a #{v.class} in the environment"
143
+ end
144
+ end
145
+
131
146
  # Print a bash export or unset statement
132
147
  private def print_env(k, v)
133
148
  if v
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Compose
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Spataro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler