Class: Seira::App

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/seira/app.rb

Constant Summary collapse

VALID_ACTIONS =
%w[help bootstrap apply restart scale revision].freeze
SUMMARY =
"Bootstrap, scale, configure, restart, your apps.".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#gcloud, gcloud, kubectl, #kubectl, #tsh, tsh

Constructor Details

#initialize(app:, action:, args:, context:) ⇒ App

Returns a new instance of App.



16
17
18
19
20
21
# File 'lib/seira/app.rb', line 16

def initialize(app:, action:, args:, context:)
  @app = app
  @action = action
  @args = args
  @context = context
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



14
15
16
# File 'lib/seira/app.rb', line 14

def action
  @action
end

#appObject (readonly)

Returns the value of attribute app.



14
15
16
# File 'lib/seira/app.rb', line 14

def app
  @app
end

#argsObject (readonly)

Returns the value of attribute args.



14
15
16
# File 'lib/seira/app.rb', line 14

def args
  @args
end

#contextObject (readonly)

Returns the value of attribute context.



14
15
16
# File 'lib/seira/app.rb', line 14

def context
  @context
end

Instance Method Details

#ask_cluster_for_current_revisionObject



56
57
58
59
60
61
# File 'lib/seira/app.rb', line 56

def ask_cluster_for_current_revision
  tier = context[:settings].config_for_app(app)['golden_tier'] || 'web'
  current_image = kubectl("get deployment -l app=#{app},tier=#{tier} -o=jsonpath='{$.items[:1].spec.template.spec.containers[:1].image}'", context: context, return_output: true).strip.chomp
  current_revision = current_image.split(':').last
  current_revision
end

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/seira/app.rb', line 23

def run
  case action
  when 'help'
    run_help
  when 'bootstrap'
    run_bootstrap
  when 'apply'
    run_apply
  when 'restart'
    run_restart
  when 'scale'
    run_scale
  when 'revision'
    run_revision
  else
    fail "Unknown command encountered"
  end
end

#run_helpObject



42
43
44
45
46
47
48
49
50
# File 'lib/seira/app.rb', line 42

def run_help
  puts SUMMARY
  puts "\n\n"
  puts "Possible actions:\n\n"
  puts "bootstrap: Create new app with main secret, cloudsql secret, and gcr secret in the new namespace."
  puts "apply: Apply the configuration in kubernetes/<cluster-name>/<app-name> using first argument or REVISION environment variable to find/replace REVISION in the YAML."
  puts "restart: Forces a rolling deploy for any deployment making use of RESTARTED_AT_VALUE in the deployment."
  puts "scale: Scales the given tier deployment to the specified number of instances."
end

#run_restartObject



52
53
54
# File 'lib/seira/app.rb', line 52

def run_restart
  run_apply(restart: true)
end