ecs_compose 0.1.0.pre6 → 0.1.0.pre7

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: dda22daa866666c5439a1ecfebba1cdf3b6e9a18
4
- data.tar.gz: 78c9d8d6272f972507ae05e2840e1b5fb1bca14a
3
+ metadata.gz: 0ae0188dc62e80cc71af5875294462deda6c5edd
4
+ data.tar.gz: 8e6f777891d855a5199eb117370be12596a4fb5a
5
5
  SHA512:
6
- metadata.gz: 2143cdc284706c09f0617679c3eed643e8717149ad58fd67abcc50de42cc63972e7e9818d0be1e640e4dcc9cd46f9e1045af1a569ce2c556b00a9e871c4d442f
7
- data.tar.gz: 26b764aa62f737096c8962cc74adfada14d9787339096a375e6b6b7c51736aaaf95e28704f7e08adfc296486085e3372ffc2f29c1a64b463df6037f3e24bd972
6
+ metadata.gz: e14d979474af2e9a368b1a6973fff7b0571480c55da159fad7bdee7fc0b4cf311f8a720e8dfea12196c4a5c553ddf39804d08f503270997aaacce325c117fb59
7
+ data.tar.gz: e880db7381c14d238fd36c12d86f42704c552e540fab0088b018375bfd1d5bcf745d1842fb590bd7bd08081a58bfa4ee5eb60a54603b294f855dd8bf334bbedd
@@ -1,5 +1,6 @@
1
- require 'psych'
1
+ require 'digest/sha1'
2
2
  require 'json'
3
+ require 'psych'
3
4
 
4
5
  module EcsCompose
5
6
  class ContainerKeyError < KeyError
@@ -18,10 +19,20 @@ module EcsCompose
18
19
 
19
20
  # Generate an ECS task definition as a raw Ruby hash.
20
21
  def generate
22
+ # Generate JSON for our containers.
21
23
  containers = @yaml.map do |name, fields|
22
24
  # Skip this service if we've been given a list to emit, and
23
25
  # this service isn't on the list.
24
26
  begin
27
+ mount_points = (fields["volumes"] || []).map do |v|
28
+ host, container, ro = v.split(':')
29
+ {
30
+ "sourceVolume" => path_to_vol_name(host),
31
+ "containerPath" => container,
32
+ "readOnly" => (ro == "ro")
33
+ }
34
+ end
35
+
25
36
  json = {
26
37
  "name" => name,
27
38
  "image" => fields.fetch("image"),
@@ -33,7 +44,7 @@ module EcsCompose
33
44
  (fields["ports"] || []).map {|pm| port_mapping(pm) },
34
45
  "essential" => true,
35
46
  "environment" => environment(fields["environment"] || {}),
36
- "mountPoints" => [],
47
+ "mountPoints" => mount_points,
37
48
  "volumesFrom" => [],
38
49
  }
39
50
  if fields.has_key?("entrypoint")
@@ -50,10 +61,21 @@ module EcsCompose
50
61
  end
51
62
  end
52
63
 
64
+ # Generate our top-level volume declarations.
65
+ volumes = @yaml.map do |name, fields|
66
+ (fields["volumes"] || []).map {|v| v.split(':')[0] }
67
+ end.flatten.sort.uniq.map do |host_path|
68
+ {
69
+ "name" => path_to_vol_name(host_path),
70
+ "host" => { "sourcePath" => host_path }
71
+ }
72
+ end
73
+
74
+ # Return our final JSON.
53
75
  {
54
76
  "family" => @family,
55
77
  "containerDefinitions" => containers,
56
- "volumes" => []
78
+ "volumes" => volumes
57
79
  }
58
80
  end
59
81
 
@@ -108,5 +130,14 @@ module EcsCompose
108
130
  # We need to force string values to keep ECS happy.
109
131
  env.map {|k, v| { "name" => k, "value" => v.to_s } }
110
132
  end
133
+
134
+ # Convert a Unix path into a valid volume name.
135
+ def path_to_vol_name(path)
136
+ # Ensure (extremely high probability of) uniqueness by hashing the
137
+ # pathname, and then include a simplified version of the path for
138
+ # readability. This might fail, but the odds are the same as a
139
+ # failure of git's content-based addressing.
140
+ Digest::SHA1.hexdigest(path) + path.gsub(/[\/.]/, '_')
141
+ end
111
142
  end
112
143
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre6
4
+ version: 0.1.0.pre7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kidd
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-06 00:00:00.000000000 Z
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor