Class: Pfab::Yamls

Inherits:
Object
  • Object
show all
Defined in:
lib/pfab/yamls.rb

Instance Method Summary collapse

Constructor Details

#initialize(apps:, application_yaml:, image_name:, env:, sha:, config:) ⇒ Yamls

Returns a new instance of Yamls.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/pfab/yamls.rb', line 5

def initialize(apps:, application_yaml:, image_name:, env:, sha:, config:)
  @apps = apps
  @base_data = {
    "env" => env.to_s,
    'image_name' => image_name,
    'sha' => sha,
    'container_repository' => config["container.repository"],
    'config' => config,
    'application' => application_yaml["name"],
    'application_yaml' => application_yaml
  }
end

Instance Method Details

#data_for(app, props) ⇒ Object



23
24
25
26
27
28
# File 'lib/pfab/yamls.rb', line 23

def data_for(app, props)
  data = @base_data.clone
  data['props'] = props
  data['deployed_name'] = app
  data
end

#env_vars(app) ⇒ Object



18
19
20
21
# File 'lib/pfab/yamls.rb', line 18

def env_vars(app)
  template = Pfab::Templates::Base.new(data_for(app, @apps[app]))
  template.env_vars
end

#generate(keys) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pfab/yamls.rb', line 30

def generate(keys)

  keys.each do |key|
    props = @apps[key]
    data = data_for(key, props)

    filename = ".application-k8s-#{data["env"]}-#{key}.yaml"
    File.open(filename, "w") do |f|
      case props[:deployable_type]
      when "web" then
        processed = Pfab::Templates::Web.new(data).write_to(f)
      when "job" then
        processed = Pfab::Templates::Job.new(data).write_to(f)
      when "daemon" then
        processed = Pfab::Templates::Daemon.new(data).write_to(f)
      when "cron" then
        processed = Pfab::Templates::Cron.new(data).write_to(f)
      end
    end
    filename
  end

end