hako 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09a67f10cb41c44240b92e06db1fe5f13184e78a
4
- data.tar.gz: 12debcaa9ddb9719d8b41ce5fb0511957918dcd9
3
+ metadata.gz: 2eb5f8e08ca1d904ac2fd8b62eef4a6f1475058c
4
+ data.tar.gz: 26dc1a08053eb64a64f8e43c9842a5e4ede4d005
5
5
  SHA512:
6
- metadata.gz: 94cc6eba550cde280f0e4f234d6dc4f9147e7a2fd7677edc25e7febd640688f462e127e103dc7139eb582b4a88bae8a87cf4c254f39c808db3ccdce99489e3da
7
- data.tar.gz: 178293b2984bf77e788f07793a748c5688e1b2dcc7570d9614662cbcb0664b8c7e44bd629794872bdbcdf33f10a1aeb76da13eff41c76b8545b06b97455f8e7c
6
+ metadata.gz: c65560e2a33df328f972de4d4602fcc5192757bf29099905215df7a3e4a491016d200ca593fa12dce4cbc99c2e285bd54c54a6ef3e8d25b7ec8df3b430a2081b
7
+ data.tar.gz: 48f1e96ecf8a524c73998ec1517c6ac2b5b96d620274b94feea0388701b0bb3eb44f33c9cf4df33b61fba82cf5872d7487e31037c93486ab20a6dba4fd56bf81
data/exe/hako CHANGED
@@ -2,4 +2,4 @@
2
2
  # frozen_string_literal: true
3
3
  require 'hako/cli'
4
4
 
5
- Hako::CLI.start
5
+ Hako::CLI.start(ARGV)
data/hako.gemspec CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'aws-sdk', '>= 2.1.0'
22
- spec.add_dependency 'thor'
23
22
 
24
23
  spec.add_development_dependency 'bundler'
25
24
  spec.add_development_dependency 'rake'
data/lib/hako/cli.rb CHANGED
@@ -1,67 +1,207 @@
1
1
  # frozen_string_literal: true
2
2
  require 'hako'
3
- require 'thor'
3
+ require 'optparse'
4
4
 
5
5
  module Hako
6
- class CLI < Thor
7
- desc 'deploy FILE', 'Run deployment'
8
- option :force, aliases: %w[-f], type: :boolean, default: false, desc: 'Run deployment even if nothing is changed'
9
- option :tag, aliases: %w[-t], type: :string, default: 'latest', desc: 'Specify tag (default: latest)'
10
- option :dry_run, aliases: %w[-n], type: :boolean, default: false, desc: 'Enable dry-run mode'
11
- option :verbose, aliases: %w[-v], type: :boolean, default: false, desc: 'Enable verbose logging'
12
- def deploy(yaml_path)
13
- require 'hako/application'
14
- require 'hako/commander'
6
+ class CLI
7
+ SUB_COMMANDS = %w[
8
+ deploy
9
+ oneshot
10
+ show-yaml
11
+ status
12
+ remove
13
+ ].freeze
15
14
 
16
- if options[:verbose]
17
- Hako.logger.level = Logger::DEBUG
15
+ def self.start(argv)
16
+ new(argv).run
17
+ end
18
+
19
+ def initialize(argv)
20
+ @argv = argv.dup
21
+ @help = false
22
+ parser.order!(@argv)
23
+ end
24
+
25
+ def run
26
+ if @help || @argv.empty?
27
+ puts parser.help
28
+ SUB_COMMANDS.each do |subcommand|
29
+ puts create_subcommand(subcommand).new.parser.help
30
+ end
31
+ else
32
+ create_subcommand(@argv.shift).new.run(@argv)
18
33
  end
34
+ end
19
35
 
20
- Commander.new(Application.new(yaml_path)).deploy(force: options[:force], tag: options[:tag], dry_run: options[:dry_run])
36
+ private
37
+
38
+ def parser
39
+ @parser ||= OptionParser.new do |opts|
40
+ opts.banner = 'hako'
41
+ opts.version = VERSION
42
+ opts.on('-h', '--help', 'Show help') { @help = true }
43
+ end
21
44
  end
22
45
 
23
- desc 'oneshot FILE COMMAND ARG...', 'Run oneshot task'
24
- option :tag, aliases: %w[-t], type: :string, default: 'latest', desc: 'Specify tag (default: latest)'
25
- option :containers, aliases: %w[-c], type: :string, default: '', banner: 'NAME1,NAME2', desc: 'Comma-separated additional container names to start with the app container (default: "")'
26
- option :verbose, aliases: %w[-v], type: :boolean, default: false, desc: 'Enable verbose logging'
27
- def oneshot(yaml_path, command, *args)
28
- require 'hako/application'
29
- require 'hako/commander'
46
+ def create_subcommand(sub)
47
+ if SUB_COMMANDS.include?(sub)
48
+ CLI.const_get(sub.split('-').map(&:capitalize).join(''))
49
+ else
50
+ $stderr.puts "No such subcommand: #{sub}"
51
+ exit 1
52
+ end
53
+ end
30
54
 
31
- if options[:verbose]
32
- Hako.logger.level = Logger::DEBUG
55
+ class Deploy
56
+ def run(argv)
57
+ parse!(argv)
58
+ require 'hako/application'
59
+ require 'hako/commander'
60
+
61
+ if @verbose
62
+ Hako.logger.level = Logger::DEBUG
63
+ end
64
+
65
+ Commander.new(Application.new(@yaml_path)).deploy(force: @force, tag: @tag, dry_run: @dry_run)
66
+ end
67
+
68
+ def parse!(argv)
69
+ @force = false
70
+ @tag = 'latest'
71
+ @dry_run = false
72
+ @verbose = false
73
+ parser.parse!(argv)
74
+ @yaml_path = argv.first
75
+
76
+ if @yaml_path.nil?
77
+ puts parser.help
78
+ exit 1
79
+ end
33
80
  end
34
81
 
35
- Commander.new(Application.new(yaml_path)).oneshot([command, *args], tag: options[:tag], containers: options[:containers].split(','))
82
+ def parser
83
+ @parser ||= OptionParser.new do |opts|
84
+ opts.banner = 'hako deploy [OPTIONS] FILE'
85
+ opts.version = VERSION
86
+ opts.on('-f', '--force', 'Run deployment even if nothing is changed') { @force = true }
87
+ opts.on('-t', '--tag=TAG', 'Specify tag (default: latest)') { |v| @tag = v }
88
+ opts.on('-n', '--dry-run', 'Enable dry-run mode') { @dry_run = true }
89
+ opts.on('-v', '--verbose', 'Enable verbose logging') { @verbose = true }
90
+ end
91
+ end
36
92
  end
37
93
 
38
- desc 'show-yaml FILE', 'Show expanded YAML'
39
- def show_yaml(yaml_path)
40
- require 'hako/yaml_loader'
41
- puts YamlLoader.new.load(Pathname.new(yaml_path)).to_yaml
94
+ class Oneshot
95
+ def run(argv)
96
+ parse!(argv)
97
+ require 'hako/application'
98
+ require 'hako/commander'
99
+
100
+ if @verbose
101
+ Hako.logger.level = Logger::DEBUG
102
+ end
103
+
104
+ Commander.new(Application.new(@yaml_path)).oneshot(@argv, tag: @tag, containers: @containers)
105
+ end
106
+
107
+ def parse!(argv)
108
+ @tag = 'latest'
109
+ @containers = []
110
+ @verbose = false
111
+ parser.parse!(argv)
112
+ @yaml_path = argv.shift
113
+ @argv = argv
114
+
115
+ if @yaml_path.nil? || @argv.empty?
116
+ puts parser.help
117
+ exit 1
118
+ end
119
+ end
120
+
121
+ def parser
122
+ @parser ||= OptionParser.new do |opts|
123
+ opts.banner = 'hako oneshot [OPTIONS] FILE COMMAND ARG...'
124
+ opts.version = VERSION
125
+ opts.on('-t', '--tag=TAG', 'Specify tag (default: latest)') { @tag = tag }
126
+ opts.on('-c', '--container=NAME', 'Additional container name to start with the app container') { |v| @containers << v }
127
+ opts.on('-v', '--verbose', 'Enable verbose logging') { @verbose = true }
128
+ end
129
+ end
42
130
  end
43
131
 
44
- desc 'status FILE', 'Show deployment status'
45
- def status(yaml_path)
46
- require 'hako/application'
47
- require 'hako/commander'
48
- Commander.new(Application.new(yaml_path)).status
132
+ class ShowYaml
133
+ def run(argv)
134
+ parse!(argv)
135
+ require 'hako/yaml_loader'
136
+ puts YamlLoader.new.load(Pathname.new(@yaml_path)).to_yaml
137
+ end
138
+
139
+ def parse!(argv)
140
+ parser.parse!(argv)
141
+ @yaml_path = argv.first
142
+ if @yaml_path.nil?
143
+ puts parser.help
144
+ exit 1
145
+ end
146
+ end
147
+
148
+ def parser
149
+ @parser ||= OptionParser.new do |opts|
150
+ opts.banner = 'hako show-yaml FILE'
151
+ opts.version = VERSION
152
+ end
153
+ end
49
154
  end
50
155
 
51
- desc 'remove FILE', 'Destroy the application'
52
- def remove(yaml_path)
53
- require 'hako/application'
54
- require 'hako/commander'
55
- Commander.new(Application.new(yaml_path)).remove
156
+ class Status
157
+ def run(argv)
158
+ parse!(argv)
159
+ require 'hako/application'
160
+ require 'hako/commander'
161
+ Commander.new(Application.new(@yaml_path)).status
162
+ end
163
+
164
+ def parse!(argv)
165
+ parser.parse!(argv)
166
+ @yaml_path = argv.first
167
+
168
+ if @yaml_path.nil?
169
+ puts parser.help
170
+ exit 1
171
+ end
172
+ end
173
+
174
+ def parser
175
+ @parser ||= OptionParser.new do |opts|
176
+ opts.banner = 'hako status FILE'
177
+ opts.version = VERSION
178
+ end
179
+ end
56
180
  end
57
181
 
58
- desc 'version', 'Show version'
59
- option :numeric, type: :boolean, default: false, desc: 'Show numeric only'
60
- def version
61
- if options[:numeric]
62
- say VERSION
63
- else
64
- say "hako v#{VERSION}"
182
+ class Remove
183
+ def run
184
+ parse!(argv)
185
+ require 'hako/application'
186
+ require 'hako/commander'
187
+ Commander.new(Application.new(@yaml_path)).remove
188
+ end
189
+
190
+ def parse!(argv)
191
+ parser.parse!(argv)
192
+ @yaml_path = argv.first
193
+
194
+ if @yaml_path.nil?
195
+ puts parser.help
196
+ exit 1
197
+ end
198
+ end
199
+
200
+ def parser
201
+ @parser ||= OptionParser.new do |opts|
202
+ opts.banner = 'hako remove FILE'
203
+ opts.version = VERSION
204
+ end
65
205
  end
66
206
  end
67
207
  end
@@ -69,8 +69,19 @@ module Hako
69
69
  end
70
70
  task = run_task(task_definition, commands)
71
71
  Hako.logger.info "Started task: #{task.task_arn}"
72
- exit_code = wait_for_task(task)
72
+ containers = wait_for_task(task)
73
73
  Hako.logger.info 'Oneshot task finished'
74
+ exit_code = 127
75
+ containers.each do |name, container|
76
+ if container.exit_code.nil?
77
+ Hako.logger.info "#{name} has stopped without exit_code: reason=#{container.reason}"
78
+ else
79
+ Hako.logger.info "#{name} has stopped with exit_code=#{container.exit_code}"
80
+ if name == 'app'
81
+ exit_code = container.exit_code
82
+ end
83
+ end
84
+ end
74
85
  exit_code
75
86
  end
76
87
 
@@ -325,9 +336,7 @@ module Hako
325
336
  task.containers.each do |c|
326
337
  containers[c.name] = c
327
338
  end
328
- app = containers.fetch('app')
329
- Hako.logger.info "Exit code is #{app.exit_code}"
330
- return app.exit_code
339
+ return containers
331
340
  end
332
341
  sleep 1
333
342
  end
data/lib/hako/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hako
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hako
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.0
27
- - !ruby/object:Gem::Dependency
28
- name: thor
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement