hako 0.9.4 → 0.10.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: e2f20543086d4292c74952e667ec1fa478ff5523
4
- data.tar.gz: 44621548e4f4fb71afccfc1dce353c12c4d1b698
3
+ metadata.gz: 790a66a0b27267656b3f0b5b39a81fa2b54ee772
4
+ data.tar.gz: 08bdb98df7dda625874ecb89a0d2b1d2dec14da6
5
5
  SHA512:
6
- metadata.gz: ea22eaa39ae95445b241f8952c5642b2bcdc5782376e620be9f858a747a9af9f264927dbf794aaee862b5aa108b12c49c9fc134d7a89411f673b9ba6c54ba9af
7
- data.tar.gz: 59ce8bf11524a1e186735c02b9a110d447e065aee375bf4df31b49a286e1ca322ceb0caf0ab5c48ce6a70bc745ab3189e4c1bf78d7586dd7d27a163ab844cd85
6
+ metadata.gz: cf57c0ce8f75f05fc37709da163324b520dc36912aeb9e6065a218f64311309255512455eae6ac0891c1fe1d428e00c251a14468ea2f0498d303a35abfff3549
7
+ data.tar.gz: e2bf166333f4cda8fe99f5ea22d51a88131991278b6191e4b5ed3e14217559dd5e15b424783212fb91ce3342e7f726a7726ddccaad66d7fa4c6a0ba2a186ce64
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'hako/app_container'
3
- require 'hako/container'
2
+ require 'hako/definition_loader'
4
3
  require 'hako/env_expander'
5
4
  require 'hako/error'
6
- require 'hako/fronts'
7
5
  require 'hako/loader'
8
6
  require 'hako/schedulers'
9
7
  require 'hako/scripts'
@@ -76,35 +74,13 @@ module Hako
76
74
  end
77
75
 
78
76
  def load_containers(tag, dry_run:, with: nil)
79
- app = AppContainer.new(@app, @app.yaml['app'].merge('tag' => tag), dry_run: dry_run)
80
- front =
81
- if @app.yaml.key?('front')
82
- load_front(@app.yaml['front'], dry_run: dry_run)
83
- end
84
-
85
- containers = { 'app' => app, 'front' => front }
86
- @app.yaml.fetch('additional_containers', {}).each do |name, container|
87
- containers[name] = Container.new(@app, container, dry_run: dry_run)
88
- end
89
- if with
90
- keys = ['app'] + with
91
- containers.keys.each do |key|
92
- unless keys.include?(key)
93
- containers.delete(key)
94
- end
95
- end
96
- end
97
- containers
77
+ DefinitionLoader.new(@app, dry_run: dry_run).load(tag, with: with)
98
78
  end
99
79
 
100
80
  def load_scheduler(yaml, scripts, force: false, dry_run: false)
101
81
  Loader.new(Hako::Schedulers, 'hako/schedulers').load(yaml.fetch('type')).new(@app.id, yaml, scripts: scripts, force: force, dry_run: dry_run)
102
82
  end
103
83
 
104
- def load_front(yaml, dry_run:)
105
- Loader.new(Hako::Fronts, 'hako/fronts').load(yaml.fetch('type')).new(@app, yaml, dry_run: dry_run)
106
- end
107
-
108
84
  def load_script(yaml, dry_run:)
109
85
  Loader.new(Hako::Scripts, 'hako/scripts').load(yaml.fetch('type')).new(@app, yaml, dry_run: dry_run)
110
86
  end
@@ -3,6 +3,8 @@ require 'hako/version'
3
3
 
4
4
  module Hako
5
5
  class Container
6
+ attr_reader :definition
7
+
6
8
  def initialize(app, definition, dry_run:)
7
9
  @app = app
8
10
  @definition = default_config.merge(definition)
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'set'
3
+ require 'hako/app_container'
4
+ require 'hako/container'
5
+ require 'hako/fronts'
6
+ require 'hako/loader'
7
+
8
+ module Hako
9
+ class DefinitionLoader
10
+ def initialize(app, dry_run:)
11
+ @app = app
12
+ @dry_run = dry_run
13
+ end
14
+
15
+ def load(tag, with: nil)
16
+ additional_containers = @app.yaml.fetch('additional_containers', {})
17
+ container_names = ['app']
18
+ if with
19
+ container_names.concat(with)
20
+ else
21
+ if @app.yaml.key?('front')
22
+ container_names << 'front'
23
+ end
24
+ container_names.concat(additional_containers.keys)
25
+ end
26
+
27
+ load_containers_from_name(tag, container_names, additional_containers)
28
+ end
29
+
30
+ private
31
+
32
+ def load_containers_from_name(tag, container_names, additional_containers)
33
+ names = Set.new(container_names)
34
+ containers = {}
35
+ while containers.size < names.size
36
+ names.difference(containers.keys).each do |name|
37
+ containers[name] =
38
+ case name
39
+ when 'app'
40
+ AppContainer.new(@app, @app.yaml['app'].merge('tag' => tag), dry_run: @dry_run)
41
+ when 'front'
42
+ load_front(@app.yaml['front'], dry_run: @dry_run)
43
+ else
44
+ Container.new(@app, additional_containers.fetch(name), dry_run: @dry_run)
45
+ end
46
+
47
+ containers[name].links.each do |link|
48
+ m = link.match(/\A([^:]+):([^:]+)\z/)
49
+ names << (m ? m[1] : link)
50
+ end
51
+ end
52
+ end
53
+ containers
54
+ end
55
+
56
+ def load_front(yaml, dry_run:)
57
+ Loader.new(Hako::Fronts, 'hako/fronts').load(yaml.fetch('type')).new(@app, yaml, dry_run: dry_run)
58
+ end
59
+ end
60
+ end
data/lib/hako/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hako
3
- VERSION = '0.9.4'
3
+ VERSION = '0.10.0'
4
4
  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.9.4
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
@@ -110,6 +110,7 @@ files:
110
110
  - lib/hako/cli.rb
111
111
  - lib/hako/commander.rb
112
112
  - lib/hako/container.rb
113
+ - lib/hako/definition_loader.rb
113
114
  - lib/hako/env_expander.rb
114
115
  - lib/hako/env_provider.rb
115
116
  - lib/hako/env_providers.rb