Class: Pfab::Yamls

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

Class Method Summary collapse

Class Method Details

.generate_for(apps:, application_yaml:, image_name:, env:, sha:, config:) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pfab/yamls.rb', line 4

def self.generate_for(apps:, application_yaml:, image_name:, env:, sha:, config:)

  apps.map do |app, props|
    puts app

    data = {
      "env" => env.to_s,
      'image_name' => image_name,
      'sha' => sha,
      'container_repository' => config["container.repository"],
      'config' => config,
      'props' => props,
      'deployed_name' => app,
      'application' => application_yaml["name"],
      'application_yaml' => application_yaml
    }

    filename = ".application-k8s-#{env}-#{app}.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