depengine 3.0.12 → 3.0.13

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: 65323cd0cb0e566052549a932ebf9648b5e9cdff
4
- data.tar.gz: e332c30d4454cf4894058dc3b1fc4f1f6c123697
3
+ metadata.gz: 9e2c029e3eb7bd3346ecf335948c89a5c32887de
4
+ data.tar.gz: d816e6f7d3a987b5fc28a2b50c71b02da46b0691
5
5
  SHA512:
6
- metadata.gz: dd0b8f3e5b915c513c177eaceaaa4cba2a85db0f808a3ced5ed1322f156062b21c44a04ebea896f2c77dc83bb5749c1cd0baa077ff733e8f3dc0b08587f3dd01
7
- data.tar.gz: e0832ffbb1bf5d715b9041b09dc3bd28ade749b7f7366384d5aa10f007147ce74b8fa88bf790e035199ca06b7790af37d37a28ffc1d150613e137246ef3f1396
6
+ metadata.gz: d04519c274f0eaa98ecbb8cff280bce4e00d6691201c13490e4f13b8f3a4fc7ed920187de3d5d7dcc9049aa969b257efeacc55918f2a6311dd601d7fccf47e59
7
+ data.tar.gz: a2d8b34ff09c1d4deeae8441fb6c0ac4d7386d63cca1d5e01f2d254642690aa62d571f9ca8e05e108e69168b4024b766061083fcb296e35f2db7ee3ac6bcd1de
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- depengine (3.0.11)
4
+ depengine (3.0.12)
5
5
  expect4r (~> 0.0)
6
6
  json (~> 1.4)
7
7
  log4r (~> 1.1)
@@ -26,7 +26,7 @@ GEM
26
26
  mime-types (~> 1.16)
27
27
  treetop (~> 1.4.8)
28
28
  mime-types (1.25.1)
29
- net-scp (1.1.2)
29
+ net-scp (1.2.0)
30
30
  net-ssh (>= 2.6.5)
31
31
  net-sftp (2.1.2)
32
32
  net-ssh (>= 2.6.5)
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  `gem build depengine.gemspec`
5
5
 
6
6
  ## Usage
7
- 1. rvm use 1.9.3
7
+ 1. rvm use 2.1.1
8
8
  2. bundle install
9
9
  3. bundle exec depengine
10
10
 
@@ -19,4 +19,40 @@ To run the specs, your machine needs to fulfill some requirements:
19
19
 
20
20
  There is a somewhat simplistic script to get a suitable environment up and running. Have a look at *bin/spec_setup*.
21
21
 
22
- `rspec`
22
+ `rspec`
23
+
24
+ ## Documentation
25
+
26
+ To see a list of all currently supported methods in the DSL, run `rake doc` and browse to: doc/table_of_contents.html#methods
27
+
28
+ ## Example recipe
29
+
30
+ ```
31
+ set :application_name, "testapp"
32
+ set :module_name, "testmodule"
33
+
34
+ set :cleanup_workspace_before, ["source", "tmp"]
35
+
36
+ set :log_level, "INFO"
37
+ set :log_file, "deploy.log"
38
+ set :log_file_level, "DEBUG"
39
+
40
+ Deployment.deliver do
41
+
42
+ config = get_all_config_parameters
43
+ $log.writer.info "Got config parameters from cdb"
44
+
45
+ $log.writer.info "date_unique: #{date_unique}"
46
+
47
+ config['test_app_hosts'].each do |test_app_host|
48
+ $log.writer.info "doing something on #{test_app_host}"
49
+ rsync("target/", "/srv/testapp/")
50
+ remote_execute("export JAVA_HOME=/opt/java7; cd /srv/testapp/project_#{config['env'].downcase}/current/; . ./setantenv.sh; ant;", :remote_host => test_app_host)
51
+ end
52
+
53
+ report_by_mail
54
+ $log.writer.info "Sent mail to deployment team #{config['deploy_email_to']}"
55
+
56
+ $log.writer.info "Deployment done!"
57
+ end
58
+ ```
data/Rakefile CHANGED
@@ -9,3 +9,8 @@ task :build do
9
9
  sh "gem build -V depengine.gemspec"
10
10
  end
11
11
 
12
+ desc "generates docs for the DSL"
13
+ task :doc do
14
+ sh "rm -rf doc/"
15
+ sh "rdoc lib/depengine/dsl/*.rb"
16
+ end
@@ -39,9 +39,13 @@ module Depengine
39
39
 
40
40
  recipe_filename = File.join(($recipe_config[:recipe_base_dir] || $recipe_config[:deploy_home]), @recipe_name)
41
41
  puts "Evaluating recipe #{recipe_filename}"
42
- eval(File.new(recipe_filename).read)
42
+ evaluate_recipe!(File.open(recipe_filename).read)
43
43
  return 0
44
44
  end
45
+
46
+ def evaluate_recipe!(recipe)
47
+ eval(recipe)
48
+ end
45
49
  end
46
50
  end
47
51
  end
@@ -15,6 +15,9 @@ module Deployment
15
15
  end
16
16
 
17
17
  class Worker
18
+
19
+ attr_accessor :cdb
20
+
18
21
  def initialize
19
22
  # initialize logging
20
23
  if not $recipe_config[:log_level].nil?
@@ -47,18 +50,15 @@ module Deployment
47
50
  Helper.validates_not_empty $recipe_config[:version], "version is not set"
48
51
  Helper.validates_not_empty $recipe_config[:deploy_home], "deploy_home is not set"
49
52
 
50
- # read configuration from cdb
51
- $recipe_config['cdb_host'] ||= "filesystem"
52
- $recipe_config['cdb_context'] ||= ""
53
- @cdb = get_cdb_parameters(@version['cdb'])
54
-
55
- # clean workspace if needed
56
- if $recipe_config[:cleanup_workspace_before]
57
- $log.writer.info "Remove all files from Workspace"
58
- Helper.cleanup_workspace!($recipe_config[:deploy_home], $recipe_config[:cleanup_workspace_before])
53
+ if $recipe_config[:skip_cdb_setup]
54
+ @cdb = {}
55
+ else
56
+ $recipe_config['cdb_host'] ||= "filesystem"
57
+ $recipe_config['cdb_context'] ||= ""
58
+ @cdb = get_cdb_parameters(@version['cdb'])
59
59
  end
60
- # init workspace with default directorys
61
- Helper.init_workspace($recipe_config[:deploy_home])
60
+
61
+ setup_workspace!
62
62
 
63
63
  # the logfile needs a correct WORKSPACE and the initial dirs
64
64
  # so we have to set it here
@@ -107,6 +107,26 @@ module Deployment
107
107
  end
108
108
  end
109
109
 
110
+ def setup_workspace!
111
+ if $recipe_config[:cleanup_workspace_before]
112
+ $log.writer.info "Remove all files from Workspace"
113
+ Helper.cleanup_workspace!($recipe_config[:deploy_home], $recipe_config[:cleanup_workspace_before])
114
+ end
115
+
116
+ Helper.init_workspace($recipe_config[:deploy_home])
117
+
118
+ if $recipe_config[:copy_to_workspace]
119
+ $recipe_config[:copy_to_workspace] = ["config"] unless $recipe_config[:copy_to_workspace].respond_to?(:each)
120
+ $recipe_config[:copy_to_workspace].each do |dir|
121
+ copy_to_workspace!(dir)
122
+ end
123
+ end
124
+ end
125
+
126
+ def copy_to_workspace!(dir)
127
+ Processor::copy(File.join($recipe_config[:recipe_base_dir], dir), $recipe_config[:deploy_home])
128
+ end
129
+
110
130
  # access configdata like this...
111
131
  # @hudson['USER']
112
132
  # $recipe_config[:application_name]
@@ -1,29 +1,51 @@
1
1
  module Deployment
2
2
  module Methods
3
3
  module Fileops
4
+
5
+ # Copies a file or directory from a given source to a given target.<br>
6
+ # Both are prefixed with the recipes +:deploy_home+.
4
7
  def copy(source, target, options={})
5
8
  Processor.copy(File.join($recipe_config[:deploy_home], source), \
6
9
  File.join($recipe_config[:deploy_home], target), \
7
10
  options)
8
11
  end
9
12
 
13
+ # Recursively creates a directory with a given name/path.<br>
14
+ # The path will be prefixed with the recipes +:deploy_home+.
10
15
  def mkdir(directory)
11
16
  Processor.mkdir(File.join($recipe_config[:deploy_home], directory))
12
17
  end
13
18
 
19
+ # Changes permission modes on a given name/path.<br>
20
+ # The path will be prefixed with the recipes +:deploy_home+.
21
+ #
22
+ # Parameters:
23
+ # * +file+ - the file to change mode on
24
+ # * +mode+ - the new file permission mode (e.g. "644")
25
+ # * [+options+] - a hash with additional parameters. This is optional.
14
26
  def chmod(file, mode, options={})
15
27
  Processor.chmod(File.join($recipe_config[:deploy_home], file), \
16
28
  mode, options)
17
29
  end
18
30
 
31
+ # Removes a given name/path.<br>
32
+ # The path will be prefixed with the recipes +:deploy_home+.
19
33
  def remove(file)
20
34
  Processor.remove(File.join($recipe_config[:deploy_home], file))
21
35
  end
22
36
 
37
+ # Creates a link from a given file to a given target.<br>
38
+ # The target be prefixed with the recipes +:deploy_home+.
23
39
  def mklink(source, target)
24
40
  Processor.mklink(source, File.join($recipe_config[:deploy_home], target))
25
41
  end
26
42
 
43
+ # Check for the existence of all files in a given list in a given directory.
44
+ #
45
+ # Parameters:
46
+ # * +list+ - a CSV list of filenames to check for
47
+ # * +target+ - the directory to check in.
48
+ # Both are prefixed with the recipes +:deploy_home+.
27
49
  def check_filelist(list, target)
28
50
  Processor.check_filelist(File.join($recipe_config[:deploy_home], list), \
29
51
  File.join($recipe_config[:deploy_home], target))
@@ -1,48 +1,106 @@
1
1
  module Deployment
2
2
  module Methods
3
3
  module Helper
4
+
5
+ # Returns an time-dependant string that can be used in pseudo-unique
6
+ # release versions and the such.
7
+ #
8
+ # The object will be cached for later reference, so multiple uses of this
9
+ # method in a recipe will result in the same string.
10
+ #
11
+ # Parameters:
12
+ # * +format+ - the strftime format that is to be used to generate the unique string. Defaults to "%Y-%m-%d_%s".
13
+ def date_unique(format="%Y-%m-%d_%s")
14
+ @date_unique ||= Time.now.strftime(format)
15
+ end
16
+
17
+ # Sends an email.
18
+ #
19
+ # Parameters:
20
+ # * +options+ - a hash with needed configuration options for the email.
21
+ # * +:body+ - the actual text to send
22
+ # * +:subject+ - the subject line of the email
23
+ # * +:from+ - the senders address
24
+ # * +:to+ - the recipiants address
4
25
  def sendmail(options)
5
26
  Helper.validates_presence_of options[:from], "Mail-FROM not set"
6
27
  Helper.validates_presence_of options[:to], "Mail-TO not set"
7
28
  Helper.validates_presence_of options[:subject], "No mail subject set"
8
29
  Helper.validates_presence_of options[:body], "No mail body set"
9
- Helper.validates_presence_of @cdb['smtp_host'], "SMTP host not set"
10
30
 
11
31
  helper = ::Helper::Mail.new
12
- helper.smtp_host = @cdb['smtp_host']
32
+ helper.smtp_host = @cdb['smtp_host'] if @cdb and @cdb['smtp_host']
13
33
  helper.sendmail(options)
14
34
  end
15
35
 
36
+ # Checks if a given url returns 200 and a body that matches a given regexp.
37
+ #
38
+ # Parameters:
39
+ # * +options+ - a hash with needed configuration options
40
+ # * +:check_protocol+ - "http" or "https" or maybe something else...
41
+ # * +:check_host+ - the host to contact
42
+ # * +:check_port+ - the port to connect to
43
+ # * +:check_uri+ - the recipiants address
44
+ # * +:check_response_string+ - the string or regexp to check
16
45
  def assert_url_response_of(options={})
17
46
  asserter = ::Asserter::Url.new
18
47
  asserter.check_protocol = options[:check_protocol] || @cdb['check_protocol'] || "http"
19
48
  asserter.check_host = options[:check_host] || @cdb['check_host']
20
49
  asserter.check_port = options[:check_port] || @cdb['check_port'] || '80'
21
50
  asserter.check_uri = options[:check_uri] || @cdb['check_uri'] || '/'
22
- asserter.check_response_string = options[:chek_response_string] || @cdb['check_response_string'] || 'html'
51
+ asserter.check_response_string = options[:check_response_string] || @cdb['check_response_string'] || 'html'
23
52
 
24
53
  asserter.assert_url_response_of(options)
25
54
  end
26
55
 
27
- def report_to_cdb(options={})
56
+ # Reports a deployment to its cdb.
57
+ def report_to_cdb()
28
58
  reporter = ::Reporter::Cdb.new
29
59
  reporter.version = @version.to_json
30
60
  reporter.worker = self
31
- reporter.set_version(options)
61
+ reporter.set_version()
32
62
  end
33
63
 
64
+ # Sends an email to report a deployment to a given recepiant.
65
+ #
66
+ # Parameters:
67
+ # * +options+ - a hash with needed configuration options for the email. All parameters are optional.
68
+ # * +:application_name+ - which application has been deployed
69
+ # * +:module_name+ - which module of the application has been deployed
70
+ # * +:status+ - the resulting status of the deployment
71
+ # * +:message+ - a additional message to send in the mail, commonly used to specify any non positive status.
72
+ # * +:deploy_email_from+ - the senders address
73
+ # * +:deploy_email_to+ - the recipiants address
34
74
  def report_by_mail(options={})
35
- reporter = ::Reporter::Mail.new
36
- reporter.deploy_email_from = options[:deploy_email_from] || @cdb['deploy_email_from']
37
- reporter.deploy_email_to = options[:deploy_email_to] || @cdb['deploy_email_to']
38
- reporter.application_name = options[:application_name] || $recipe_config[:application_name] || @cdb['application_name']
39
- reporter.module_name = options[:module_name] || $recipe_config[:module_name] || @cdb['module_name']
40
- reporter.environment = $recipe_config['ENVIRONMENT']
41
- reporter.version = @version.to_json
42
- reporter.worker = self
43
- reporter.send(options)
75
+ application_name = options[:application_name] || $recipe_config[:application_name] || @cdb['application_name']
76
+ module_name = options[:module_name] || $recipe_config[:module_name] || @cdb['module_name']
77
+
78
+ status = options[:status] || "done"
79
+ message = options[:message] || ""
80
+
81
+ mail_options = {
82
+ :from => options[:deploy_email_from] || @cdb['deploy_email_from'],
83
+ :to => options[:deploy_email_to] || @cdb['deploy_email_to'],
84
+ :subject => "DeploymentReport: #{module_name} #{$recipe_config['ENV']} #{application_name} #{status}",
85
+ :body => "Module: #{module_name}\nEnvironment: #{$recipe_config['ENV']}\nJob: #{application_name}\nVersion: #{@version.to_json}\n#{status}.\n\n#{message}"
86
+ }
87
+ sendmail(mail_options)
44
88
  end
45
89
 
90
+ # Deploys a tomcat based application to a set of app servers. <br>
91
+ # The tomcats are restarted in this process.
92
+ #
93
+ # Parameters:
94
+ # * +options+ - a hash with needed configuration options.
95
+ # * +:servers+ - an enumerable list of the app servers
96
+ # * +:runners+ - a subset of +:servers+ which are currently active. Is equal to +:servers+ if not set
97
+ # * +:initd_script+ - the path to the init script of the appserver. Used to stop/start.
98
+ # * +:application_name+ - the name of the current application
99
+ # * +:catalina_home+ - the path in which the app servers webapps/ directory is
100
+ # * +:tomcat_context+ - the tomcat context to deploy in
101
+ # * +:logfilename+ - the name of the logfile. Will be automatically prefixed with #{catalina_home}/logs/
102
+ # * +:check_host+ - an options hash to pass to +#assert_url_response_of+ to check the status of the app
103
+ # All parameters can also be spcified via CDB.
46
104
  def tomcat_deploy(options={})
47
105
  publisher = ::Publisher::Tomcat.new
48
106
  publisher.servers = options[:servers] || @cdb['servers']
@@ -57,6 +115,11 @@ module Deployment
57
115
  publisher.deploy(options)
58
116
  end
59
117
 
118
+ # Mounts a SMB share.
119
+ #
120
+ # Parameters:
121
+ # * +remote_path+ - the path to the remote share (e.g."smb://somehost/someshare")
122
+ # * +:local_path+ - the local path in which the share will be mounted
60
123
  def samba_mount (remote_path, local_path)
61
124
  smb = ::Helper::Smb.new
62
125
  smb.remote_path = remote_path
@@ -64,6 +127,10 @@ module Deployment
64
127
  smb.samba_mount()
65
128
  end
66
129
 
130
+ # Unmounts a previously mounted SMB share.
131
+ #
132
+ # Parameters:
133
+ # * +:local_path+ - the local path in which the share is mounted
67
134
  def samba_umount (local_path)
68
135
  smb = ::Helper::Smb.new
69
136
  smb.local_path = local_path
@@ -16,9 +16,9 @@ module Deployment
16
16
  Helper.validates_presence_of $recipe_config['VALUE'], \
17
17
  "VALUE parameter is missing"
18
18
 
19
- iis = ::Publisher::Iis_build.new
20
- iis.iis_build_protocol = @cdb['iis_build_protocol']
21
- iis.iis_build_url = @cdb['iis_build_url']
19
+ iis = ::Publisher::IIS.new
20
+ iis.protocol = @cdb['iis_build_protocol']
21
+ iis.url = @cdb['iis_build_url']
22
22
  if @cdb['http_read_timeout']
23
23
  iis.http_read_timeout = @cdb['http_read_timeout']
24
24
  else
@@ -40,9 +40,9 @@ module Deployment
40
40
  Helper.validates_presence_of @version['app'], \
41
41
  "VERSION parameter is missing"
42
42
 
43
- iis = ::Publisher::Iis_deploy.new
44
- iis.iis_deploy_protocol = @cdb['iis_deploy_protocol']
45
- iis.iis_deploy_url = options[:iis_deploy_url] || @cdb['iis_deploy_url']
43
+ iis = ::Publisher::IIS.new
44
+ iis.protocol = @cdb['iis_deploy_protocol']
45
+ iis.url = options[:iis_deploy_url] || @cdb['iis_deploy_url']
46
46
  if @cdb['http_read_timeout']
47
47
  iis.http_read_timeout = @cdb['http_read_timeout']
48
48
  else
@@ -59,9 +59,9 @@ module Deployment
59
59
  Helper.validates_presence_of $recipe_config['VALUE'], \
60
60
  "VALUE parameter is missing"
61
61
 
62
- iis = ::Publisher::Iis_appcmd.new
63
- iis.iis_appcmd_protocol = @cdb['iis_appcmd_protocol']
64
- iis.iis_appcmd_url = @cdb['iis_appcmd_url']
62
+ iis = ::Publisher::IIS.new
63
+ iis.protocol = @cdb['iis_appcmd_protocol']
64
+ iis.url = @cdb['iis_appcmd_url']
65
65
  if @cdb['http_read_timeout']
66
66
  iis.http_read_timeout = @cdb['http_read_timeout']
67
67
  else
@@ -3,23 +3,13 @@ module Deployment
3
3
  module Patch
4
4
 
5
5
  def patch_properties (source, target, options={})
6
- patch_set = 'patch_properties'
7
- if not options[:patch_set].nil?
8
- patch_set = options[:patch_set]
9
- end
10
- Helper.validates_presence_of @cdb[patch_set], \
11
- "Can not find a valid patch_set"
6
+ patch_set = options[:patch_set] || 'patch_properties'
7
+ Helper.validates_presence_of @cdb[patch_set], "Can not find a valid patch_set"
12
8
 
13
- assigner = '='
14
- if not options[:assigner].nil?
15
- assigner = options[:assigner]
16
- end
9
+ assigner = options[:assigner] || '='
17
10
 
18
11
  properties = Processor::Properties.new
19
12
  properties.properties_hash = @cdb[patch_set]
20
- ### add db_endpoint
21
- properties.properties_hash['db_endpoint_1'] = @cdb['db_endpoint_1']
22
- properties.properties_hash['db_endpoint_2'] = @cdb['db_endpoint_2']
23
13
  properties.assigner = assigner
24
14
  properties.patch(File.join($recipe_config[:deploy_home], source), \
25
15
  File.join($recipe_config[:deploy_home], target, \
@@ -77,28 +77,28 @@ module Deployment
77
77
  end
78
78
 
79
79
  def git_fetch(options={})
80
- publisher = ::Publisher::Git.new
80
+ publisher = ::Provider::Git.new
81
81
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
82
82
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
83
83
  publisher.fetch()
84
84
  end
85
85
 
86
86
  def git_checkout(branch_name, options={})
87
- publisher = ::Publisher::Git.new
87
+ publisher = ::Provider::Git.new
88
88
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
89
89
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
90
90
  publisher.checkout(branch_name, options)
91
91
  end
92
92
 
93
93
  def git_submodule(submodule_option, options={})
94
- publisher = ::Publisher::Git.new
94
+ publisher = ::Provider::Git.new
95
95
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
96
96
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
97
97
  publisher.submodule(submodule_option, options)
98
98
  end
99
99
 
100
100
  def git_tag(tag_name, options={})
101
- publisher = ::Publisher::Git.new
101
+ publisher = ::Provider::Git.new
102
102
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
103
103
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
104
104
  publisher.tag(tag_name, options)