hako 0.2.1 → 0.3.0

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: db06d64418cd4a7dcd0217e8c6ada22c9fd100fb
4
- data.tar.gz: 5f962c2f0b257e6486d69c5bde8f4d16a38663ed
3
+ metadata.gz: bb5ba73f8d811faf60da24c071c8287b1c3dc439
4
+ data.tar.gz: 1a8548db2c69d4e9fc75b0b60a2119bff2f5c505
5
5
  SHA512:
6
- metadata.gz: 55589bac643779f00ed7eaf18c40106e262610685ba747affd57f21001a38ebf0c31f6f0cbdd14f87bea34ca3a5adb6969e116fc149a12737ffe193d80812dde
7
- data.tar.gz: 5d6f39b9a9d2dc9452ebb412981fe0f255b9485faa82819a24a8f2e29554908333693491d84108e1e47fd0ed8016bcc92d84bfb5202d768e25df28cac9225a2e
6
+ metadata.gz: d0f4de4bb3bd8838879bd3ea09054b641658685b8bf3538329e89374c0d4ad8e749c24dd1c89fcad92148580c84bb870f95964f1271fc69fdbdb9c18f2d8ea90
7
+ data.tar.gz: b4cb1198bfd64381b703949cd7c24ddc34f6beb4ce13a34b39f977ee921093bc0d79defa381e092cc2c326ac526bc42940bb8bf0d06f5a1ef49cb32cc07d53a5
data/.rubocop_todo.yml CHANGED
@@ -21,7 +21,3 @@ Metrics/BlockNesting:
21
21
 
22
22
  Style/Documentation:
23
23
  Enabled: false
24
-
25
- # Temporarily...
26
- Metrics/ParameterLists:
27
- Enabled: false
@@ -1,9 +1,10 @@
1
- require 'hako/after_scripts'
1
+ require 'hako/container'
2
2
  require 'hako/env_expander'
3
3
  require 'hako/error'
4
4
  require 'hako/front_config'
5
5
  require 'hako/fronts'
6
6
  require 'hako/schedulers'
7
+ require 'hako/scripts'
7
8
 
8
9
  module Hako
9
10
  class Commander
@@ -11,7 +12,6 @@ module Hako
11
12
 
12
13
  def initialize(app)
13
14
  @app = app
14
- $LOAD_PATH << @app.root_path.join('lib')
15
15
  end
16
16
 
17
17
  def deploy(force: false, tag: 'latest')
@@ -19,14 +19,16 @@ module Hako
19
19
  front = load_front(@app.yaml['front'])
20
20
  scheduler = load_scheduler(@app.yaml['scheduler'])
21
21
  app_port = @app.yaml.fetch('port', nil)
22
- docker_labels = @app.yaml.fetch('docker_labels', {})
23
22
  image = @app.yaml.fetch('image') { raise Error.new('image must be set') }
24
- image_tag = "#{image}:#{tag}"
25
- after_scripts = @app.yaml.fetch('after_scripts', []).map { |config| load_after_script(config) }
26
-
27
- scheduler.deploy(image_tag, env, app_port, docker_labels, front, force: force)
23
+ app = Container.new(
24
+ 'image_tag' => "#{image}:#{tag}",
25
+ 'docker_labels' => @app.yaml.fetch('docker_labels', {}),
26
+ )
27
+ scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config) }
28
28
 
29
- after_scripts.each(&:after_deploy)
29
+ scripts.each { |script| script.before_deploy(app) }
30
+ scheduler.deploy(app, env, app_port, front, force: force)
31
+ scripts.each { |script| script.after_deploy(app) }
30
32
  end
31
33
 
32
34
  def oneshot(commands, tag: 'latest')
@@ -34,7 +36,7 @@ module Hako
34
36
  scheduler = load_scheduler(@app.yaml['scheduler'])
35
37
  image = @app.yaml.fetch('image') { raise Error.new('image must be set') }
36
38
  image_tag = "#{image}:#{tag}"
37
- exit scheduler.oneshot(image_tag, env, commands)
39
+ exit scheduler.oneshot(Container.new('image_tag' => image_tag), env, commands)
38
40
  end
39
41
 
40
42
  def status
@@ -42,9 +44,9 @@ module Hako
42
44
  end
43
45
 
44
46
  def remove
45
- after_scripts = @app.yaml.fetch('after_scripts', []).map { |config| load_after_script(config) }
47
+ scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config) }
46
48
  load_scheduler(@app.yaml['scheduler']).remove
47
- after_scripts.each(&:after_remove)
49
+ scripts.each(&:after_remove)
48
50
  end
49
51
 
50
52
  private
@@ -81,10 +83,10 @@ module Hako
81
83
  Hako::Fronts.const_get(camelize(front_config.type)).new(front_config)
82
84
  end
83
85
 
84
- def load_after_script(config)
86
+ def load_script(config)
85
87
  type = config.fetch('type')
86
- require "hako/after_scripts/#{type}"
87
- Hako::AfterScripts.const_get(camelize(type)).new(@app, config)
88
+ require "hako/scripts/#{type}"
89
+ Hako::Scripts.const_get(camelize(type)).new(@app, config)
88
90
  end
89
91
 
90
92
  def camelize(name)
@@ -0,0 +1,20 @@
1
+ module Hako
2
+ class Container
3
+ def initialize(definition)
4
+ @definition = definition
5
+ end
6
+
7
+ %w[
8
+ image_tag
9
+ docker_labels
10
+ ].each do |name|
11
+ define_method(name) do
12
+ @definition[name]
13
+ end
14
+
15
+ define_method("#{name}=") do |val|
16
+ @definition[name] = val
17
+ end
18
+ end
19
+ end
20
+ end
@@ -8,7 +8,7 @@ module Hako
8
8
  def initialize(_app_id, _options)
9
9
  end
10
10
 
11
- def deploy(_image_tag, _env, _app_port, _docker_labels, _front_config, _options)
11
+ def deploy(_app, _env, _app_port, _front_config, _options)
12
12
  raise NotImplementedError
13
13
  end
14
14
 
@@ -7,16 +7,16 @@ module Hako
7
7
  @app_id = app_id
8
8
  end
9
9
 
10
- def deploy(image_tag, env, app_port, _docker_labels, _front, force: false)
11
- puts "Deploy #{image_tag} with app_port=#{app_port}, force=#{force}"
10
+ def deploy(app, env, app_port, _front, force: false)
11
+ puts "Deploy #{app.image_tag} with app_port=#{app_port}, force=#{force}"
12
12
  puts 'Environment variables:'
13
13
  env.each do |key, val|
14
14
  puts " #{key}=#{val.inspect}"
15
15
  end
16
16
  end
17
17
 
18
- def oneshot(image_tag, env, commands)
19
- puts "Run #{image_tag} with oneshot commands=#{commands.inspect}"
18
+ def oneshot(app, env, commands)
19
+ puts "Run #{app.image_tag} with oneshot commands=#{commands.inspect}"
20
20
  puts 'Environment variables:'
21
21
  env.each do |key, val|
22
22
  puts " #{key}=#{val.inspect}"
@@ -23,7 +23,7 @@ module Hako
23
23
  @ec2 = Aws::EC2::Client.new(region: region)
24
24
  end
25
25
 
26
- def deploy(image_tag, env, app_port, docker_labels, front, force: false)
26
+ def deploy(app, env, app_port, front, force: false)
27
27
  @force_mode = force
28
28
  front_env = {
29
29
  'AWS_DEFAULT_REGION' => front.config.s3.region,
@@ -31,7 +31,7 @@ module Hako
31
31
  'S3_CONFIG_KEY' => front.config.s3.key(@app_id),
32
32
  }
33
33
  front_port = determine_front_port
34
- task_definition = register_task_definition(image_tag, env, docker_labels, front.config, front_env, front_port)
34
+ task_definition = register_task_definition(app, env, front.config, front_env, front_port)
35
35
  if task_definition == :noop
36
36
  Hako.logger.info "Task definition isn't changed"
37
37
  task_definition = @ecs.describe_task_definition(task_definition: @app_id).task_definition
@@ -50,8 +50,8 @@ module Hako
50
50
  Hako.logger.info 'Deployment completed'
51
51
  end
52
52
 
53
- def oneshot(image_tag, env, commands)
54
- task_definition = register_task_definition_for_oneshot(image_tag)
53
+ def oneshot(app, env, commands)
54
+ task_definition = register_task_definition_for_oneshot(app)
55
55
  Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
56
56
  task = run_task(task_definition, env, commands)
57
57
  Hako.logger.info "Started task: #{task.task_arn}"
@@ -195,26 +195,26 @@ module Hako
195
195
  EcsDefinitionComparator.new(expected_container).different?(actual_container)
196
196
  end
197
197
 
198
- def register_task_definition(image_tag, env, docker_labels, front_config, front_env, front_port)
199
- front = front_container(front_config, front_env, front_port)
200
- app = app_container(image_tag, env, docker_labels)
201
- if task_definition_changed?(front, app)
198
+ def register_task_definition(app, env, front_config, front_env, front_port)
199
+ front_def = front_container(front_config, front_env, front_port)
200
+ app_def = app_container(app, env)
201
+ if task_definition_changed?(front_def, app_def)
202
202
  @ecs.register_task_definition(
203
203
  family: @app_id,
204
- container_definitions: [front, app],
204
+ container_definitions: [front_def, app_def],
205
205
  ).task_definition
206
206
  else
207
207
  :noop
208
208
  end
209
209
  end
210
210
 
211
- def register_task_definition_for_oneshot(image_tag)
211
+ def register_task_definition_for_oneshot(app)
212
212
  @ecs.register_task_definition(
213
213
  family: "#{@app_id}-oneshot",
214
214
  container_definitions: [
215
215
  {
216
216
  name: 'oneshot',
217
- image: image_tag,
217
+ image: app.image_tag,
218
218
  cpu: @cpu,
219
219
  memory: @memory,
220
220
  links: [],
@@ -239,18 +239,18 @@ module Hako
239
239
  }
240
240
  end
241
241
 
242
- def app_container(image_tag, env, docker_labels)
242
+ def app_container(app, env)
243
243
  environment = env.map { |k, v| { name: k, value: v } }
244
244
  {
245
245
  name: 'app',
246
- image: image_tag,
246
+ image: app.image_tag,
247
247
  cpu: @cpu,
248
248
  memory: @memory,
249
249
  links: [],
250
250
  port_mappings: [],
251
251
  essential: true,
252
252
  environment: environment,
253
- docker_labels: docker_labels,
253
+ docker_labels: app.docker_labels,
254
254
  }
255
255
  end
256
256
 
@@ -1,4 +1,4 @@
1
1
  module Hako
2
- module AfterScripts
2
+ module Scripts
3
3
  end
4
4
  end
data/lib/hako/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hako
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hako
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
@@ -118,10 +118,10 @@ files:
118
118
  - exe/hako
119
119
  - hako.gemspec
120
120
  - lib/hako.rb
121
- - lib/hako/after_scripts.rb
122
121
  - lib/hako/application.rb
123
122
  - lib/hako/cli.rb
124
123
  - lib/hako/commander.rb
124
+ - lib/hako/container.rb
125
125
  - lib/hako/env_expander.rb
126
126
  - lib/hako/env_provider.rb
127
127
  - lib/hako/env_providers.rb
@@ -137,6 +137,7 @@ files:
137
137
  - lib/hako/schedulers/ecs.rb
138
138
  - lib/hako/schedulers/ecs_definition_comparator.rb
139
139
  - lib/hako/schedulers/ecs_elb.rb
140
+ - lib/hako/scripts.rb
140
141
  - lib/hako/templates/nginx.conf.erb
141
142
  - lib/hako/templates/nginx.location.conf.erb
142
143
  - lib/hako/version.rb