Class: UcbDeployer::JiraDeployer

Inherits:
Deployer
  • Object
show all
Defined in:
lib/ucb_deployer/jira_deployer.rb

Constant Summary

Constants inherited from Deployer

Deployer::CONFIG_OPTIONS

Instance Attribute Summary

Attributes inherited from Deployer

#debug_mode, #version

Instance Method Summary collapse

Methods inherited from Deployer

#debug, #disable_web, #enable_web, #info, #load_config, #maintenance_template

Constructor Details

#initialize(config_file = "#{ENV['HOME']}/.ucb_deployer/config/jira/deploy.yml") ⇒ JiraDeployer

Returns a new instance of JiraDeployer.



5
6
7
8
# File 'lib/ucb_deployer/jira_deployer.rb', line 5

def initialize(config_file = "#{ENV['HOME']}/.ucb_deployer/config/jira/deploy.yml")
  self.debug("Using config file: #{config_file}")
  self.load_config(config_file)
end

Instance Method Details

#buildObject



30
31
32
33
# File 'lib/ucb_deployer/jira_deployer.rb', line 30

def build()
  self.info("Building application.")
  Dir.chdir("#{self.build_dir()}/src") { `sh #{self.build_dir()}/src/build.sh` }
end

#cas_authenticator_classObject



151
152
153
# File 'lib/ucb_deployer/jira_deployer.rb', line 151

def cas_authenticator_class()
  "org.soulwing.cas.apps.atlassian.JiraCasAuthenticator"
end

#cas_logout_urlObject



53
54
55
# File 'lib/ucb_deployer/jira_deployer.rb', line 53

def cas_logout_url()
  "/casLogout.action"
end

#config_entityengine_xmlObject

Updates the jira entityengine.xml file with the correct database configs



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ucb_deployer/jira_deployer.rb', line 113

def config_entityengine_xml()
  ee_xml = File.readlines(self.entityengine_xml()).map do |line|
    if m = /(#{Regexp.quote(self.entityengine_xml_db_token())})/.match(line)
      self.debug(m[0])
      new_str = "#{m.pre_match}#{entityengine_db}#{m.post_match}"
      self.debug(new_str)
      new_str
    elsif m = /(#{Regexp.quote(self.entityengine_xml_schema_token())})/.match(line)
      self.debug(m[0])
      new_str = "#{m.pre_match}#{self.entityengine_schema()}#{m.post_match}"
      self.debug(new_str)
      new_str
    else
      line
    end
  end
  
  File.open(self.entityengine_xml(), "w") do |io|
    ee_xml.each { |line| io.puts(line) }
  end
end

#config_ist_bannerObject

Places IST banner jpg in imaages directory



224
225
226
227
# File 'lib/ucb_deployer/jira_deployer.rb', line 224

def config_ist_banner()
  FileUtils.cp("#{UcbDeployer::RESOURCES_DIR}/ist_banner.jpg",
               "#{self.build_dir()}/src/webapp/images/")
end

#config_jira_application_propertiesObject

Sets the jira.home property in the file: jira-application.properties.



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ucb_deployer/jira_deployer.rb', line 199

def config_jira_application_properties()
  jira_props = File.readlines(self.jira_application_properties()).map do |line|
    if m = /(#{Regexp.quote(jira_home_token)})/.match(line)
      self.debug(m[0])
      new_str = "#{self.jira_home_token()} #{self.data_dir()}"
      self.debug(new_str)
      new_str
    elsif m = /(#{Regexp.quote(jira_projectkey_token)})/.match(line)
      self.debug(m[0])
      new_str = "#{self.jira_projectkey_token()} ([A-Z][A-Z0-9]+)"
      self.debug(new_str)
      new_str
    else
      line
    end
  end
  
  File.open(self.jira_application_properties(), "w") do |io|
    jira_props.each { |line| io.puts(line) }
  end
end

#config_seraph_config_xmlObject

Updates the jira seraph_config.xml file with the soulwing authenticator.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ucb_deployer/jira_deployer.rb', line 159

def config_seraph_config_xml()
  seraph_xml = File.readlines(self.seraph_config_xml()).map do |line|
    if m = /(#{Regexp.quote(self.seraph_config_xml_auth_class_token())})/.match(line)
      self.debug(m[0])
      new_str = "#{m.pre_match}#{self.cas_authenticator_class()}#{m.post_match}"
      self.debug(new_str)
      new_str
    elsif m = /(#{Regexp.quote(self.seraph_config_xml_logout_url_token())})/.match(line)
      self.debug(m[0])
      new_str = "#{m.pre_match}#{self.cas_server_url()}/logout#{m.post_match}"
      self.debug(new_str)
      new_str
    else
      line
    end
  end
  
  File.open(self.seraph_config_xml(), "w") do |io|
    seraph_xml.each { |line| io.puts(line) }
  end
end

#config_web_xmlObject

Updates the jira web.xml file with the soulwing (CAS library) authentication configuration



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ucb_deployer/jira_deployer.rb', line 72

def config_web_xml()
  web_xml = File.readlines(self.web_xml()).map do |line|
    if line =~ /#{web_xml_token}/
      template = File.open("#{DEPLOYER_HOME}/resources/jira_cas_web.xml") { |f| f.read() }
      line + ERB.new(template).result(self.send(:binding))
    else
      line
    end
  end
  
  File.open(self.web_xml(), "w") do |io|
    web_xml.each { |line| io.puts(line) }
  end      
end

#configureObject



20
21
22
23
24
25
26
27
28
# File 'lib/ucb_deployer/jira_deployer.rb', line 20

def configure()
  self.info("Configuring application.")
  self.config_web_xml()
  self.config_seraph_config_xml()
  self.config_entityengine_xml()
  self.config_jira_application_properties()
  self.config_ist_banner()
  self.reshuffle_jars()
end

#deployObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ucb_deployer/jira_deployer.rb', line 35

def deploy()
  self.info("Deploying application.")
  
  if File.exists?("#{self.deploy_dir()}/#{self.war_name()}")
    FileUtils.rm_rf(Dir["#{self.deploy_dir()}/#{self.war_name()}"])
  end

  FileUtils.mkdir("#{self.deploy_dir()}/#{self.war_name()}")
  `mv #{self.build_dir()}/src/dist-tomcat/atlassian-jira-*.war #{self.deploy_dir()}/#{self.war_name()}/#{self.war_name()}.war`
  `cd #{self.deploy_dir()}/#{self.war_name()}/ && jar -xvf #{self.war_name()}.war`
  `rm #{self.deploy_dir()}/#{self.war_name()}/#{self.war_name()}.war`
end

#entityengine_dbObject



102
103
104
# File 'lib/ucb_deployer/jira_deployer.rb', line 102

def entityengine_db()
  "field-type-name=\"postgres72\""
end

#entityengine_schemaObject



106
107
108
# File 'lib/ucb_deployer/jira_deployer.rb', line 106

def entityengine_schema()
  "schema-name=\"jira_app\""
end

#entityengine_xmlObject

Shortcut to jira entityengine.xml file



90
91
92
# File 'lib/ucb_deployer/jira_deployer.rb', line 90

def entityengine_xml()
  "#{self.build_dir()}/src/edit-webapp/WEB-INF/classes/entityengine.xml"
end

#entityengine_xml_db_tokenObject



94
95
96
# File 'lib/ucb_deployer/jira_deployer.rb', line 94

def entityengine_xml_db_token()
  "field-type-name=\"hsql\""
end

#entityengine_xml_schema_tokenObject



98
99
100
# File 'lib/ucb_deployer/jira_deployer.rb', line 98

def entityengine_xml_schema_token()
  "schema-name=\"PUBLIC\""
end

#exportObject



10
11
12
13
14
15
16
17
18
# File 'lib/ucb_deployer/jira_deployer.rb', line 10

def export()
  self.info("Exporting from: #{self.svn_project_url()}/jira-#{self.version()}")
  
  Dir.chdir("#{self.build_dir()}") do
    FileUtils.rm_rf("#{self.build_dir()}/src")
    `svn export #{self.svn_project_url()}/jira-#{self.version()}`
    FileUtils.mv("jira-#{self.version()}", "src")
  end
end

#jira_application_propertiesObject

Shortcut to jira-application.properties file



184
185
186
# File 'lib/ucb_deployer/jira_deployer.rb', line 184

def jira_application_properties()
  "#{self.build_dir()}/src/edit-webapp/WEB-INF/classes/jira-application.properties"
end

#jira_home_tokenObject



188
189
190
# File 'lib/ucb_deployer/jira_deployer.rb', line 188

def jira_home_token()
  "jira.home ="
end

#jira_projectkey_tokenObject



192
193
194
# File 'lib/ucb_deployer/jira_deployer.rb', line 192

def jira_projectkey_token()
  "jira.projectkey.pattern ="
end

#reshuffle_jarsObject

Remove jars from WEB-INF/lib that have been installed at the container level to avoid conflicts.



233
234
235
236
237
238
239
240
241
# File 'lib/ucb_deployer/jira_deployer.rb', line 233

def reshuffle_jars()
  FileUtils.mkdir_p("#{self.build_dir()}/src/edit-webapp/WEB-INF/lib/")
  FileUtils.cp(Dir["#{UcbDeployer::RESOURCES_DIR}/soulwing-casclient-*"],
               "#{self.build_dir()}/src/edit-webapp/WEB-INF/lib/")
  # These have been placed in $CATALINA_HOME/lib
  ["mail", "activation", "javamail", "commons-logging", "log4j"].each do |jar_file|
    FileUtils.rm_rf(Dir["#{self.build_dir()}/src/webapp/WEB-INF/lib/#{jar_file}-*"])
  end
end

#rollbackObject



48
49
# File 'lib/ucb_deployer/jira_deployer.rb', line 48

def rollback()
end

#seraph_config_xmlObject

Shortcut to jira seraph-config.xml file



138
139
140
# File 'lib/ucb_deployer/jira_deployer.rb', line 138

def seraph_config_xml()
  "#{self.build_dir()}/src/webapp/WEB-INF/classes/seraph-config.xml"
end

#seraph_config_xml_auth_class_tokenObject



142
143
144
145
# File 'lib/ucb_deployer/jira_deployer.rb', line 142

def seraph_config_xml_auth_class_token()
  "com.atlassian.jira.security.login.JiraSeraphAuthenticator"
  # "com.atlassian.jira.security.login.JiraOsUserAuthenticator"
end

#seraph_config_xml_logout_url_tokenObject



147
148
149
# File 'lib/ucb_deployer/jira_deployer.rb', line 147

def seraph_config_xml_logout_url_token()
  "/secure/Logout!default.jspa"
end

#web_xmlObject

Shortcut to jira web.xml file



60
61
62
# File 'lib/ucb_deployer/jira_deployer.rb', line 60

def web_xml()
  "#{self.build_dir()}/src/webapp/WEB-INF/web.xml"
end

#web_xml_tokenObject



64
65
66
# File 'lib/ucb_deployer/jira_deployer.rb', line 64

def web_xml_token()
  "<!--This filter is used to determine is there are any Application Errors before any pages are accessed"
end