depengine 3.0.12 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,8 @@ module Deployment
7
7
  template.basepath = options[:basepath] || $recipe_config[:recipe_base_dir] || $recipe_config[:deploy_home]
8
8
  options[:excludes] = [] if options[:excludes].nil?
9
9
  options[:excludes] << '.svn'
10
- template.parse_template(source, content, target, options)
10
+ options[:excludes] << '.git'
11
+ template.parse_template(source, content, ::Helper::path_in_deploy_home(target), options)
11
12
  end
12
13
 
13
14
  def parse_erb_template(source, target, content, options={})
@@ -16,7 +17,8 @@ module Deployment
16
17
  template.basepath = options[:basepath] || $recipe_config[:recipe_base_dir] || $recipe_config[:deploy_home]
17
18
  options[:excludes] = [] if options[:excludes].nil?
18
19
  options[:excludes] << '.svn'
19
- template.parse_erb_template(source, content, target, options)
20
+ options[:excludes] << '.git'
21
+ template.parse_erb_template(source, content, ::Helper::path_in_deploy_home(target), options)
20
22
  end
21
23
  end
22
24
  end
@@ -2,20 +2,27 @@ module Helper
2
2
 
3
3
  class Mail
4
4
 
5
- attr_accessor :smtp_host
6
- attr_accessor :smtp_port
5
+ attr_accessor :smtp_host, :smtp_port
7
6
 
8
7
  def initialize
9
- smtp_host = 'localhost' if not smtp_host
10
- smtp_port = 25 if not smtp_port
8
+ smtp_host ||= 'localhost'
9
+ smtp_port ||= 25
11
10
  end
12
11
 
12
+ # Sends an email via smtp.
13
+ #
14
+ # Parameters:
15
+ # * +options+ - a hash with needed configuration options for the email
16
+ # * +:from+ - the senders address
17
+ # * +:to+ - the recipiants address
18
+ # * +:subject+ - the email subject
19
+ # * +:body+ - the actual text to send in the mail
13
20
  def sendmail(options={})
14
21
  begin
15
22
  Pony.mail( \
16
23
  :from => options[:from],
17
24
  :to => options[:to],
18
- :via => :smtp,
25
+ :via => :smtp,
19
26
  :via_options => {
20
27
  :address => smtp_host,
21
28
  :port => smtp_port,
@@ -10,4 +10,19 @@ module Helper
10
10
  if attribute.nil?
11
11
  end
12
12
  module_function :validates_not_empty
13
+
14
+ def path_in_deploy_home(path)
15
+ absolute_path?(path) ? path : File.join($recipe_config[:deploy_home] || "", path)
16
+ end
17
+ module_function :path_in_deploy_home
18
+
19
+ def path_in_recipe_base_dir(path)
20
+ absolute_path?(path) ? path : File.join($recipe_config[:recipe_base_dir] || "", path)
21
+ end
22
+ module_function :path_in_recipe_base_dir
23
+
24
+ def absolute_path?(path)
25
+ path.start_with? "/"
26
+ end
27
+ module_function :absolute_path?
13
28
  end
@@ -52,13 +52,6 @@ module Processor
52
52
  else
53
53
  entry = entry.sub(keyvalue[1].strip, \
54
54
  properties_hash[keyvalue[0].strip])
55
- ### patch global variable
56
- if not entry.nil? and entry.include?('<t:db_endpoint_1/>')
57
- entry = entry.sub(/<t\:db_endpoint_1\/>/, properties_hash['db_endpoint_1'])
58
- end
59
- if not entry.nil? and entry.include?('<t:db_endpoint_2/>')
60
- entry = entry.sub(/<t\:db_endpoint_2\/>/, properties_hash['db_endpoint_2'])
61
- end
62
55
  end
63
56
  end
64
57
  end
@@ -1,7 +1,7 @@
1
1
  module Processor
2
2
  class Template
3
3
  include Processor
4
- attr_accessor :basepath
4
+ attr_accessor :basepath, :outdir, :source, :content
5
5
  attr_writer :cdb
6
6
 
7
7
  # Render a template and write the output to a file or directory
@@ -9,73 +9,88 @@ module Processor
9
9
  def parse_template(template_source, content, outdir, options={})
10
10
  Helper.validates_presence_of basepath, "Basepath not set for template engine"
11
11
  # expand basepath
12
- self.basepath = File.expand_path basepath
12
+ @basepath = File.expand_path basepath
13
+ @outdir = outdir
14
+ @source = File.join(@basepath, template_source)
15
+ @content = content
16
+ @excludes = options[:excludes]
13
17
 
14
- if File.file?( File.join( basepath, template_source ) )
15
- source_root_path = File.join( basepath, File.dirname(template_source) )
16
- single_file = File.join( basepath, template_source )
18
+ if File.file?(File.join(basepath, template_source))
19
+ from_file
17
20
  else
18
- # source is a directory
19
- source_root_path = File.join( basepath, template_source)
20
- single_file = nil
21
+ all_from_directory
21
22
  end
22
- target_root_path = File.join( basepath, outdir )
23
- target_path = target_root_path
23
+ return self
24
+ end
24
25
 
25
- Find.find( single_file || source_root_path ) do |path|
26
+ def from_file
27
+ if excluded? @source
28
+ $log.writer.debug "Skip template #{@source}"
29
+ return
30
+ end
31
+ target_dir = target_path_of(@source)
32
+ create_sub_dirs!(target_dir)
33
+ target_file = File.join(target_dir, File.basename(@source).gsub(".tpl",""))
34
+ File.open(target_file, "w") do |f|
35
+ f.write(parse(@source))
36
+ end
37
+ end
38
+
39
+ def all_from_directory
40
+ find_templates(@source).each do |t|
41
+ @source = t
42
+ from_file
43
+ end
44
+ end
45
+
46
+ def find_templates(path_to_find_in)
47
+ templates = []
48
+ Find.find(path_to_find_in) do |path|
26
49
  # next if we found ourself
27
- next if path == source_root_path
50
+ next if path == path_to_find_in
51
+ next unless File.file?(path) and path.end_with?(".tpl")
52
+ templates << path
53
+ end
54
+ templates
55
+ end
28
56
 
29
- sub_dir = File.join( File.dirname( path ).split(/\//) - \
30
- source_root_path.split(/\//) )
31
- target_path = File.join( target_root_path, sub_dir )
32
- target = File.join( target_path, File.basename( path ) )
57
+ def target_path_of(path)
58
+ path = File.dirname(path) if File.file?(path)
59
+ sub_dir = File.join(path.split(/\//) - @basepath.split(/\//))
60
+ File.join(@outdir, sub_dir)
61
+ end
33
62
 
34
- if not options[:excludes].nil?
35
- options[:excludes].each do |exclude|
36
- if target.include? exclude
37
- $log.writer.debug "Skip template #{target}"
38
- Find.prune
39
- next
40
- end
63
+ def excluded?(target)
64
+ if @excludes
65
+ @excludes.each do |exclude|
66
+ if target.include? exclude
67
+ return true
41
68
  end
42
69
  end
70
+ end
71
+ return false
72
+ end
43
73
 
44
- if File.directory? path
45
- if not File.directory? target
46
- FileUtils.mkdir_p( target )
47
- $log.writer.debug "Create directory #{target}"
48
- end
49
- else
50
- target_file = File.join( target_path, \
51
- File.basename(target, ".tpl"))
52
- begin
53
- if not File.binary? path and not File.zero? path
54
- writer = File.new(target_file, 'w')
55
- writer.write(parse(path, content))
56
- writer.close if not writer.nil?
57
- writer = nil
58
- else
59
- FileUtils.cp(path, File.expand_path(target_file))
60
- end
61
- rescue Exception => e
62
- $log.writer.error "Can not write output from template to #{target_file}"
63
- $log.writer.error e.message
64
- exit 1
65
- end
66
- end
74
+ def create_sub_dirs!(target)
75
+ if not File.directory?(target)
76
+ FileUtils.mkdir_p(target)
77
+ $log.writer.debug "Create directory #{target}"
67
78
  end
68
79
  end
69
80
 
81
+
70
82
  # This function returns the output of a parsed template, 'template' can be
71
83
  # a filename or a String.
72
84
  def self.parse(template, content)
73
85
  $log.writer.debug "Parse Template #{template}"
74
- Template.new.parse(template, content)
86
+ t = Template.new
87
+ t.source = template
88
+ t.content = content
89
+ t.parse(template)
75
90
  end
76
91
 
77
- def parse(template, content)
78
- context = load_tags(content, @cdb)
92
+ def parse(template)
93
+ context = load_tags(@content, @cdb)
79
94
  begin
80
95
  parser = Radius::Parser.new(context, :tag_prefix => 't')
81
96
  template_content = ""
@@ -1,4 +1,4 @@
1
- module Publisher
1
+ module Provider
2
2
  class Git
3
3
  attr_accessor :repository_url
4
4
  attr_accessor :repository_local_dir
@@ -0,0 +1,101 @@
1
+ module Publisher
2
+ class IIS
3
+ attr_accessor :url, :protocol, :http_read_timeout
4
+
5
+ def build(tag, env, version, value, application_name)
6
+ Helper.validates_presence_of @url, "IIS URL not set"
7
+ Helper.validates_presence_of @protocol, "Protocol not set"
8
+ iis_error = false
9
+
10
+ begin
11
+ uri = URI(@protocol + '://' + @url)
12
+ Net::HTTP.start(uri.host, uri.port) do |http|
13
+ http.read_timeout = http_read_timeout
14
+ request = Net::HTTP::Post.new uri.request_uri
15
+ request.set_form_data('tag' => tag, 'env' => env, 'version' => version, 'value' => value, 'application_name' => application_name)
16
+ request.content_type = 'application/x-www-form-urlencoded;charset=utf-8'
17
+ http.request request do |response|
18
+ response.read_body do |chunk|
19
+ if chunk.include?("### Error while executing")
20
+ $log.writer.error "Error executing build on IIS"
21
+ iis_error = true
22
+ end
23
+ $log.writer.info "#{chunk}"
24
+ end
25
+ end
26
+ end
27
+ rescue Exception => e
28
+ $log.writer.error "Error: while connecting to IIS Server"
29
+ $log.writer.error "Request was: #{uri.to_s}"
30
+ $log.writer.error e.message
31
+ exit 1
32
+ end
33
+
34
+ if iis_error
35
+ exit 1
36
+ end
37
+
38
+ end
39
+
40
+ def appcmd(value)
41
+ Helper.validates_presence_of @url, "IIS URL not set"
42
+ Helper.validates_presence_of @protocol, "Protocol not set"
43
+
44
+ begin
45
+ uri = URI(@protocol + '://' + @url)
46
+ Net::HTTP.start(uri.host, uri.port) do |http|
47
+ http.read_timeout = http_read_timeout
48
+ request = Net::HTTP::Post.new uri.request_uri
49
+ request.set_form_data('value' => value)
50
+ request.content_type = 'application/x-www-form-urlencoded;charset=utf-8'
51
+ http.request request do |response|
52
+ response.read_body do |chunk|
53
+ $log.writer.info "#{chunk}"
54
+ end
55
+ end
56
+ end
57
+ rescue Exception => e
58
+ $log.writer.error "Error: while connecting to IIS Server"
59
+ $log.writer.error "Request was: #{uri.to_s}"
60
+ $log.writer.error e.message
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ def deploy(version, iis_application_name, env)
66
+ Helper.validates_presence_of @url, "IIS URL not set"
67
+ Helper.validates_presence_of @protocol, "Protocol not set"
68
+ iis_error = false
69
+
70
+ begin
71
+ uri = URI(@protocol + '://' + @url)
72
+ Net::HTTP.start(uri.host, uri.port) do |http|
73
+ http.read_timeout = http_read_timeout
74
+ request = Net::HTTP::Post.new uri.request_uri
75
+ request.set_form_data('version' => version, 'application_name' => iis_application_name, 'env' => env)
76
+ request.content_type = 'application/x-www-form-urlencoded;charset=utf-8'
77
+ http.request request do |response|
78
+ response.read_body do |chunk|
79
+ if chunk.include?("### Error while executing")
80
+ $log.writer.error "Error executing deploy on IIS"
81
+ iis_error = true
82
+ end
83
+ $log.writer.info "#{chunk}"
84
+ end
85
+ end
86
+ end
87
+ rescue Exception => e
88
+ $log.writer.error "Error: while connecting to IIS Server"
89
+ $log.writer.error "Request was: #{uri.to_s}"
90
+ $log.writer.error e.message
91
+ exit 1
92
+ end
93
+
94
+ if iis_error
95
+ exit 1
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+ end
@@ -3,7 +3,7 @@ module Reporter
3
3
  attr_accessor :version
4
4
  attr_accessor :worker
5
5
 
6
- def set_version(options={})
6
+ def set_version
7
7
  Helper.validates_presence_of version, "version not set"
8
8
 
9
9
  worker.set_cdb_parameter('deployed_version', version)
@@ -1,3 +1,3 @@
1
1
  module Depengine
2
- VERSION = "3.0.12"
2
+ VERSION = "3.0.13"
3
3
  end
@@ -12,7 +12,6 @@ $log.writer.level = Log4r::DEBUG
12
12
 
13
13
  describe "the cdb backend" do
14
14
  include Provider
15
- path = '/INT/dbde/dboverallsearch/port'
16
15
  path_to_cdb = File.join(File.dirname(__FILE__), '../../cdb/')
17
16
  version = 0
18
17
 
@@ -34,19 +33,6 @@ describe "the cdb backend" do
34
33
  result.should include("INT_module_app")
35
34
  end
36
35
 
37
- it "should deliver all parameters for an app from the cdb by path" do
38
- worker = Provider::CDB.new
39
- worker.protocol = 'http'
40
- worker.host = 'localhost:4567'
41
- worker.context = ''
42
- worker.env = 'STAGE'
43
-
44
- result = worker.get_parameters('testing/helloworld', 0)
45
-
46
- result['env'].should include("STAGE")
47
- result['patch_config_helloworld']['URL'].should include("www.neue-url.de")
48
- end
49
-
50
36
  it "should set a parameter in the cdb" do
51
37
  worker = Provider::CDB.new
52
38
  worker.protocol = 'http'
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ #Generated by Maven
2
+ #Mon Apr 01 01:02:03 CEST 2014
3
+ version=0.23.42-SNAPSHOT
4
+ webhost=com.example.www
5
+ mailhost=com.example.mail
@@ -0,0 +1,27 @@
1
+ set :application_name, "testapp"
2
+ set :module_name, "testmodule"
3
+
4
+ set :cleanup_workspace_before, ["source", "tmp"]
5
+
6
+ set :log_level, "INFO"
7
+ set :log_file, "deploy.log"
8
+ set :log_file_level, "DEBUG"
9
+
10
+ Deployment.deliver do
11
+
12
+ config = get_all_config_parameters
13
+ $log.writer.info "Got config parameters from cdb"
14
+
15
+ $log.writer.info "date_unique: #{date_unique}"
16
+
17
+ config['test_app_hosts'].each do |test_app_host|
18
+ $log.writer.info "doing something on #{test_app_host}"
19
+ rsync("target/", "/srv/testapp/")
20
+ remote_execute("export JAVA_HOME=/opt/java7; cd /srv/testapp/project_#{config['env'].downcase}/current/; . ./setantenv.sh; ant;", :remote_host => test_app_host)
21
+ end
22
+
23
+ report_by_mail
24
+ $log.writer.info "Sent mail to deployment team #{config['deploy_email_to']}"
25
+
26
+ $log.writer.info "Deployment done!"
27
+ end
@@ -0,0 +1,127 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'depengine'
3
+ require 'depengine/cli'
4
+ require 'tmpdir'
5
+ require 'fileutils'
6
+
7
+ describe "the date_unique method" do
8
+
9
+ before :each do
10
+ $recipe_config_backup = $recipe_config
11
+ $recipe_config = {
12
+ :deploy_home => "/tmp/deploy_home",
13
+ :recipe_base_dir => "/tmp/recipe_base_dir",
14
+ :env => "TEST",
15
+ :version => "42.23.0",
16
+ :log_level => "ERROR",
17
+ :skip_cdb_setup => true,
18
+ :application_name => "testenvapp",
19
+ :module_name => "testenvmodule"
20
+ }
21
+ end
22
+
23
+ after :each do
24
+ $recipe_config = $recipe_config_backup
25
+ end
26
+
27
+ it "should use a specified format" do
28
+ expect(Deployment::Worker.new.date_unique("%Y")).to match /^\d{4}$/
29
+ end
30
+
31
+ it "should have a default format" do
32
+ expect(Deployment::Worker.new.date_unique).to match /^\d{4}-\d{2}-\d{2}_\d+$/
33
+ end
34
+
35
+ it "should cache its object" do
36
+ w = Deployment::Worker.new
37
+ first = w.date_unique
38
+ sleep(1)
39
+ expect(w.date_unique).to eql first
40
+ end
41
+
42
+ end
43
+
44
+ describe "the copy_to_workspace method" do
45
+ before :each do
46
+ $recipe_config_backup = $recipe_config
47
+ $recipe_config = {
48
+ :deploy_home => Dir.tmpdir,
49
+ :recipe_base_dir => File.expand_path(File.dirname(__FILE__) + "/demo_recipe/"),
50
+ :env => "TEST",
51
+ :version => "42.23.0",
52
+ :log_level => "ERROR",
53
+ :skip_cdb_setup => true,
54
+ :application_name => "testenvapp",
55
+ :module_name => "testenvmodule"
56
+ }
57
+ end
58
+
59
+ after :each do
60
+ FileUtils.rm_rf $recipe_config[:deploy_home]
61
+ $recipe_config = $recipe_config_backup
62
+ end
63
+
64
+ context "given an array of directories" do
65
+ it "should copy all direcotries" do
66
+ $recipe_config[:copy_to_workspace] = ["config"]
67
+ Deployment::Worker.new
68
+ expect(File.directory?(File.join($recipe_config[:deploy_home], "config"))).to be true
69
+ expect(File.file?(File.join($recipe_config[:deploy_home], "config", "config.properties"))).to be true
70
+ end
71
+ end
72
+ context "set to a truthy object" do
73
+ it "should copy the config/ dir" do
74
+ $recipe_config[:copy_to_workspace] = true
75
+ Deployment::Worker.new
76
+ expect(File.file?(File.join($recipe_config[:deploy_home], "config", "config.properties"))).to be true
77
+ end
78
+ end
79
+ context "not given" do
80
+ it "should not copy anything" do
81
+ $recipe_config[:copy_to_workspace] = nil
82
+ Deployment::Worker.new
83
+ expect(File.file?(File.join($recipe_config[:deploy_home], "config", "config.properties"))).to be false
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "the report_by_mail method" do
89
+ before :each do
90
+ $recipe_config_backup = $recipe_config
91
+ $recipe_config = {
92
+ :deploy_home => Dir.tmpdir,
93
+ :recipe_base_dir => File.expand_path(File.dirname(__FILE__) + "/demo_recipe/"),
94
+ :env => "TEST",
95
+ :version => "42.23.0",
96
+ :log_level => "ERROR",
97
+ :skip_cdb_setup => true,
98
+ :application_name => "testenvapp",
99
+ :module_name => "testenvmodule"
100
+ }
101
+ end
102
+ after :each do
103
+ FileUtils.rm_rf $recipe_config[:deploy_home]
104
+ $recipe_config = $recipe_config_backup
105
+ end
106
+
107
+ it "should send a automatically filled mail via smtp" do
108
+ worker = Deployment::Worker.new
109
+ worker.cdb['deploy_email_from'] = "#{ENV['USER']}@localhost"
110
+ worker.cdb['deploy_email_to'] = "#{ENV['USER']}@localhost"
111
+ expect {worker.report_by_mail()}.to_not raise_error
112
+ end
113
+
114
+ it "should send a manually filled mail via smtp" do
115
+ worker = Deployment::Worker.new
116
+ h = {
117
+ :application_name => "thisisjustatestapplication",
118
+ :module_name => "andthisatestmodule",
119
+ :status => "somewhatsuccessful",
120
+ :message => "i dont know what could possibly go wrong",
121
+ :deploy_email_from => "#{ENV['USER']}@localhost",
122
+ :deploy_email_to => "#{ENV['USER']}@localhost"
123
+ }
124
+ expect {worker.report_by_mail(h)}.to_not raise_error
125
+ end
126
+
127
+ end