hako 0.8.5 → 0.9.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: 872f90813b982a8a19c5b4cf901aa06eb401216b
4
- data.tar.gz: 02e799d33ceaa061a85578b48929b2eaa4c0922c
3
+ metadata.gz: 2ed263f551648e6f8339ae4493a1346edef6ac80
4
+ data.tar.gz: 4d10d78c93bef27b471759c828d26bb6ad5c896c
5
5
  SHA512:
6
- metadata.gz: f6089d93829d5c5866857bb10104a5a145801efd7ca3672aec0e6e58704d735416404a435b780d0f5d897a0c838de545c3ea051e060584f5a4db8a28d0aeb824
7
- data.tar.gz: 50227fd8d3abfff03896b85fbb96a9deb9c53246e26c05724d9e0bc01d30cb53c70b1d3667ef782751b80da7003381ce738fa3f63cc5b8dab6c45e8acf3937a6
6
+ metadata.gz: b71c6b89b1316596432acbad9b9114fb893210d8810b8583478db132e8e43fa77ad02b98522d4536fe9bcb76e4039d788dd1b3675ffe1f3742eb989cea648d23
7
+ data.tar.gz: e2de4aa6a1bfc2c7c67887ec472c108cc88a07beed8fd8e22e949024d4c910cba05c5dc8332fb2169df4f9dedd9d81646f53aed11d7665ef2b2e58cff0a96081
@@ -21,7 +21,7 @@ app:
21
21
  env:
22
22
  $providers:
23
23
  - type: file
24
- path: examples/hello.env
24
+ path: hello.env
25
25
  PORT: 3000
26
26
  MESSAGE: '#{username}-san'
27
27
  front:
@@ -24,21 +24,23 @@ module Hako
24
24
  scripts.each { |script| script.after_deploy(containers) }
25
25
  end
26
26
 
27
- def oneshot(commands, tag:, containers:, env: {})
28
- containers = load_containers(tag, dry_run: false, with: containers)
29
- scheduler = load_scheduler(@app.yaml['scheduler'])
27
+ def oneshot(commands, tag:, containers:, env: {}, dry_run: false)
28
+ containers = load_containers(tag, dry_run: dry_run, with: containers)
29
+ scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
30
+ scheduler = load_scheduler(@app.yaml['scheduler'], scripts)
31
+
30
32
  with_oneshot_signal_handlers(scheduler) do
31
33
  exit scheduler.oneshot(containers, commands, env)
32
34
  end
33
35
  end
34
36
 
35
37
  def status
36
- load_scheduler(@app.yaml['scheduler']).status
38
+ load_scheduler(@app.yaml['scheduler'], []).status
37
39
  end
38
40
 
39
41
  def remove
40
42
  scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
41
- load_scheduler(@app.yaml['scheduler']).remove
43
+ load_scheduler(@app.yaml['scheduler'], scripts).remove
42
44
  scripts.each(&:after_remove)
43
45
  end
44
46
 
@@ -89,8 +91,8 @@ module Hako
89
91
  containers
90
92
  end
91
93
 
92
- def load_scheduler(yaml, force: false, dry_run: false)
93
- Loader.new(Hako::Schedulers, 'hako/schedulers').load(yaml.fetch('type')).new(@app.id, yaml, force: force, dry_run: dry_run)
94
+ def load_scheduler(yaml, scripts, force: false, dry_run: false)
95
+ Loader.new(Hako::Schedulers, 'hako/schedulers').load(yaml.fetch('type')).new(@app.id, yaml, scripts: scripts, force: force, dry_run: dry_run)
94
96
  end
95
97
 
96
98
  def load_front(yaml, dry_run:)
@@ -6,7 +6,15 @@ module Hako
6
6
  class ValidationError < Error
7
7
  end
8
8
 
9
- def initialize(_app_id, _options)
9
+ def initialize(app_id, options, scripts:, dry_run:, force:)
10
+ @app_id = app_id
11
+ @scripts = scripts
12
+ @dry_run = dry_run
13
+ @force = force
14
+ configure(options)
15
+ end
16
+
17
+ def configure(_options)
10
18
  end
11
19
 
12
20
  def deploy(_containers, _options)
@@ -4,19 +4,17 @@ require 'hako/scheduler'
4
4
  module Hako
5
5
  module Schedulers
6
6
  class Echo < Scheduler
7
- def initialize(app_id, _options)
8
- @app_id = app_id
9
- end
10
-
11
- def deploy(containers, env, app_port, force: false)
12
- puts "Deploy #{containers.fetch('app').image_tag} with app_port=#{app_port}, force=#{force}"
7
+ def deploy(containers)
8
+ app = containers.fetch('app')
9
+ puts "Deploy #{app.image_tag} with app_port=#{app.port}, force=#{@force}, dry_run=#{@dry_run}"
13
10
  puts 'Environment variables:'
14
- env.each do |key, val|
11
+ app.env.each do |key, val|
15
12
  puts " #{key}=#{val.inspect}"
16
13
  end
17
14
  end
18
15
 
19
- def oneshot(app, env, commands)
16
+ def oneshot(containers, commands, env)
17
+ app = containers.fetch('app')
20
18
  puts "Run #{app.image_tag} with oneshot commands=#{commands.inspect}"
21
19
  puts 'Environment variables:'
22
20
  env.each do |key, val|
@@ -11,17 +11,16 @@ module Hako
11
11
  DEFAULT_CLUSTER = 'default'
12
12
  DEFAULT_FRONT_PORT = 10000
13
13
 
14
- def initialize(app_id, options, force:, dry_run:)
15
- @app_id = app_id
14
+ attr_reader :task
15
+
16
+ def configure(options)
16
17
  @cluster = options.fetch('cluster', DEFAULT_CLUSTER)
17
18
  @desired_count = options.fetch('desired_count') { validation_error!('desired_count must be set') }
18
19
  region = options.fetch('region') { validation_error!('region must be set') }
19
20
  @role = options.fetch('role', nil)
20
21
  @ecs = Aws::ECS::Client.new(region: region)
21
- @elb = EcsElb.new(app_id, Aws::ElasticLoadBalancing::Client.new(region: region), options.fetch('elb', nil))
22
+ @elb = EcsElb.new(@app_id, Aws::ElasticLoadBalancing::Client.new(region: region), options.fetch('elb', nil))
22
23
  @ec2 = Aws::EC2::Client.new(region: region)
23
- @force = force
24
- @dry_run = dry_run
25
24
  @started_at = nil
26
25
  @container_instance_arn = nil
27
26
  end
@@ -71,6 +70,7 @@ module Hako
71
70
  end
72
71
  @task = run_task(task_definition, commands, env)
73
72
  Hako.logger.info "Started task: #{@task.task_arn}"
73
+ @scripts.each { |script| script.oneshot_started(self) }
74
74
  wait_for_oneshot_finish
75
75
  end
76
76
 
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'hako/scripts'
3
+
4
+ module Hako
5
+ class Script
6
+ def initialize(app, options, dry_run:)
7
+ @app = app
8
+ @dry_run = dry_run
9
+ configure(options)
10
+ end
11
+
12
+ def configure(_options)
13
+ end
14
+
15
+ def before_deploy(_containers)
16
+ end
17
+
18
+ def after_deploy(_containers)
19
+ end
20
+
21
+ def oneshot_started(_scheduler)
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hako
3
- VERSION = '0.8.5'
3
+ VERSION = '0.9.0'
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.5
4
+ version: 0.9.0
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-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -125,6 +125,7 @@ files:
125
125
  - lib/hako/schedulers/ecs.rb
126
126
  - lib/hako/schedulers/ecs_definition_comparator.rb
127
127
  - lib/hako/schedulers/ecs_elb.rb
128
+ - lib/hako/script.rb
128
129
  - lib/hako/scripts.rb
129
130
  - lib/hako/templates/nginx.conf.erb
130
131
  - lib/hako/templates/nginx.location.conf.erb