ecs_compose 0.1.0.pre22 → 0.1.0.pre23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ecs_compose/compare.rb +44 -0
- data/lib/ecs_compose/ecs.rb +6 -0
- data/lib/ecs_compose/task_definition.rb +19 -7
- data/lib/ecs_compose.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44652fed3e1b8e9b49392f9d042291e8cbc9ed67
|
4
|
+
data.tar.gz: 017482c7d7f0937820b20e243562de13e4a742be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/ecs_compose/ecs.rb
CHANGED
@@ -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
|
20
|
-
# definition if it doesn't exist, and
|
21
|
-
#
|
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
|
-
|
25
|
-
|
26
|
-
|
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
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.
|
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-
|
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
|