Class: Iota::CLI::Deploy
- Inherits:
-
Object
- Object
- Iota::CLI::Deploy
- Defined in:
- lib/iota/cli/deploy.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#thor ⇒ Object
readonly
Returns the value of attribute thor.
Instance Method Summary collapse
-
#initialize(options, environment, thor) ⇒ Deploy
constructor
A new instance of Deploy.
- #run ⇒ Object
Constructor Details
#initialize(options, environment, thor) ⇒ Deploy
Returns a new instance of Deploy.
7 8 9 10 11 12 |
# File 'lib/iota/cli/deploy.rb', line 7 def initialize(, environment, thor) = @environment = environment @thor = thor @path = [:path] || '.' end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'lib/iota/cli/deploy.rb', line 5 def environment @environment end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/iota/cli/deploy.rb', line 5 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/iota/cli/deploy.rb', line 5 def path @path end |
#thor ⇒ Object (readonly)
Returns the value of attribute thor.
5 6 7 |
# File 'lib/iota/cli/deploy.rb', line 5 def thor @thor end |
Instance Method Details
#run ⇒ Object
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/iota/cli/deploy.rb', line 14 def run unless File.exists?('./iota.conf') thor.say("Config file ('./iota.conf') is missing.", :red) return end thor.say("Loading configuration.", :yellow) config = YAML.load_file('./iota.conf') thor.say("Done.", :blue) unless Iota::Function::ENVIRONMENT_ALIAS_NAME_MAP.keys.include?(environment) thor.say("Invalid environment #{environment}. \\ Please specify either 'production' or 'development'.", :red) return end # TODO: not found function_name = config['function_name'] function = Iota::Function.new(function_name, path) if function.exists? thor.say("Updating code...", :yellow) function.update_code thor.say("Done.", :blue) new_version = function.publish_version.version thor.say("Latest code is published as version:#{new_version}.", :yellow) aliases = function.list_aliases new_version_alias_name = Iota::Function::ENVIRONMENT_ALIAS_NAME_MAP[environment] last_version_alias_name = new_version_alias_name + Iota::Function::LAST_VERSION_SUFFIX last_version_alias = aliases.select{|a| a.name == last_version_alias_name}.first new_version_alias = aliases.select{|a| a.name == new_version_alias_name}.first # last -> prod/dev, prod/dev -> new_version unless last_version_alias.nil? || new_version_alias.nil? thor.say("Updating aliases...", :yellow) function.update_alias(last_version_alias_name, new_version_alias.function_version) function.update_alias(new_version_alias_name, new_version) thor.say("Done.", :blue) else thor.say("There's no aliases with name '#{last_version_alias_name}' \ and/or '#{new_version_alias_name}'.", :red) end else thor.say("Function '#{function_name}' doesn't seem to be exists.", :yellow) y_or_n = thor.ask("Do you want to create new function '#{function_name}' ? (y/n)") if y_or_n =~ /[yY]/ thor.say("Creating function '#{function_name}' ...", :yellow) begin function.create_function(config['runtime'], config['role']) rescue ArgumentError thor.say("ArgumentError occured. You might need to specify role arn \ you want to pass to your function via 'iota.conf' file or ENV['AWS_LAMBDA_IAM_ROLE'].", :red) return end thor.say("Done.", :blue) thor.say("Setting aliases.", :yellow) first_version = function.publish_version.version Iota::Function::ENVIRONMENT_ALIAS_NAME_MAP.values.each do |alias_name| function.create_alias(alias_name, first_version) function.create_alias(alias_name << '_LAST', first_version) end thor.say("Done.") end end end |