ecs_compose 0.1.0.pre10 → 0.1.0.pre11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/ecs-compose +3 -0
- data/lib/ecs_compose/ecs.rb +16 -2
- data/lib/ecs_compose/json_generator.rb +3 -1
- data/lib/ecs_compose/task_definition.rb +10 -4
- data/lib/ecs_compose/task_error.rb +45 -0
- data/lib/ecs_compose.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d921f9b7cfc815df0f612407f5c4b6a5eb36a242
|
4
|
+
data.tar.gz: 517f89b2d4b32570307fb789370270b24a211882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850739a8d7a033f072c3b8a764a967d428cc28d7402ac69fc002d57e57bb5414cb260945c655023388fa96a5f2b11a75aa3243f99607716db4c7944bc626490f
|
7
|
+
data.tar.gz: 90a241bc97e878262a503e6310ff30fc8a4bf2b31bb15c05c9f1ee5e690250386b95ad2b4750ae8d7704ea3ff5ce100e6c6ce5180fe534253cf30521aa3dc775
|
data/exe/ecs-compose
CHANGED
data/lib/ecs_compose/ecs.rb
CHANGED
@@ -18,12 +18,16 @@ module EcsCompose
|
|
18
18
|
# Run `aws ecs` with the specified arguments.
|
19
19
|
def self.run(*args)
|
20
20
|
command = ["aws", "ecs"] + args + ["--output", "json"]
|
21
|
-
puts "→ #{command.join(' ').blue}"
|
21
|
+
STDERR.puts "→ #{command.join(' ').blue}"
|
22
22
|
stdout, status = Open3.capture2(*command)
|
23
23
|
if status != 0
|
24
24
|
raise "Error running: #{command.inspect}"
|
25
25
|
end
|
26
|
-
|
26
|
+
if stdout.empty?
|
27
|
+
nil
|
28
|
+
else
|
29
|
+
JSON.parse(stdout)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
# Register the specified task definition (passed as JSON data).
|
@@ -57,5 +61,15 @@ module EcsCompose
|
|
57
61
|
"--task-definition", task_definition,
|
58
62
|
*extra_args)
|
59
63
|
end
|
64
|
+
|
65
|
+
def self.wait_tasks_stopped(*arns)
|
66
|
+
run("wait", "tasks-stopped",
|
67
|
+
"--tasks", arns.join(" "))
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.describe_tasks(*arns)
|
71
|
+
run("describe-tasks",
|
72
|
+
"--tasks", arns.join(" "))
|
73
|
+
end
|
60
74
|
end
|
61
75
|
end
|
@@ -36,7 +36,9 @@ module EcsCompose
|
|
36
36
|
json = {
|
37
37
|
"name" => name,
|
38
38
|
"image" => fields.fetch("image"),
|
39
|
-
# Default to a tiny guaranteed CPU share.
|
39
|
+
# Default to a tiny guaranteed CPU share. Currently, 2 is the
|
40
|
+
# smallest meaningful value, and various ECS tools will round
|
41
|
+
# smaller numbers up.
|
40
42
|
"cpu" => fields["cpu_shares"] || 2,
|
41
43
|
"memory" => mem_limit_to_mb(fields.fetch("mem_limit")),
|
42
44
|
"links" => fields["links"] || [],
|
@@ -21,7 +21,7 @@ module EcsCompose
|
|
21
21
|
# Returns a string of the form `"name:revision"` identifying the task
|
22
22
|
# we registered.
|
23
23
|
def register
|
24
|
-
reg =
|
24
|
+
reg = Ecs.register_task_definition(to_json)
|
25
25
|
.fetch("taskDefinition")
|
26
26
|
"#{reg.fetch('family')}:#{reg.fetch('revision')}"
|
27
27
|
end
|
@@ -29,14 +29,20 @@ module EcsCompose
|
|
29
29
|
# Register this task definition with ECS, and update the corresponding
|
30
30
|
# service.
|
31
31
|
def update
|
32
|
-
|
32
|
+
Ecs.update_service(name, register)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Run this task definition as a one-shot ECS task, with the specified
|
36
36
|
# overrides.
|
37
37
|
def run(**args)
|
38
38
|
overrides_json = json_generator.generate_override_json(**args)
|
39
|
-
|
39
|
+
info = Ecs.run_task(register, overrides_json: overrides_json)
|
40
|
+
arn = info.fetch("tasks")[0].fetch("taskArn")
|
41
|
+
#STDERR.puts("Running as: #{arn}")
|
42
|
+
|
43
|
+
# Wait until the task has finished running and check for errors.
|
44
|
+
Ecs.wait_tasks_stopped(arn)
|
45
|
+
TaskError.fail_on_errors(Ecs.describe_tasks(arn))
|
40
46
|
end
|
41
47
|
|
42
48
|
# Generate ECS task definition JSON for this instance.
|
@@ -48,7 +54,7 @@ module EcsCompose
|
|
48
54
|
|
49
55
|
# Return a JSON generator for this task.
|
50
56
|
def json_generator
|
51
|
-
@json_generator ||=
|
57
|
+
@json_generator ||= JsonGenerator.new(name, yaml)
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EcsCompose
|
2
|
+
# We raise this error if `aws ecs describe-tasks` indicates that a
|
3
|
+
# process has failed.
|
4
|
+
class TaskError < RuntimeError
|
5
|
+
def self.fail_on_errors(task_descriptions)
|
6
|
+
errs1 = task_descriptions.fetch("failures").map {|f| failure_error(f) }
|
7
|
+
errs2 = task_descriptions.fetch("tasks").map do |task|
|
8
|
+
task.fetch("containers").map do |container|
|
9
|
+
container_error(container)
|
10
|
+
end
|
11
|
+
end.flatten.compact
|
12
|
+
errs = errs1 + errs2
|
13
|
+
unless errs.empty?
|
14
|
+
raise new(errs)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#:nodoc:
|
19
|
+
def self.container_error(container)
|
20
|
+
exit_code = container.fetch("exitCode")
|
21
|
+
name = container.fetch("name")
|
22
|
+
if exit_code == 0
|
23
|
+
nil
|
24
|
+
elsif container.has_key?("reason")
|
25
|
+
"#{name}: #{container.fetch("reason")}"
|
26
|
+
else
|
27
|
+
"#{name}: exited with code #{exit_code}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#:nodoc:
|
32
|
+
def self.failure_error(failure)
|
33
|
+
"#{failure.fetch("reason")} (resource: #{failure.fetch("arn")})"
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :messages
|
37
|
+
|
38
|
+
# Create a new task error with one or more messages.
|
39
|
+
def initialize(messages)
|
40
|
+
message = (["Errors running tasks:"] + messages).join("\n- ")
|
41
|
+
super(message)
|
42
|
+
@messages = messages
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/ecs_compose.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.pre11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Kidd
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/ecs_compose/json_generator.rb
|
109
109
|
- lib/ecs_compose/manifest.rb
|
110
110
|
- lib/ecs_compose/task_definition.rb
|
111
|
+
- lib/ecs_compose/task_error.rb
|
111
112
|
- lib/ecs_compose/version.rb
|
112
113
|
- publish.sh
|
113
114
|
homepage: https://github.com/faradayio/ecs_compose
|