ecs_compose 0.1.0.pre9 → 0.1.0.pre10

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: 97bee1ba4d301b7508fda9f624e739a4ba411929
4
- data.tar.gz: 104f5b9e4f4ea8c0da05b8b530157b49826d4e9c
3
+ metadata.gz: f3cd0b018b8b9b888c1122557c0a161334766b53
4
+ data.tar.gz: 16060721d639f8d4476873f03b41a34a18f68648
5
5
  SHA512:
6
- metadata.gz: 5e2a62625471bebdfb4ebde7811543b5086ede67c28e6e5c0563420f9d353f155f71271503f95f4ce2b188361cd5246f1a50c692f84fd0f893749542445a4dea
7
- data.tar.gz: 1a76b2dbdb523e95bff256958e25f476c20796b401951898bfeecba912f9888dba71507d4760662724981fc9b432d6adfbfcd53d688e957da0d0b10bd0f16c57
6
+ metadata.gz: b64b87966680476d655a08de539f3f7d9ff1e6bdb043bdca0e98fff3c8becbe3162c656818385da9e62a7970146c2e55b97e234995b683350b9894628e1974be
7
+ data.tar.gz: 089581fab759d2710fd2e74d913fec10dcdf1a6a0e8ca6fb182f019d8ceece2637f4929a01bbfafae6b73a81fdc1e8874b1047804d4c74136ce9a663fc800b20
data/exe/ecs-compose CHANGED
@@ -11,7 +11,7 @@ Usage:
11
11
  ecs-compose --version
12
12
  ecs-compose [options] register [<task_def>...]
13
13
  ecs-compose [options] up [<service>...]
14
- ecs-compose [options] run [-e <name>=<value>]... [--entrypoint <entrypoint>] <task> [--] [<arg>...]
14
+ ecs-compose [options] run [-e <name>=<value>]... [--entrypoint <entrypoint>] <task> [-- [<arg>...]]
15
15
  ecs-compose [options] json [<task_def>]
16
16
 
17
17
  Options:
@@ -27,7 +27,8 @@ Options:
27
27
  docker-compose.yml file
28
28
  -e <name>=<value> Set an environment variable
29
29
  --entrypoint <entrypoint>
30
- Override the container's regular entrypoint
30
+ Override the container's regular entrypoint (NOT CURRENTLY
31
+ SUPPORTED BY ECS)
31
32
 
32
33
  Commands:
33
34
  register Registers the specified ECS task definitions (defaults to all)
@@ -72,7 +73,7 @@ class App
72
73
  def command_register
73
74
  available = manifest.task_definitions
74
75
  chosen = all_or_specified(available, options.fetch('<task_def>'))
75
- chosen.each {|td| td.register }
76
+ chosen.each {|td| puts(td.register) }
76
77
  end
77
78
 
78
79
  def command_up
@@ -82,6 +83,12 @@ class App
82
83
  end
83
84
 
84
85
  def command_run
86
+ # Work around docopt lossage.
87
+ dashes = options.fetch('--')
88
+ if dashes && dashes != '--'
89
+ fatal_err "The '--' option to run is mandatory for now"
90
+ end
91
+
85
92
  available = manifest.task_definitions.select {|td| td.type == :task }
86
93
  task_name = options.fetch('<task>')
87
94
  task = available.find {|td| td.name == task_name } or
@@ -47,5 +47,15 @@ module EcsCompose
47
47
  "--service", service,
48
48
  "--task-definition", task_definition)
49
49
  end
50
+
51
+ # Run a one-off task. Sample args: `"migrator:1"`. The overrides may
52
+ # be specified in the JSON format used by `aws ecs run-task`.
53
+ def self.run_task(task_definition, overrides_json: nil)
54
+ extra_args = []
55
+ extra_args.concat(["--overrides", overrides_json]) if overrides_json
56
+ run("run-task",
57
+ "--task-definition", task_definition,
58
+ *extra_args)
59
+ end
50
60
  end
51
61
  end
@@ -86,6 +86,42 @@ module EcsCompose
86
86
  JSON.generate(generate())
87
87
  end
88
88
 
89
+ # Generate an `--overrides` value for use with with `aws ecs run-task`
90
+ # as a raw Ruby hash.
91
+ def generate_override(environment: {}, entrypoint: nil, command: nil)
92
+ # Right now, we only support overriding for single-container tasks, so
93
+ # find our single container if we have it.
94
+ if @yaml.length != 1
95
+ raise "Can only override task attributes for single-container tasks"
96
+ end
97
+ name = @yaml.keys.first
98
+ container_overrides = { "name" => name }
99
+
100
+ # Apply any environment overrides.
101
+ if environment && !environment.empty?
102
+ container_overrides["environment"] = environment.map do |k, v|
103
+ { "name" => k, "value" => v }
104
+ end
105
+ end
106
+
107
+ # Apply any other overrides.
108
+ container_overrides["command"] = command if command
109
+ # TODO: This may not actually be supported by AWS yet.
110
+ container_overrides["entryPoint"] = entrypoint if entrypoint
111
+
112
+ # Return nil if we haven't generated any actual overrides.
113
+ if container_overrides.length > 1
114
+ { "containerOverrides" => [ container_overrides ] }
115
+ else
116
+ nil
117
+ end
118
+ end
119
+
120
+ # Like generate, but return serialized JSON.
121
+ def generate_override_json(**args)
122
+ JSON.generate(generate_override(**args))
123
+ end
124
+
89
125
  protected
90
126
 
91
127
  # Parse a Docker-style `mem_limit` and convert to megabytes.
@@ -18,25 +18,25 @@ module EcsCompose
18
18
 
19
19
  # Register this task definition with ECS. Will create the task
20
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.
21
23
  def register
22
- EcsCompose::Ecs.register_task_definition(to_json)
24
+ reg = EcsCompose::Ecs.register_task_definition(to_json)
25
+ .fetch("taskDefinition")
26
+ "#{reg.fetch('family')}:#{reg.fetch('revision')}"
23
27
  end
24
28
 
25
29
  # Register this task definition with ECS, and update the corresponding
26
30
  # service.
27
31
  def update
28
- reg = register["taskDefinition"]
29
- task_def = "#{reg.fetch('family')}:#{reg.fetch('revision')}"
30
- EcsCompose::Ecs.update_service(name, task_def)
32
+ EcsCompose::Ecs.update_service(name, register)
31
33
  end
32
34
 
33
35
  # Run this task definition as a one-shot ECS task, with the specified
34
36
  # overrides.
35
- def run(environment: {}, entrypoint: nil, command: nil)
36
- puts "environment: #{environment.inspect}"
37
- puts "entrypoint: #{entrypoint.inspect}"
38
- puts "command: #{command.inspect}"
39
- raise "Not yet implemented"
37
+ def run(**args)
38
+ overrides_json = json_generator.generate_override_json(**args)
39
+ EcsCompose::Ecs.run_task(register, overrides_json: overrides_json)
40
40
  end
41
41
 
42
42
  # Generate ECS task definition JSON for this instance.
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.pre9
4
+ version: 0.1.0.pre10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kidd