marathon_deploy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3a0f127044b188815965b3e84ab4557089fba6c
4
- data.tar.gz: 914fee4de65ceb166a9790fa4ca1b6d84af8981d
3
+ metadata.gz: 2064827ef363519d13290fa9e84e34b37d15a954
4
+ data.tar.gz: 9bb6235b0c8b3421cb3904561a67d022a6a72f5d
5
5
  SHA512:
6
- metadata.gz: 3b380869cd355157e8f323de645cd8b5da55be01241447e1bb6e0dfe3bb6ba0ec697b61facc3255fa5e1b1a3c576083dca6dca7c5b9bb1f419ccc8bbd6e17f7a
7
- data.tar.gz: 7244d59e9504ec09c195ff4bf73a0fca16030644c29bbbc036cc59f57152c17bca2e08b2f5a1237305a500cfe333040f9735acb83293b4341d8cb982c2b0c43d
6
+ metadata.gz: 652ed65844e48852e55d1eb8a69436ab042df65139c0c7af24c3d34f94008a511c6275a68aaf6e94499a01bceba4dfdf3e00149484350b2cb6b7dab10a461651
7
+ data.tar.gz: 7be0be184f7d07d62e2457965e1d1723a03fa926c0bb6e633b5b1f970d8e359ed81e42b18dafb122f4b5b02add40d87d76e29fbf23ff6e43bcf115948560af7d
data/bin/deploy.rb CHANGED
@@ -11,11 +11,11 @@ require 'logger'
11
11
  options = {}
12
12
 
13
13
  # DEFAULTS
14
- options[:deployfile] = MarathonDefaults::DEFAULT_DEPLOYFILE
15
- options[:verbose] = MarathonDefaults::DEFAULT_LOGLEVEL
16
- options[:environment] = MarathonDefaults::DEFAULT_ENVIRONMENT_NAME
14
+ options[:deployfile] = MarathonDeploy::MarathonDefaults::DEFAULT_DEPLOYFILE
15
+ options[:verbose] = MarathonDeploy::MarathonDefaults::DEFAULT_LOGLEVEL
16
+ options[:environment] = MarathonDeploy::MarathonDefaults::DEFAULT_ENVIRONMENT_NAME
17
17
  options[:marathon_endpoints] = nil
18
- options[:logfile] = MarathonDefaults::DEFAULT_LOGFILE
18
+ options[:logfile] = MarathonDeploy::MarathonDefaults::DEFAULT_LOGFILE
19
19
 
20
20
  OptionParser.new do |opts|
21
21
  opts.banner = "Usage: deploy.rb [options]"
@@ -50,22 +50,22 @@ $LOG = options[:logfile] ? Logger.new(options[:logfile]) : Logger.new(STDOUT)
50
50
  $LOG.level = options[:verbose]
51
51
 
52
52
  deployfile = options[:deployfile]
53
- environment = Environment.new(options[:environment])
53
+ environment = MarathonDeploy::Environment.new(options[:environment])
54
54
 
55
55
  marathon_endpoints = Array.new
56
56
  if (options[:marathon_endpoints].nil?)
57
57
  if (environment.is_production?)
58
- marathon_endpoints = MarathonDefaults::DEFAULT_PRODUCTION_MARATHON_ENDPOINTS
58
+ marathon_endpoints = MarathonDeploy::MarathonDefaults::DEFAULT_PRODUCTION_MARATHON_ENDPOINTS
59
59
  else
60
- marathon_endpoints = MarathonDefaults::DEFAULT_PREPRODUCTION_MARATHON_ENDPOINTS
60
+ marathon_endpoints = MarathonDeploy::MarathonDefaults::DEFAULT_PREPRODUCTION_MARATHON_ENDPOINTS
61
61
  end
62
62
  else
63
63
  marathon_endpoints = options[:marathon_endpoints]
64
64
  end
65
65
 
66
66
  begin
67
- application = Application.new(deployfile)
68
- rescue Error::IOError, Error::UndefinedMacroError,Error::MissingMarathonAttributesError,Error::UnsupportedFileExtension => e
67
+ application = MarathonDeploy::Application.new(deployfile)
68
+ rescue MarathonDeploy::Error::IOError, MarathonDeploy::Error::UndefinedMacroError,MarathonDeploy::Error::MissingMarathonAttributesError,MarathonDeploy::Error::UnsupportedFileExtension => e
69
69
  $LOG.debug(e)
70
70
  $LOG.error(e.message)
71
71
  exit!
@@ -73,7 +73,7 @@ end
73
73
 
74
74
  begin
75
75
  application.add_envs({ :APPLICATION_NAME => application.id, :ENVIRONMENT => environment})
76
- rescue Error::BadFormatError => e
76
+ rescue MarathonDeploy::Error::BadFormatError => e
77
77
  $LOG.error(e)
78
78
  exit!
79
79
  end
@@ -89,16 +89,16 @@ puts "#" * 100
89
89
  # deploy to each endpoint
90
90
  marathon_endpoints.each do |marathon_url|
91
91
  begin
92
- client = MarathonClient.new(marathon_url)
92
+ client = MarathonDeploy::MarathonClient.new(marathon_url)
93
93
  client.application = application
94
94
  client.deploy
95
- rescue Error::MissingMarathonAttributesError,Error::BadURLError, Timeout::Error => e
95
+ rescue MarathonDeploy::Error::MissingMarathonAttributesError,MarathonDeploy::Error::BadURLError, Timeout::Error => e
96
96
  $LOG.error(e.message)
97
97
  exit!
98
- rescue Error::DeploymentError => e
98
+ rescue MarathonDeploy::Error::DeploymentError => e
99
99
  $LOG.error("Deployment of #{application} failed => #{e}")
100
100
  exit!
101
- rescue SocketError, Error::MarathonError => e
101
+ rescue SocketError, MarathonDeploy::Error::MarathonError => e
102
102
  $LOG.error("Problem talking to marathon endpoint => #{marathon_url} (#{e.message})")
103
103
  exit!
104
104
  end
data/bin/json2yaml.rb CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'marathon_deploy/yaml_json'
4
4
  yaml = ARGV[0]
5
- puts YamlJson.json2yaml(yaml,false)
5
+ puts MarathonDeploy::YamlJson.json2yaml(yaml,false)
@@ -4,13 +4,12 @@ cpus: 0.5
4
4
  env:
5
5
  APPLICATION_NAME: public-search-germany-webapp
6
6
  CONFIG_ASSEMBLER_BASE_URL: http://mobile-config-assembler.service.consul/config-assembler
7
- DATACENTER_NUMBER: '666'
8
7
  JAVA_XMS: 252m
9
8
  JAVA_XMX: 504m
10
9
  SERVERCLASS_NAME: pubse
11
10
  SERVICE_8009_NAME: public-search-germany-webapp
12
11
  SERVICE_8009_TAGS: ajp
13
12
  id: public-search-germany-webapp
14
- instances: 15
13
+ instances: 6
15
14
  mem: 32
16
15
  uris: []
@@ -2,17 +2,19 @@
2
2
  cmd: while true ; do echo "i got probed ..." ; /bin/nc -l -p $PORT0 ; done
3
3
  cpus: 0.5
4
4
  env:
5
+ A_MACRO_TEST: %%SPECIAL_PROPERTY%%
5
6
  APPLICATION_NAME: public-search-germany-webapp
6
7
  CONFIG_ASSEMBLER_BASE_URL: http://mobile-config-assembler.service.consul/config-assembler
7
8
  DATACENTER_NUMBER: '666'
8
9
  JAVA_XMS: 252m
9
10
  JAVA_XMX: 504m
10
- SPECIAL_PROPERTY: %%SPECIAL_PROPERTY%%
11
+ SPECIAL_PROPERTY: %%SPECIAL_PROPERTY%%%%SPECIAL_PROPERTY%%
11
12
  SERVERCLASS_NAME: pubse
12
13
  SERVICE_8009_NAME: public-search-germany-webapp
13
14
  SERVICE_8009_TAGS: ajp
15
+ ANOTHER_MACRO_TEST: %%SPECIAL_PROPERTY%%
14
16
  id: content-webapp
15
- instances: 3
17
+ instances: 6
16
18
  mem: 32
17
19
  uris: []
18
20
  healthChecks:
@@ -3,7 +3,9 @@ require 'marathon_deploy/yaml_json'
3
3
  require 'marathon_deploy/error'
4
4
  require 'marathon_deploy/utils'
5
5
 
6
- class Application
6
+ module MarathonDeploy
7
+
8
+ class Application
7
9
 
8
10
  attr_reader :json, :id
9
11
  attr_accessor :envs
@@ -82,4 +84,5 @@ class Application
82
84
  end
83
85
  end
84
86
 
87
+ end
85
88
  end
@@ -3,7 +3,8 @@ require 'marathon_deploy/utils'
3
3
  require 'marathon_deploy/marathon_defaults'
4
4
  require 'timeout'
5
5
 
6
- class Deployment
6
+ module MarathonDeploy
7
+ class Deployment
7
8
 
8
9
  DEPLOYMENT_RECHECK_INTERVAL = MarathonDefaults::DEPLOYMENT_RECHECK_INTERVAL
9
10
  DEPLOYMENT_TIMEOUT = MarathonDefaults::DEPLOYMENT_TIMEOUT
@@ -57,7 +58,7 @@ class Deployment
57
58
  #STDOUT.puts "" if ( $LOG.level == 1 )
58
59
  if (deployment_seen)
59
60
  elapsedTime = '%.2f' % (Time.now - startTime)
60
- $LOG.info("Deployment with deploymentId #{@deploymentId} ended (Total time #{elapsedTime}s )")
61
+ $LOG.info("Deployment with deploymentId #{@deploymentId} ended (Total deployment time #{elapsedTime}s)")
61
62
  end
62
63
  end
63
64
  end
@@ -83,20 +84,25 @@ class Deployment
83
84
  end
84
85
  end
85
86
 
86
- def wait_until_healthy
87
+ def wait_until_healthy
88
+ startTime = Time.now
87
89
  Timeout::timeout(HEALTHY_WAIT_TIMEOUT) do
88
90
  loop do
89
91
  break if (!health_checks_defined?)
90
92
  sick = get_alive("false")
93
+ elapsedTime = '%.2f' % (Time.now - startTime)
91
94
  if (!sick.empty?)
92
- $LOG.info("#{sick.size}/#{@application.instances} instances are not healthy => " + sick.join(','))
95
+ $LOG.info("#{sick.size}/#{@application.instances} instances are not healthy, retrying in #{HEALTHY_WAIT_RECHECK_INTERVAL}s (elapsed time #{elapsedTime}s)")
96
+ $LOG.debug("Sick instances: " + sick.join(','))
93
97
  else
94
98
  healthy = get_alive("true")
95
99
  if (healthy.size == @application.instances)
96
- $LOG.info("#{healthy.size}/#{@application.instances} instances are healthy => " + healthy.join(','))
100
+ elapsedTime = '%.2f' % (Time.now - startTime)
101
+ $LOG.info("#{healthy.size} of #{@application.instances} expected instances are healthy (Total health-check time #{elapsedTime}s).")
102
+ $LOG.debug("Healthy instances running: " + healthy.join(','))
97
103
  break
98
104
  else
99
- $LOG.info("#{healthy.size}/#{@application.instances} healthy instances seen, retrying")
105
+ $LOG.info("#{healthy.size} healthy instances seen, #{@application.instances} healthy instances expected, retrying in in #{HEALTHY_WAIT_RECHECK_INTERVAL}s")
100
106
  end
101
107
  end
102
108
  sleep(HEALTHY_WAIT_RECHECK_INTERVAL)
@@ -105,8 +111,8 @@ class Deployment
105
111
  end
106
112
 
107
113
  def cancel(deploymentId,force=false)
108
- raise Error::BadURLError, "deploymentId must be specified to cancel deployment", caller if (deploymentId.empty?)
109
- if (running_for_deployment_id?(deploymentId))
114
+ raise ArgumentError, "deploymentId must be specified to cancel deployment", caller if (deploymentId.empty?)
115
+ if (running_for_deployment_id?)
110
116
  response = HttpUtil.delete(@url + MarathonDefaults::MARATHON_DEPLOYMENT_REST_PATH + deploymentId + "?force=#{force}")
111
117
  $LOG.debug("Cancellation response [#{response.code}] => " + JSON.pretty_generate(JSON.parse(response.body)))
112
118
  end
@@ -266,4 +272,5 @@ class Deployment
266
272
  return payload.find_all { |d| d['affectedApps'].include?('/' + @application.id) }
267
273
  end
268
274
 
275
+ end
269
276
  end
@@ -1,6 +1,7 @@
1
1
  require 'marathon_deploy/marathon_defaults'
2
2
 
3
- class Environment
3
+ module MarathonDeploy
4
+ class Environment
4
5
 
5
6
  attr_reader :name
6
7
 
@@ -25,4 +26,6 @@ class Environment
25
26
  def to_s
26
27
  @name
27
28
  end
29
+
30
+ end
28
31
  end
@@ -1,5 +1,6 @@
1
- module Error
2
-
1
+ module MarathonDeploy
2
+ module Error
3
+
3
4
  class MarathonError < StandardError; end
4
5
 
5
6
  class TimeoutError < MarathonError; end
@@ -18,4 +19,5 @@ module Error
18
19
 
19
20
  class UndefinedMacroError < MarathonError ; end
20
21
 
22
+ end
21
23
  end
@@ -2,7 +2,8 @@ require 'net/http'
2
2
  require 'uri'
3
3
  require 'marathon_deploy/error'
4
4
 
5
- module HttpUtil
5
+ module MarathonDeploy
6
+ module HttpUtil
6
7
 
7
8
  def self.put(url,payload)
8
9
  uri = construct_uri url
@@ -88,4 +89,5 @@ module HttpUtil
88
89
  end
89
90
  end
90
91
 
92
+ end
91
93
  end
@@ -1,6 +1,7 @@
1
1
  require 'marathon_deploy/error'
2
2
 
3
- module Macro
3
+ module MarathonDeploy
4
+ module Macro
4
5
 
5
6
  MACRO_BOUNDARY = '%%'
6
7
 
@@ -25,13 +26,13 @@ module Macro
25
26
  end
26
27
 
27
28
  def self.get_undefined_macros(macros)
28
- raise ArgumentError, "argument must be an array", caller if (!macros.class == Array)
29
+ raise ArgumentError, "Argument must be an array", caller if (!macros.class == Array)
29
30
  undefined = Array.new
30
31
  return macros.select { |m| !has_env?(m) }
31
32
  end
32
33
 
33
34
  def self.has_env?(macro)
34
- raise ArgumentError, "argument must be a String", caller if (!macro.class == String)
35
+ raise ArgumentError, "Argument must be a String", caller if (!macro.class == String)
35
36
  env_name = strip(macro)
36
37
  if (env_defined?(strip(env_name)))
37
38
  return true
@@ -46,10 +47,11 @@ module Macro
46
47
 
47
48
  def self.expand_macros(data)
48
49
  processed = ""
49
- macros = get_macros(data)
50
+ macros = get_macros(data).uniq
51
+ $LOG.debug("Macros found in deploy file: #{macros.join(',')}")
50
52
  undefined = get_undefined_macros(macros)
51
53
  if (!undefined.empty?)
52
- raise Error::UndefinedMacroError, "macros found in deploy file without defined environment variables: #{undefined.uniq.join(',')}", caller
54
+ raise Error::UndefinedMacroError, "Macros found in deploy file without defined environment variables: #{undefined.join(',')}", caller
53
55
  end
54
56
 
55
57
  data.each do |line|
@@ -68,4 +70,5 @@ module Macro
68
70
 
69
71
  private_class_method :get_macros, :get_env_keys, :strip, :has_env?, :get_undefined_macros, :env_defined?, :expand_macros
70
72
 
73
+ end
71
74
  end
@@ -3,7 +3,8 @@ require 'marathon_deploy/deployment'
3
3
  require 'marathon_deploy/utils'
4
4
  require 'marathon_deploy/marathon_defaults'
5
5
 
6
- class MarathonClient
6
+ module MarathonDeploy
7
+ class MarathonClient
7
8
 
8
9
  attr_reader :marathon_url, :options
9
10
  attr_accessor :application
@@ -33,7 +34,7 @@ class MarathonClient
33
34
  begin
34
35
  deployment.wait_for_application("Deployment already running for application #{application.id}")
35
36
  rescue Timeout::Error => e
36
- raise Timeout::Error, "Timed out after #{deployment.timeout}s waiting for existing deployment of #{application.id} to finish. Check marathon #{@marathon_url + '/#deployments'} for stuck deployments!", caller
37
+ raise Timeout::Error, "Timed out after #{deployment.timeout}s waiting for existing deployment of #{application.id} to finish. Check marathon ui #{@marathon_url + '/#deployments'} for stuck deployments!", caller
37
38
  end
38
39
 
39
40
  $LOG.info("Starting deployment of #{application.id}")
@@ -72,8 +73,9 @@ class MarathonClient
72
73
  begin
73
74
  deployment.wait_until_healthy
74
75
  rescue Timeout::Error => e
75
- raise Timeout::Error, "Timed out after #{deployment.healthcheck_timeout}s waiting for #{application.instances} instances of #{application.id} to become healthy", caller
76
+ raise Timeout::Error, "Timed out after #{deployment.healthcheck_timeout}s waiting for #{application.instances} instances of #{application.id} to become healthy. Check marathon ui #{@marathon_url + '/#deployments'} for more information.", caller
76
77
  end
77
-
78
+ end
79
+
78
80
  end
79
81
  end
@@ -2,15 +2,16 @@ require 'marathon_deploy/utils'
2
2
  require 'marathon_deploy/error'
3
3
  require 'logger'
4
4
 
5
- module MarathonDefaults
5
+ module MarathonDeploy
6
+ module MarathonDefaults
6
7
 
7
8
  DEPLOYMENT_RECHECK_INTERVAL = 3
8
9
  DEPLOYMENT_TIMEOUT = 300
9
- HEALTHY_WAIT_TIMEOUT = 300
10
+ HEALTHY_WAIT_TIMEOUT = 10 #300
10
11
  HEALTHY_WAIT_RECHECK_INTERVAL = 3
11
12
  PRODUCTION_ENVIRONMENT_NAME = 'PRODUCTION'
12
13
  DEFAULT_ENVIRONMENT_NAME = 'INTEGRATION'
13
- DEFAULT_PREPRODUCTION_MARATHON_ENDPOINTS = ['http://192.168.59.103:8080']
14
+ DEFAULT_PREPRODUCTION_MARATHON_ENDPOINTS = ['http://localhost:8080']
14
15
  DEFAULT_PRODUCTION_MARATHON_ENDPOINTS = ['http://paasmaster46-1.mobile.rz:8080']
15
16
  DEFAULT_DEPLOYFILE = 'deploy.yaml'
16
17
  DEFAULT_LOGFILE = false
@@ -30,10 +31,7 @@ module MarathonDefaults
30
31
  :JAVA_XMX => "128m"
31
32
  }
32
33
 
33
- @@required_marathon_env_variables = %w[
34
- DATACENTER_NUMBER
35
- APPLICATION_NAME
36
- ]
34
+ @@required_marathon_env_variables = %w[]
37
35
 
38
36
  #@@required_marathon_attributes = %w[id env container healthChecks args storeUrls].map(&:to_sym)
39
37
  @@required_marathon_attributes = %w[id].map(&:to_sym)
@@ -80,4 +78,5 @@ module MarathonDefaults
80
78
  return json
81
79
  end
82
80
 
81
+ end
83
82
  end
@@ -1,4 +1,5 @@
1
- module Utils
1
+ module MarathonDeploy
2
+ module Utils
2
3
 
3
4
  def self.symbolize(data)
4
5
  data.inject({}){|h,(k,v)| h[k.to_sym] = v; h}
@@ -27,5 +28,6 @@ module Utils
27
28
  end
28
29
  return nil
29
30
  end
30
-
31
+
32
+ end
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module MarathonDeploy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,7 +2,8 @@ require 'yaml'
2
2
  require 'json'
3
3
  require 'marathon_deploy/macro'
4
4
 
5
- module YamlJson
5
+ module MarathonDeploy
6
+ module YamlJson
6
7
 
7
8
  def self.yaml2json(filename, process_macros=true)
8
9
  if (process_macros)
@@ -42,4 +43,5 @@ module YamlJson
42
43
  return JSON.parse(data)
43
44
  end
44
45
 
46
+ end
45
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marathon_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Colby
@@ -70,7 +70,6 @@ description: Pushes a yaml or json file to the Marathon API.
70
70
  email:
71
71
  - jcolby@team.mobile.de
72
72
  executables:
73
- - deploy
74
73
  - deploy.rb
75
74
  - json2yaml.rb
76
75
  extensions: []
@@ -83,7 +82,6 @@ files:
83
82
  - README.md
84
83
  - Rakefile
85
84
  - TODO
86
- - bin/deploy
87
85
  - bin/deploy.rb
88
86
  - bin/json2yaml.rb
89
87
  - examples/deploy.json
@@ -129,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
127
  version: '0'
130
128
  requirements: []
131
129
  rubyforge_project:
132
- rubygems_version: 2.4.6
130
+ rubygems_version: 2.4.5
133
131
  signing_key:
134
132
  specification_version: 4
135
133
  summary: Mesos/Marathon deployment tool.
data/bin/deploy DELETED
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
-
3
- # TODO