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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e732444d9107e6409fde22edc4700c1c7ceaad3c
4
- data.tar.gz: ba803c7452847c673431eab79e2d02b99d748423
3
+ metadata.gz: 66bb151aeed8702ad507aa84126eff3bda7fbf90
4
+ data.tar.gz: 8085cc9bf14cc57ad151282ac13b5d35785be054
5
5
  SHA512:
6
- metadata.gz: 6fccda9380d7deecc83029d0cb2180601bc6949d2997e37d279728ebecbd083a78c66512cf4eee74d9b4bb75e41a319ee12bfc0e471831bbd3463619d3f68e8b
7
- data.tar.gz: 65224e4c679303011d1a2c85bb77935c72e26023c583f35cd8a3698e513c9b987d71fedd81ec538ef3da4190368be12b2621a8c56bf54b53cc13533382d937a3
6
+ metadata.gz: 6817c50c328ae791ead793aea49a4bab1972166cff09c07fe88b7166378e2c35bf9fa2ed9f435f9a0115794007254ec1a97100b94e8083cc0eed5c96ce58c4bf
7
+ data.tar.gz: 9f3278475c0c6d9e05450aabfdc93ece6b57a10d9397de67e56cb557f1cb9a9018706dcf266bf5528b177c6f436fd98bac5fd01313f09cf8bd24e1c8b1ab25c7
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /task_definitions/
11
+ /services/
12
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -6,3 +6,8 @@ Style/Documentation:
6
6
  Enabled: false
7
7
  Style/RegexpLiteral:
8
8
  EnforcedStyle: percent_r
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'spec/**/*_spec.rb'
13
+ - 'mikoshi.gemspec'
data/.travis.yml CHANGED
@@ -3,8 +3,9 @@ notifications:
3
3
  sudo: false
4
4
  language: ruby
5
5
  rvm:
6
- - 2.2.7
7
6
  - 2.3.4
8
7
  - 2.4.1
9
8
  - ruby-head
10
9
  before_install: gem install bundler -v 1.14.3
10
+ script:
11
+ - bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in mikoshi.gemspec
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
- family: "ping2googledns"
28
- network_mode: "bridge"
29
- container_definitions:
30
- - name: "ping"
31
- image: "unasuke/ping2googledns:latest"
32
- cpu: 128
33
- memory: 128
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
- cluster: "default"
41
- service: "ping2googledns"
42
- task_definition: <%= "ping2googledns:#{ENV['TASK_REVISION']}" %>
43
- desired_count: 1
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
- $ TASK_REVISION=3 mikoshi update_service ping2googledns
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 'rake/testtask'
4
+ require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
4
6
 
5
- Rake::TestTask.new(:test) do |t|
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[test rubocop]
10
+ task default: %i[spec rubocop]
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'mikoshi'
data/exe/mikoshi CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
5
  require 'mikoshi'
4
6
  Mikoshi::Cli.start
data/lib/mikoshi.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mikoshi/version'
2
4
  require 'mikoshi/cli'
3
5
  require 'mikoshi/plan'
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'.freeze
11
- SERVICE_PATH = 'services'.freeze
12
- PLAN_EXT = '.yml.erb'.freeze
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
@@ -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
- @client.create_service(@data.except(:service))
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
- @client.update_service(@data.except(:service_name))
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
- resp = @client.describe_services(cluster: @data[:cluster], services: [@data[:service]])
29
- if resp.services.empty? || resp.services.first.status == 'INACTIVE'
33
+ def deploy_service(message: false)
34
+ case operation
35
+ when :create
30
36
  create_service
31
- else
37
+ when :update
32
38
  update_service
33
39
  end
34
- end
35
40
 
36
- def deployed?
37
- resp = @client.describe_services(cluster: @data[:cluster], services: [@data[:service]])
38
- deployment = resp.services.first.deployments.find do |d|
39
- d.task_definition.end_with?(@data[:task_definition])
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
- if deployment.running_count == @data[:desired_count]
43
- true
58
+ private
59
+
60
+ def operation
61
+ if @operation
62
+ @operation
44
63
  else
45
- false
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
- resp = @client.register_task_definition(@data)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mikoshi
2
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.2.0'
3
5
  end
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 'minitest', '~> 5.0'
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.1.5
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-16 00:00:00.000000000 Z
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: minitest
98
+ name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: '5.0'
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: '5.0'
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: '0'
191
+ version: 2.3.0
149
192
  required_rubygems_version: !ruby/object:Gem::Requirement
150
193
  requirements:
151
194
  - - ">="