ecs_oneshot 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +14 -4
- data/lib/ecs_oneshot/cli.rb +5 -14
- data/lib/ecs_oneshot/config.rb +1 -9
- data/lib/ecs_oneshot/task.rb +5 -2
- data/lib/ecs_oneshot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f55e1bf5ed436b6b9a39d8dd9ee6946b475a060e8f50560d64ddef12326b8cc
|
4
|
+
data.tar.gz: 9056ca0a22315281d41e87a55e046d35164595475cae7fce4bd6b47c22c965f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c449cd8b03b692ce89a12d2a98ee769b498ef5b5b0282d2266421e50c404ffbb474cc3ed3749b8d4a4218d9a7bb07ff1520d6a4cf8b115afb14525de526eade
|
7
|
+
data.tar.gz: db60aab1c7dc48e7e9a9116358c3e60b925a7245727b6d942a333c492b47eb49705d4e3498cdf1d0d3faba03569fc2669f348399af33bc91414ac8ab081fa57d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
![Ruby](https://github.com/sinsoku/ecs_oneshot/workflows/Ruby/badge.svg)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/ecs_oneshot.svg)](https://badge.fury.io/rb/ecs_oneshot)
|
5
5
|
|
6
|
-
|
6
|
+
Provides a simple way to run one-shot tasks using the ECS runTask API.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -23,12 +23,21 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
|
26
|
+
```
|
27
|
+
Usage: ecs_oneshot [options] -- <commmand>
|
28
|
+
-c, --config FILE Specify configuration file. (default: .ecs_oneshot.yml)
|
29
|
+
-e, --environment ENVIRONMENT Specify environment. (default: production)
|
30
|
+
--cluster CLUSTER
|
31
|
+
--service SERVICE
|
32
|
+
--task-definition TASK_DEFINITION
|
33
|
+
--container CONTAINER
|
34
|
+
```
|
27
35
|
|
28
|
-
|
36
|
+
## Example
|
29
37
|
|
30
38
|
```console
|
31
|
-
$ ecs_oneshot --cluster
|
39
|
+
$ ecs_oneshot --cluster mycluster --service myservice --task-definition rails-app:1 --container app -- bin/rails -T
|
40
|
+
Task started. Watch this task's details in the Amazon ECS console: https://console.aws.amazon.com/ecs/home?ap-northeast-1#/clusters/default/tasks/00000000-1234-5678-9000-aaaaaaaaaaaa/details
|
32
41
|
=== Wait for Task Starting...
|
33
42
|
=== Following Logs...
|
34
43
|
rails about # List versions of all Rails frameworks and the environment
|
@@ -49,6 +58,7 @@ If the configuration file exists, it will be loaded.
|
|
49
58
|
production:
|
50
59
|
cluster: mycluster
|
51
60
|
service: myservice
|
61
|
+
task_definition: task-def
|
52
62
|
container: mycontainer
|
53
63
|
```
|
54
64
|
|
data/lib/ecs_oneshot/cli.rb
CHANGED
@@ -9,11 +9,7 @@ module EcsOneshot
|
|
9
9
|
def run(args = ARGV)
|
10
10
|
options = parse_options(args)
|
11
11
|
|
12
|
-
|
13
|
-
init_config(options)
|
14
|
-
else
|
15
|
-
run_task(options)
|
16
|
-
end
|
12
|
+
run_task(options)
|
17
13
|
rescue Error => e
|
18
14
|
warn e.message
|
19
15
|
exit 1
|
@@ -36,6 +32,7 @@ module EcsOneshot
|
|
36
32
|
|
37
33
|
t = Task.new(config)
|
38
34
|
t.run
|
35
|
+
puts "Task started. Watch this task's details in the Amazon ECS console: #{t.console_url}\n\n"
|
39
36
|
puts "=== Wait for Task Starting..."
|
40
37
|
t.wait_running
|
41
38
|
puts "=== Following Logs..."
|
@@ -43,14 +40,7 @@ module EcsOneshot
|
|
43
40
|
puts "\n=== Task Stopped."
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
path = options[:config]
|
48
|
-
env = options[:environment]
|
49
|
-
|
50
|
-
Config.safe_build(options).save(path, env)
|
51
|
-
end
|
52
|
-
|
53
|
-
def parse_options(args) # rubocop:disable Metrics/MethodLength
|
43
|
+
def parse_options(args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
54
44
|
opts = OptionParser.new
|
55
45
|
opts.banner = "Usage: ecs_oneshot [options] -- <commmand>"
|
56
46
|
opts.version = VERSION
|
@@ -59,13 +49,14 @@ module EcsOneshot
|
|
59
49
|
opts.on("-e", "--environment ENVIRONMENT", "Specify environment. (default: production)")
|
60
50
|
opts.on("--cluster CLUSTER")
|
61
51
|
opts.on("--service SERVICE")
|
52
|
+
opts.on("--task-definition TASK_DEFINITION")
|
62
53
|
opts.on("--container CONTAINER")
|
63
|
-
opts.on("--init", "Generate a configuration file.")
|
64
54
|
|
65
55
|
{}.tap do |h|
|
66
56
|
h[:command] = opts.parse(args, into: h)
|
67
57
|
h[:config] ||= ".ecs_oneshot.yml"
|
68
58
|
h[:environment] ||= "production"
|
59
|
+
h[:task_definition] = h.delete(:"task-definition")
|
69
60
|
end
|
70
61
|
end
|
71
62
|
end
|
data/lib/ecs_oneshot/config.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require "yaml"
|
4
4
|
|
5
5
|
module EcsOneshot
|
6
|
-
Config = Struct.new(:cluster, :service, :container, :command, keyword_init: true)
|
6
|
+
Config = Struct.new(:cluster, :service, :container, :task_definition, :command, keyword_init: true)
|
7
7
|
|
8
8
|
class Config
|
9
9
|
class << self
|
@@ -23,14 +23,6 @@ module EcsOneshot
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def save(path, env)
|
27
|
-
raise Error, "already exists at '#{path}'." if File.exist?(path)
|
28
|
-
|
29
|
-
File.open(path, "w") do |f|
|
30
|
-
YAML.dump({ env => to_h.transform_keys(&:to_s) }, f)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
26
|
def merge(other)
|
35
27
|
new_options = to_h.merge(other.to_h.compact)
|
36
28
|
Config.new(**new_options)
|
data/lib/ecs_oneshot/task.rb
CHANGED
@@ -20,6 +20,10 @@ module EcsOneshot
|
|
20
20
|
@id = @arn.split("/").last
|
21
21
|
end
|
22
22
|
|
23
|
+
def console_url
|
24
|
+
"https://console.aws.amazon.com/ecs/home?#{ecs.config.region}#/clusters/#{config.cluster}/tasks/#{@id}/details"
|
25
|
+
end
|
26
|
+
|
23
27
|
def wait_running
|
24
28
|
ecs.wait_until(:tasks_running, cluster: config.cluster, tasks: [arn])
|
25
29
|
rescue Aws::Waiters::Errors::WaiterFailed
|
@@ -68,8 +72,7 @@ module EcsOneshot
|
|
68
72
|
def task_definition
|
69
73
|
return @task_definition if @task_definition
|
70
74
|
|
71
|
-
|
72
|
-
task_definition = service.task_definition.sub(/:\d+$/, "")
|
75
|
+
task_definition = config.task_definition || service.task_definition
|
73
76
|
@task_definition = ecs.describe_task_definition(task_definition: task_definition)
|
74
77
|
.task_definition
|
75
78
|
end
|
data/lib/ecs_oneshot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecs_oneshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takumi Shotoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-cloudwatchlogs
|