Class: MarathonDeploy::Application
- Inherits:
-
Object
- Object
- MarathonDeploy::Application
- Defined in:
- lib/marathon_deploy/application.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #add_envs(envs) ⇒ Object
- #add_identifier ⇒ Object
-
#env ⇒ JSON
List of ENV variables for this application.
- #health_checks ⇒ Object
-
#initialize(options = { :force => false, :deployfile => 'deploy.yml', :remove_elements => []}) ⇒ Application
constructor
Models an application to be added converted to json and send to the marathon-api.
- #instances ⇒ Object
- #overlay_preproduction_settings ⇒ Object
- #remove_elements(remove_array) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = { :force => false, :deployfile => 'deploy.yml', :remove_elements => []}) ⇒ Application
Models an application to be added converted to json and send to the marathon-api
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 |
# File 'lib/marathon_deploy/application.rb', line 16 def initialize(={ :force => false, :deployfile => 'deploy.yml', :remove_elements => []}) deployfile = [:deployfile] if (!File.exist?(deployfile)) = "\'#{File.expand_path(deployfile)}\' not found." raise Error::IOError, , caller end extension = File.extname(deployfile) case extension when '.json' @json = YamlJson.read_json_w_macros(deployfile) when '.yaml','.yml' @json = YamlJson.yaml2json(deployfile) else = "File extension #{extension} is not supported for deployment file #{deployfile}" raise Error::UnsupportedFileExtension, , caller end # JSON fix for marathon # marathon require ENV variables to be quoted @json['env'].each do |key, value| if (value.is_a? Numeric) @json['env'][key] = value.to_json end end missing_attributes = MarathonDefaults.missing_attributes(@json) if(!missing_attributes.empty?) = "#{deployfile} is missing required marathon API attributes: #{missing_attributes.join(',')}" raise Error::MissingMarathonAttributesError, , caller end missing_envs = MarathonDefaults.missing_envs(@json) if(!missing_envs.empty?) = "#{deployfile} is missing required environment variables: #{missing_envs.join(',')}" raise Error::MissingMarathonAttributesError, , caller end @deployfile = deployfile @json = Utils.deep_symbolize(@json) add_identifier if ([:force]) remove_elements([:remove_elements]) inject_envs = ENV.select { |k,v| /^#{MarathonDeploy::MarathonDefaults::ENVIRONMENT_VARIABLE_PREFIX}/.match(k) } cleaned_envs = Hash[inject_envs.map { |k,v| [k.gsub(/^#{MarathonDeploy::MarathonDefaults::ENVIRONMENT_VARIABLE_PREFIX}/,''), v ] }] self.add_envs cleaned_envs.to_h unless cleaned_envs.empty? end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/marathon_deploy/application.rb', line 10 def id @id end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
10 11 12 |
# File 'lib/marathon_deploy/application.rb', line 10 def json @json end |
Instance Method Details
#add_envs(envs) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/marathon_deploy/application.rb', line 104 def add_envs(envs) if (envs.is_a?(Hash)) envs.each do |key,value| if (value.is_a? Numeric) @json[:env][key] = value.to_json else @json[:env][key] = value end end else raise Error::BadFormatError, "argument must be a hash", caller end end |
#add_identifier ⇒ Object
77 78 79 80 81 |
# File 'lib/marathon_deploy/application.rb', line 77 def add_identifier random = Utils.random # Time.now.to_i @json[:env]['UNIQUE_ID'] = "#{id}_#{random}" end |
#env ⇒ JSON
Returns list of ENV variables for this application.
96 97 98 |
# File 'lib/marathon_deploy/application.rb', line 96 def env @json[:env] end |
#health_checks ⇒ Object
73 74 75 |
# File 'lib/marathon_deploy/application.rb', line 73 def health_checks @json[:healthChecks] end |
#instances ⇒ Object
118 119 120 |
# File 'lib/marathon_deploy/application.rb', line 118 def instances @json[:instances] end |
#overlay_preproduction_settings ⇒ Object
69 70 71 |
# File 'lib/marathon_deploy/application.rb', line 69 def @json = MarathonDefaults.(@json) end |
#remove_elements(remove_array) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/marathon_deploy/application.rb', line 83 def remove_elements(remove_array) if (remove_array.is_a?(Array)) remove_array.each do |element| @json.delete(element) end end end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/marathon_deploy/application.rb', line 91 def to_s JSON.pretty_generate(@json) end |