Class: Eien::Deploy::ApplyTask

Inherits:
Task
  • Object
show all
Defined in:
lib/eien/deploy/apply_task.rb

Instance Attribute Summary collapse

Attributes inherited from Task

#context, #namespace, #task_config

Instance Method Summary collapse

Methods included from Helpers::TimeHelpers

#summarize_age

Constructor Details

#initialize(context, app) ⇒ ApplyTask

Returns a new instance of ApplyTask.



8
9
10
11
# File 'lib/eien/deploy/apply_task.rb', line 8

def initialize(context, app)
  @app = app
  super(context)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/eien/deploy/apply_task.rb', line 6

def app
  @app
end

Instance Method Details

#run!Object



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
38
39
40
41
42
43
44
# File 'lib/eien/deploy/apply_task.rb', line 13

def run!
  the_app = Eien.app_from_name(context, app)
  app_name = the_app..name

  resources = ::Eien::Deploy::GenerateTask.new(context, app_name).run!

  temp_file = Tempfile.new(["eien_generated_resources", ".yaml"])
  begin
    resources.map do |resource|
      temp_file.write(resource.to_h.deep_stringify_keys.to_yaml)
    end

    temp_file.close

    deploy_options = Krane::CLI::DeployCommand::OPTIONS
      .each_with_object(HashWithIndifferentAccess.new) do |(key, option), options|
      options[key] = option[:default]
    end

    deploy_options[:filenames] << temp_file.path
    deploy_options[:selector] = "#{::Eien::LABEL_PREFIX}/app=#{app_name}"

    Krane::CLI::DeployCommand.from_options(
      the_app.spec.namespace,
      context,
      deploy_options,
    )
  ensure
    temp_file.close
    temp_file.unlink
  end
end