ecs_compose 0.1.0.pre14 → 0.1.0.pre15

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: 258ad2a5c72320cfcddc857c2ef3bb65b514191b
4
- data.tar.gz: ddde11787a6c3b444715af2f5139c2e27a00e631
3
+ metadata.gz: 3dc8bf5ed177981cdbfc662042cd9e67a5e2c9b1
4
+ data.tar.gz: 8d297607c1bdb1fc442832e1c64c8bf896cc053a
5
5
  SHA512:
6
- metadata.gz: ddf8db17be5df23a2afa7cd5b968efbc8cdcada1e7321f3d345c528509e431ce06cca31fd140c0b2ff7cd3edacc5b4bf6b8e255a13d83b4dbc8902a100e27b7c
7
- data.tar.gz: aa1d015f363ed9590c42b75decd8d479b25cd22eb8d5379bd62b5cdc2dfc9c43328e501445ba78f407d4e0daf2457613509c5deba635772bdfd290444afdb61e
6
+ metadata.gz: d7b7e7285cd236537a5869df7274b55f964ab16eb753b087dd58a6b00a871c2212bbf324e143830a42f587f03262a8a612727ab745af060515392cf7277566f0
7
+ data.tar.gz: ee6b648d01d48a55cb93cf7a2f2574510c33ad97acb5d13b993aeb02312643c5537ca45840e14ace98c5c2b5a15bea279c1ddd88baee5c09de59a3d99a9d01e3
data/exe/ecs-compose CHANGED
@@ -26,6 +26,7 @@ Options:
26
26
  -i, --file-info (task:<name> | service:<name>)
27
27
  Specify the task type and task name for a
28
28
  docker-compose.yml file
29
+ --cluster <cluster> ECS cluster to use [default: default]
29
30
  -e <name>=<value> Set an environment variable
30
31
  --entrypoint <entrypoint>
31
32
  Override the container's regular entrypoint (NOT CURRENTLY
@@ -47,10 +48,12 @@ class App
47
48
  DEFAULT_FILE = "docker-compose.yml"
48
49
  DEFAULT_MANIFEST = "deploy/DEPLOY-MANIFEST.yml"
49
50
 
50
- attr_reader :options, :manifest
51
+ attr_reader :options, :cluster, :manifest
51
52
 
52
53
  def initialize
53
54
  @options = Docopt::docopt(USAGE, version: EcsCompose::VERSION)
55
+ # Docopt.rb does not actually support [default: ...] correctly!
56
+ @cluster = EcsCompose::Cluster.new(options.fetch('--cluster') || "default")
54
57
  @manifest = load_manifest()
55
58
 
56
59
  # Uncomment to dump the docopt parser output, which can be non-obvious.
@@ -81,8 +84,8 @@ class App
81
84
  def command_up
82
85
  available = manifest.task_definitions.select {|td| td.type == :service }
83
86
  chosen = all_or_specified(available, options.fetch('<service>'))
84
- services = chosen.map {|td| td.update }
85
- EcsCompose::TaskDefinition.wait_for_services(services)
87
+ services = chosen.map {|td| td.update(cluster) }
88
+ EcsCompose::TaskDefinition.wait_for_services(cluster, services)
86
89
  end
87
90
 
88
91
  def command_run
@@ -107,10 +110,11 @@ class App
107
110
  command = options.fetch('<arg>')
108
111
  command = nil if command.empty?
109
112
 
110
- arn = task.run(environment: env,
113
+ arn = task.run(cluster,
114
+ environment: env,
111
115
  entrypoint: options.fetch('--entrypoint').flatten[0],
112
116
  command: command)
113
- EcsCompose::TaskDefinition.wait_for_tasks([arn])
117
+ EcsCompose::TaskDefinition.wait_for_tasks(cluster, [arn])
114
118
  end
115
119
 
116
120
  def command_scale
@@ -132,9 +136,9 @@ class App
132
136
  service_names = scales.map do |name, count|
133
137
  service = available.find {|td| td.name == name } or
134
138
  raise "Unknown service: #{name}"
135
- service.scale(count)
139
+ service.scale(cluster, count)
136
140
  end
137
- EcsCompose::TaskDefinition.wait_for_services(service_names)
141
+ EcsCompose::TaskDefinition.wait_for_services(cluster, service_names)
138
142
  end
139
143
 
140
144
  def command_json
@@ -0,0 +1,9 @@
1
+ module EcsCompose
2
+ class Cluster
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+ end
9
+ end
@@ -47,51 +47,58 @@ module EcsCompose
47
47
 
48
48
  # Update the specified service. Sample args: `"frontend"`,
49
49
  # `"frontend:7"`.
50
- def self.update_service(service, task_definition)
50
+ def self.update_service(cluster, service, task_definition)
51
51
  run("update-service",
52
+ "--cluster", cluster,
52
53
  "--service", service,
53
54
  "--task-definition", task_definition)
54
55
  end
55
56
 
56
57
  # Update the specified service. Sample args: `"frontend"`, `3`.
57
- def self.update_service_desired_count(service, desired_count)
58
+ def self.update_service_desired_count(cluster, service, desired_count)
58
59
  run("update-service",
60
+ "--cluster", cluster,
59
61
  "--service", service,
60
62
  "--desired-count", desired_count.to_s)
61
63
  end
62
64
 
63
65
  # Run a one-off task. Sample args: `"migrator:1"`. The overrides may
64
66
  # be specified in the JSON format used by `aws ecs run-task`.
65
- def self.run_task(task_definition, overrides_json: nil)
67
+ def self.run_task(cluster, task_definition, overrides_json: nil)
66
68
  extra_args = []
67
69
  extra_args.concat(["--overrides", overrides_json]) if overrides_json
68
70
  run("run-task",
71
+ "--cluster", cluster,
69
72
  "--task-definition", task_definition,
70
73
  *extra_args)
71
74
  end
72
75
 
73
76
  # Wait until all of the specified services have reached a stable state.
74
77
  # Returns nil.
75
- def self.wait_services_stable(services)
78
+ def self.wait_services_stable(cluster, services)
76
79
  run("wait", "services-stable",
80
+ "--cluster", cluster,
77
81
  "--services", *services)
78
82
  end
79
83
 
80
84
  # Wait until all of the specified tasks have stopped. Returns nil.
81
- def self.wait_tasks_stopped(arns)
85
+ def self.wait_tasks_stopped(cluster, arns)
82
86
  run("wait", "tasks-stopped",
87
+ "--cluster", cluster,
83
88
  "--tasks", *arns)
84
89
  end
85
90
 
86
91
  # Describe a set of services as JSON.
87
- def self.describe_services(services)
92
+ def self.describe_services(cluster, services)
88
93
  run("describe-services",
94
+ "--cluster", cluster,
89
95
  "--services", *services)
90
96
  end
91
97
 
92
98
  # Describe a set of tasks as JSON.
93
- def self.describe_tasks(arns)
99
+ def self.describe_tasks(cluster, arns)
94
100
  run("describe-tasks",
101
+ "--cluster", cluster,
95
102
  "--tasks", *arns)
96
103
  end
97
104
  end
@@ -28,39 +28,41 @@ module EcsCompose
28
28
 
29
29
  # Register this task definition with ECS, and update the corresponding
30
30
  # service.
31
- def update
32
- Ecs.update_service(name, register)
31
+ def update(cluster)
32
+ Ecs.update_service(cluster.name, name, register)
33
33
  name
34
34
  end
35
35
 
36
36
  # Set the number of running copies of a service we want to have.
37
- def scale(count)
38
- Ecs.update_service_desired_count(name, count)
37
+ def scale(cluster, count)
38
+ Ecs.update_service_desired_count(cluster.name, name, count)
39
39
  name
40
40
  end
41
41
 
42
42
  # Wait for a set of services to reach a steady state.
43
- def self.wait_for_services(service_names)
44
- Ecs.wait_services_stable(service_names)
43
+ def self.wait_for_services(cluster, service_names)
44
+ Ecs.wait_services_stable(cluster.name, service_names)
45
45
  # TODO: We never actually get here if the services don't stabilize,
46
46
  # because wait_services_stable will fail with `Waiter ServicesStable
47
47
  # failed: Max attempts`. But we're keeping this code until we
48
48
  # implement event polling and our own version of waiting.
49
- ServiceError.fail_if_not_stabilized(Ecs.describe_services(service_names))
49
+ descriptions = Ecs.describe_services(cluster.name, service_names)
50
+ ServiceError.fail_if_not_stabilized(descriptions)
50
51
  end
51
52
 
52
53
  # Run this task definition as a one-shot ECS task, with the specified
53
54
  # overrides.
54
- def run(**args)
55
+ def run(cluster, **args)
55
56
  overrides_json = json_generator.generate_override_json(**args)
56
- info = Ecs.run_task(register, overrides_json: overrides_json)
57
+ info = Ecs.run_task(cluster.name, register,
58
+ overrides_json: overrides_json)
57
59
  info.fetch("tasks")[0].fetch("taskArn")
58
60
  end
59
61
 
60
62
  # Wait for a set of tasks to finish, and raise an error if they fail.
61
- def self.wait_for_tasks(task_arns)
62
- Ecs.wait_tasks_stopped(task_arns)
63
- TaskError.fail_on_errors(Ecs.describe_tasks(task_arns))
63
+ def self.wait_for_tasks(cluster, task_arns)
64
+ Ecs.wait_tasks_stopped(cluster.name, task_arns)
65
+ TaskError.fail_on_errors(Ecs.describe_tasks(cluster.name, task_arns))
64
66
  end
65
67
 
66
68
  # Generate ECS task definition JSON for this instance.
data/lib/ecs_compose.rb CHANGED
@@ -4,6 +4,7 @@ require "ecs_compose/ecs"
4
4
  require "ecs_compose/deployment_error"
5
5
  require "ecs_compose/service_error"
6
6
  require "ecs_compose/task_error"
7
+ require "ecs_compose/cluster"
7
8
  require "ecs_compose/task_definition"
8
9
  require "ecs_compose/manifest"
9
10
 
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.pre14
4
+ version: 0.1.0.pre15
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-11 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -104,6 +104,7 @@ files:
104
104
  - exe/ecs-compose
105
105
  - go-publish.sh
106
106
  - lib/ecs_compose.rb
107
+ - lib/ecs_compose/cluster.rb
107
108
  - lib/ecs_compose/deployment_error.rb
108
109
  - lib/ecs_compose/ecs.rb
109
110
  - lib/ecs_compose/json_generator.rb