mikoshi 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +2 -1
- data/Gemfile +2 -0
- data/README.md +22 -12
- data/Rakefile +5 -8
- data/bin/console +1 -0
- data/exe/mikoshi +2 -0
- data/lib/mikoshi.rb +2 -0
- data/lib/mikoshi/cli.rb +6 -18
- data/lib/mikoshi/plan.rb +8 -0
- data/lib/mikoshi/plan/service.rb +50 -16
- data/lib/mikoshi/plan/task_definition.rb +16 -1
- data/lib/mikoshi/version.rb +3 -1
- data/mikoshi.gemspec +7 -1
- metadata +51 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66bb151aeed8702ad507aa84126eff3bda7fbf90
|
4
|
+
data.tar.gz: 8085cc9bf14cc57ad151282ac13b5d35785be054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6817c50c328ae791ead793aea49a4bab1972166cff09c07fe88b7166378e2c35bf9fa2ed9f435f9a0115794007254ec1a97100b94e8083cc0eed5c96ce58c4bf
|
7
|
+
data.tar.gz: 9f3278475c0c6d9e05450aabfdc93ece6b57a10d9397de67e56cb557f1cb9a9018706dcf266bf5528b177c6f436fd98bac5fd01313f09cf8bd24e1c8b1ab25c7
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Mikoshi
|
2
2
|
[![Build Status](https://travis-ci.org/unasuke/mikoshi.svg?branch=master)](https://travis-ci.org/unasuke/mikoshi)
|
3
|
+
[![codecov](https://codecov.io/gh/unasuke/mikoshi/branch/master/graph/badge.svg)](https://codecov.io/gh/unasuke/mikoshi)
|
3
4
|
|
4
5
|
This gem is tool to deploy ECS task definition and service with described by yaml documents.
|
5
6
|
|
@@ -24,23 +25,32 @@ First, describe task definition to yaml.
|
|
24
25
|
|
25
26
|
```yaml
|
26
27
|
# task_definitions/ping2googledns.yml.erb
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
task_definition:
|
29
|
+
family: "ping2googledns"
|
30
|
+
network_mode: "bridge"
|
31
|
+
container_definitions:
|
32
|
+
- name: "ping"
|
33
|
+
image: "unasuke/ping2googledns:latest"
|
34
|
+
cpu: 128
|
35
|
+
memory: 128
|
36
|
+
hooks:
|
37
|
+
after_register:
|
38
|
+
- echo registerd
|
34
39
|
```
|
35
40
|
|
36
41
|
... and service too.
|
37
42
|
|
38
43
|
```yaml
|
39
44
|
# services/ping2googledns.yml.erb
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
service:
|
46
|
+
cluster: "default"
|
47
|
+
service: "ping2googledns"
|
48
|
+
task_definition: <%= "ping2googledns:#{ENV['TASK_DEF_REVISION']}" %>
|
49
|
+
desired_count: 1
|
50
|
+
hooks:
|
51
|
+
before_update:
|
52
|
+
- echo some shell command
|
53
|
+
- echo shell command another one
|
44
54
|
```
|
45
55
|
|
46
56
|
Then, invoke those commands.
|
@@ -52,7 +62,7 @@ Update task definition: ping2googledns
|
|
52
62
|
Done update task definition: ping2googledns revision: 6
|
53
63
|
|
54
64
|
# update service
|
55
|
-
$
|
65
|
+
$ TASK_DEF_REVISION=3 mikoshi update_service ping2googledns
|
56
66
|
Update service : ping2googledns
|
57
67
|
Waiting for 10 sec...
|
58
68
|
Update service success
|
data/Rakefile
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
|
-
require '
|
4
|
+
require 'rspec/core/rake_task'
|
3
5
|
require 'rubocop/rake_task'
|
4
6
|
|
5
|
-
|
6
|
-
t.libs << 'test'
|
7
|
-
t.libs << 'lib'
|
8
|
-
t.test_files = FileList['test/**/*_test.rb']
|
9
|
-
end
|
10
|
-
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
8
|
RuboCop::RakeTask.new
|
12
9
|
|
13
|
-
task default: %i[
|
10
|
+
task default: %i[spec rubocop]
|
data/bin/console
CHANGED
data/exe/mikoshi
CHANGED
data/lib/mikoshi.rb
CHANGED
data/lib/mikoshi/cli.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'thor'
|
2
4
|
require 'aws-sdk'
|
3
|
-
require 'timeout'
|
4
5
|
require 'mikoshi/plan'
|
5
6
|
require 'mikoshi/plan/task_definition'
|
6
7
|
require 'mikoshi/plan/service'
|
7
8
|
|
8
9
|
module Mikoshi
|
9
10
|
class Cli < Thor
|
10
|
-
TASK_DEFINITION_PATH = 'task_definitions'
|
11
|
-
SERVICE_PATH = 'services'
|
12
|
-
PLAN_EXT = '.yml.erb'
|
11
|
+
TASK_DEFINITION_PATH = 'task_definitions'
|
12
|
+
SERVICE_PATH = 'services'
|
13
|
+
PLAN_EXT = '.yml.erb'
|
13
14
|
FETCH_INTERVAL = 10
|
14
15
|
DEPLOY_TIMEOUT = 300
|
15
16
|
|
@@ -33,20 +34,7 @@ module Mikoshi
|
|
33
34
|
client: aws_client,
|
34
35
|
)
|
35
36
|
puts "Update service : #{service_name}"
|
36
|
-
service.deploy_service
|
37
|
-
begin
|
38
|
-
Timeout.timeout(DEPLOY_TIMEOUT) do
|
39
|
-
loop do
|
40
|
-
puts "Waiting for #{FETCH_INTERVAL} sec..."
|
41
|
-
sleep FETCH_INTERVAL
|
42
|
-
break if service.deployed?
|
43
|
-
end
|
44
|
-
end
|
45
|
-
rescue Timeout::Error
|
46
|
-
puts "Update failed by timeout(#{DEPLOY_TIMEOUT} sec)"
|
47
|
-
exit(false)
|
48
|
-
end
|
49
|
-
|
37
|
+
service.deploy_service(message: true)
|
50
38
|
puts "Done update service #{service_name}"
|
51
39
|
end
|
52
40
|
|
data/lib/mikoshi/plan.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/hash/keys'
|
2
4
|
require 'erb'
|
3
5
|
require 'yaml'
|
@@ -14,6 +16,12 @@ module Mikoshi
|
|
14
16
|
@data = YAML.safe_load(ERB.new(File.new(yaml_path).read).result).deep_symbolize_keys
|
15
17
|
@client = client
|
16
18
|
end
|
19
|
+
|
20
|
+
def invoke_hooks(hooks)
|
21
|
+
hooks.each do |hook|
|
22
|
+
system hook
|
23
|
+
end
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
data/lib/mikoshi/plan/service.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/hash/except'
|
2
4
|
require 'mikoshi/plan'
|
3
5
|
|
@@ -9,40 +11,72 @@ module Mikoshi
|
|
9
11
|
def initialize(yaml_path: nil, client: nil)
|
10
12
|
super
|
11
13
|
|
12
|
-
if @data[:task_definition].match(TASK_DEFINITION_WITH_REVISION).nil?
|
14
|
+
if @data[:service][:task_definition].match(TASK_DEFINITION_WITH_REVISION).nil?
|
13
15
|
raise ArgumentError, 'task_definition should have revision by numerically.'
|
14
16
|
end
|
15
17
|
|
16
|
-
@data.store :service_name, @data[:service]
|
18
|
+
@data[:service].store :service_name, @data[:service][:service]
|
17
19
|
end
|
18
20
|
|
19
21
|
def create_service
|
20
|
-
|
22
|
+
invoke_before_create_hooks
|
23
|
+
|
24
|
+
@client.create_service(@data[:service].except(:service))
|
21
25
|
end
|
22
26
|
|
23
27
|
def update_service
|
24
|
-
|
28
|
+
invoke_before_update_hooks
|
29
|
+
|
30
|
+
@client.update_service(@data[:service].except(:service_name))
|
25
31
|
end
|
26
32
|
|
27
|
-
def deploy_service
|
28
|
-
|
29
|
-
|
33
|
+
def deploy_service(message: false)
|
34
|
+
case operation
|
35
|
+
when :create
|
30
36
|
create_service
|
31
|
-
|
37
|
+
when :update
|
32
38
|
update_service
|
33
39
|
end
|
34
|
-
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
@client.wait_until(:services_stable, cluster: @data[:service][:cluster], services: [@data[:service][:service]]) do |w|
|
42
|
+
w.max_attempts = 30
|
43
|
+
w.delay = 10
|
44
|
+
|
45
|
+
w.before_wait do
|
46
|
+
puts 'Waiting to change status of service...' if message
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
case operation
|
51
|
+
when :create
|
52
|
+
invoke_after_create_hooks
|
53
|
+
when :update
|
54
|
+
invoke_after_update_hooks
|
40
55
|
end
|
56
|
+
end
|
41
57
|
|
42
|
-
|
43
|
-
|
58
|
+
private
|
59
|
+
|
60
|
+
def operation
|
61
|
+
if @operation
|
62
|
+
@operation
|
44
63
|
else
|
45
|
-
|
64
|
+
resp = @client.describe_services(cluster: @data[:service][:cluster], services: [@data[:service][:service]])
|
65
|
+
|
66
|
+
@operation ||=
|
67
|
+
if resp.services.empty? || resp.services.first.status == 'INACTIVE'
|
68
|
+
:create
|
69
|
+
else
|
70
|
+
:update
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
%w[before after].each do |step|
|
76
|
+
%w[create update].each do |func|
|
77
|
+
define_method "invoke_#{step}_#{func}_hooks" do
|
78
|
+
invoke_hooks @data[:hooks]["#{step}_#{func}".to_sym] unless @data.dig(:hooks, "#{step}_#{func}".to_sym).nil?
|
79
|
+
end
|
46
80
|
end
|
47
81
|
end
|
48
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mikoshi/plan'
|
2
4
|
|
3
5
|
module Mikoshi
|
@@ -8,10 +10,23 @@ module Mikoshi
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def register_task_definition
|
11
|
-
|
13
|
+
invoke_before_register_hooks
|
14
|
+
|
15
|
+
resp = @client.register_task_definition(@data[:task_definition])
|
12
16
|
ENV['TASK_DEF_REVISION'] = resp.task_definition.revision.to_s
|
17
|
+
|
18
|
+
invoke_after_register_hooks
|
19
|
+
|
13
20
|
resp
|
14
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
%w[before after].each do |step|
|
26
|
+
define_method "invoke_#{step}_register_hooks" do
|
27
|
+
invoke_hooks @data[:hooks]["#{step}_register".to_sym] unless @data.dig(:hooks, "#{step}_register".to_sym).nil?
|
28
|
+
end
|
29
|
+
end
|
15
30
|
end
|
16
31
|
end
|
17
32
|
end
|
data/lib/mikoshi/version.rb
CHANGED
data/mikoshi.gemspec
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# coding: utf-8
|
2
3
|
|
3
4
|
lib = File.expand_path('../lib', __FILE__)
|
@@ -22,12 +23,17 @@ Gem::Specification.new do |spec|
|
|
22
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
24
|
spec.require_paths = ['lib']
|
24
25
|
|
26
|
+
spec.required_ruby_version = '>= 2.3.0'
|
27
|
+
|
25
28
|
spec.add_dependency 'activesupport', '~> 5'
|
26
29
|
spec.add_dependency 'aws-sdk', '~> 2'
|
27
30
|
spec.add_dependency 'thor'
|
28
31
|
|
29
32
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
33
|
+
spec.add_development_dependency 'codecov'
|
30
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
-
spec.add_development_dependency '
|
35
|
+
spec.add_development_dependency 'rspec'
|
36
|
+
spec.add_development_dependency 'simplecov'
|
32
37
|
spec.add_development_dependency 'unasukecop'
|
38
|
+
spec.add_development_dependency 'pry'
|
33
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mikoshi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,19 +95,33 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '10.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - ">="
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: unasukecop
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +136,20 @@ dependencies:
|
|
108
136
|
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
111
153
|
description: Mikoshi is a tool that deploy to ECS and manage task definition and cluster.
|
112
154
|
email:
|
113
155
|
- yusuke1994525@gmail.com
|
@@ -117,6 +159,7 @@ extensions: []
|
|
117
159
|
extra_rdoc_files: []
|
118
160
|
files:
|
119
161
|
- ".gitignore"
|
162
|
+
- ".rspec"
|
120
163
|
- ".rubocop.yml"
|
121
164
|
- ".travis.yml"
|
122
165
|
- Gemfile
|
@@ -145,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
188
|
requirements:
|
146
189
|
- - ">="
|
147
190
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
191
|
+
version: 2.3.0
|
149
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
193
|
requirements:
|
151
194
|
- - ">="
|