ecs_compose 0.1.0.pre22 → 0.1.0.pre23

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: 80275b619f65f41b6ee381a7de76901d691c78c5
4
- data.tar.gz: 3488a74fe16c5a9bb737c805463b013dc4e74fbb
3
+ metadata.gz: 44652fed3e1b8e9b49392f9d042291e8cbc9ed67
4
+ data.tar.gz: 017482c7d7f0937820b20e243562de13e4a742be
5
5
  SHA512:
6
- metadata.gz: bd401ef52fde780548729ea6c8b20f2777b38739b89487953253372924cf39315ac0f0fc88639a80a31a5c95547f319ac7cf1cff6b43b637c5e817bc6e517c6a
7
- data.tar.gz: 6d6723fb23c8192f480c1f7e224987196d22faf73c16b354876221c87ad10bbf3eb2e02e5a9adc6320cce242ae96a6c8f8ba9d6d3efaac7e8f981ed169dd97c7
6
+ metadata.gz: 38cf507deb32f24f41bde413dde811af98dac5e82bd58cb8b955d4483f65ec9da18399ae7cad0823c5c12e033cd9a2c91f1ded5d5268ed4eb1f3cc4fde6d70c2
7
+ data.tar.gz: 48962ba33465cecbd19e8bb01bc1c767c202b3a51da743296751eb15b74cdf9a684534f753699f4c915f4c7805143551da18620e52fb1c8a0103d4ffbfa05a41
@@ -0,0 +1,44 @@
1
+ module EcsCompose
2
+ # Utilities for comparing ECS task definition JSON, which we need to do
3
+ # to determine whether or not a running service needs to be deployed.
4
+ module Compare
5
+
6
+ # Recursively sort all arrays contained in `val`, in order to normalize
7
+ # things like environment variables in different orders.
8
+ def self.sort_recursively(val)
9
+ case val
10
+ when Array
11
+ val.sort_by do |item|
12
+ if item.instance_of?(Hash)
13
+ item.to_a.sort
14
+ else
15
+ item
16
+ end
17
+ end.map {|item| sort_recursively(item) }
18
+ when Hash
19
+ newval = {}
20
+ val.each do |k, v|
21
+ newval[k] = sort_recursively(v)
22
+ end
23
+ newval
24
+ else
25
+ val
26
+ end
27
+ end
28
+
29
+ # Do two task definitions match after normalization?
30
+ def self.task_definitions_match?(td1, td2)
31
+ normalize_task_definition(td1) == normalize_task_definition(td2)
32
+ end
33
+
34
+ protected
35
+
36
+ # Sort and strip out things we expect to change.
37
+ def self.normalize_task_definition(td)
38
+ td = sort_recursively(td)
39
+ td.delete("taskDefinitionArn")
40
+ td.delete("revision")
41
+ td
42
+ end
43
+ end
44
+ end
@@ -45,6 +45,12 @@ module EcsCompose
45
45
  end
46
46
  end
47
47
 
48
+ # Export the JSON describing an existing task.
49
+ def self.describe_task_definition(name)
50
+ run('describe-task-definition',
51
+ '--task-definition', name)
52
+ end
53
+
48
54
  # Update the specified service. Sample args: `"frontend"`,
49
55
  # `"frontend:7"`.
50
56
  def self.update_service(cluster, service, task_definition)
@@ -16,14 +16,21 @@ module EcsCompose
16
16
  @yaml = yaml
17
17
  end
18
18
 
19
- # Register this task definition with ECS. Will create the task
20
- # definition if it doesn't exist, and add a new version of the task.
21
- # Returns a string of the form `"name:revision"` identifying the task
22
- # we registered.
19
+ # Register this task definition with ECS if it isn't already
20
+ # registered. Will create the task definition if it doesn't exist, and
21
+ # add a new version of the task. Returns a string of the form
22
+ # `"name:revision"` identifying the task we registered, or an existing
23
+ # task with the same properties.
23
24
  def register
24
- reg = Ecs.register_task_definition(to_json)
25
- .fetch("taskDefinition")
26
- "#{reg.fetch('family')}:#{reg.fetch('revision')}"
25
+ existing = Ecs.describe_task_definition(@name).fetch("taskDefinition")
26
+ new = register_new.fetch("taskDefinition")
27
+ use =
28
+ if Compare.task_definitions_match?(existing, new)
29
+ existing
30
+ else
31
+ new
32
+ end
33
+ "#{use.fetch('family')}:#{use.fetch('revision')}"
27
34
  end
28
35
 
29
36
  # Register this task definition with ECS, and update the corresponding
@@ -73,6 +80,11 @@ module EcsCompose
73
80
 
74
81
  protected
75
82
 
83
+ # Always register a task. Called by our public `register` API.
84
+ def register_new
85
+ Ecs.register_task_definition(to_json)
86
+ end
87
+
76
88
  # Return a JSON generator for this task.
77
89
  def json_generator
78
90
  @json_generator ||= JsonGenerator.new(name, yaml)
data/lib/ecs_compose.rb CHANGED
@@ -7,6 +7,7 @@ require "ecs_compose/task_error"
7
7
  require "ecs_compose/cluster"
8
8
  require "ecs_compose/task_definition"
9
9
  require "ecs_compose/manifest"
10
+ require "ecs_compose/compare"
10
11
 
11
12
  module EcsCompose
12
13
  # Your code goes here...
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.pre22
4
+ version: 0.1.0.pre23
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-10-23 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -105,6 +105,7 @@ files:
105
105
  - go-publish.sh
106
106
  - lib/ecs_compose.rb
107
107
  - lib/ecs_compose/cluster.rb
108
+ - lib/ecs_compose/compare.rb
108
109
  - lib/ecs_compose/deployment_error.rb
109
110
  - lib/ecs_compose/ecs.rb
110
111
  - lib/ecs_compose/json_generator.rb