diff --git a/README.rdoc b/README.rdoc index 5230e08..a5cd270 100644 --- a/README.rdoc +++ b/README.rdoc @@ -5,8 +5,9 @@ This cookbook basically translates the install instructions from http://docs.cod = REQUIREMENTS: * java + jdk -* A database cookbook like 'mysql' if you like to run sonar in production. -The built in derby database is not recommended for production. +* A database cookbook like 'mysql' if you like to run sonar in production. The built in derby database is not recommended for production. However, make sure 'bind-address' value is correctly configured in the MySQL side. Recommended configuration to work with this Sonar recipe: + + node['mysql']['bind_address'] = 'localhost' = ATTRIBUTES: @@ -17,9 +18,36 @@ See attributes/default.rb for details. The cookbook installs sonar with derby database (default). Inlcude a proxy_* recipe to your run_list to access sonar over a proxy server. +A possible role definition, given as example, to put into roles/metrics-server.rb : + + name "metrics-server" + + description "Roles for a Metrics server" + + # List of recipes and roles to apply. Requires Chef 0.8, earlier versions use 'recipes()'. + run_list "recipe[mysql::server]", + "recipe[apache2]", + "recipe[sonar]", + "recipe[sonar::database_mysql]", + "recipe[sonar::proxy_apache]" + + # Attributes applied no matter what the node has set already. + override_attributes 'sonar' => { + 'web_domain' => 'metrics.example.com', + 'dir' => '/usr/share', + 'version' => '2.13.1', + 'os_kernel' => 'linux-x86-64', + 'jdbc_username' => "sonar", + 'jdbc_password' => "sonar", + 'jdbc_url' => "jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8", + 'jdbc_driverClassName' => "com.mysql.jdbc.Driver", + 'jdbc_validationQuery' => "select 1" + }, 'mysql' => { + 'bind_address' => 'localhost' + } + = Todos -* Implement 'dir' attribute to make installation path more flexible * Implement different Database backends like MySql * Implement plugin recipes eg. http://docs.codehaus.org/display/SONAR/PHP+Plugin Download jars to plugin folder, restart Sonar diff --git a/attributes/default.rb b/attributes/default.rb index c745c39..7b6c258 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,7 +1,7 @@ # General settings -default['sonar']['dir'] = "/opt/sonar" -default['sonar']['version'] = "2.11" -default['sonar']['checksum'] = "9d05e25ca79c33d673004444d89c8770" +default['sonar']['dir'] = "/opt" +default['sonar']['version'] = "2.13.1" +default['sonar']['checksum'] = "37e0502e07e197b8e3a382c64fac8e1d" default['sonar']['os_kernel'] = "linux-x86-32" default['sonar']['mirror'] = "http://dist.sonar.codehaus.org" @@ -30,3 +30,6 @@ default['sonar']['java_command'] = "java" default['sonar']['logfile_maxsize'] = "0" default['sonar']['syslog_loglevel'] = "NONE" + +# Sonar Plugin settings +default['sonar']['plugin_php']['url'] = 'http://repository.codehaus.org/org/codehaus/sonar-plugins/php/sonar-php-plugin/1.0/sonar-php-plugin-1.0.jar' diff --git a/metadata.rb b/metadata.rb index 4054101..1d4812e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -20,7 +20,7 @@ attribute "sonar/dir", :display_name => "Sonar directory", :description => "Path to sonar", - :default => "/opt/sonar" + :default => "/opt" attribute "sonar/version", :display_name => "Sonar version", diff --git a/recipes/database_mysql.rb b/recipes/database_mysql.rb index ba193ab..2476f97 100644 --- a/recipes/database_mysql.rb +++ b/recipes/database_mysql.rb @@ -1,7 +1,7 @@ include_recipe "mysql::server" # Setup sonar user -grants_path = "/opt/sonar/extras/database/mysql/create_database.sql" +grants_path = "#{node['sonar']['dir']}/sonar/extras/database/mysql/create_database.sql" template grants_path do source "create_mysql_database.sql.erb" diff --git a/recipes/default.rb b/recipes/default.rb index f859443..1bffe10 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -21,31 +21,31 @@ package "unzip" -remote_file "/opt/sonar-#{node['sonar']['version']}.zip" do +remote_file "#{node['sonar']['dir']}/sonar-#{node['sonar']['version']}.zip" do source "#{node['sonar']['mirror']}/sonar-#{node['sonar']['version']}.zip" mode "0644" checksum "#{node['sonar']['checksum']}" - not_if {File.exists?("/opt/sonar-#{node['sonar']['version']}.zip")} + not_if {File.exists?("#{node['sonar']['dir']}/sonar-#{node['sonar']['version']}.zip")} end -execute "unzip /opt/sonar-#{node['sonar']['version']}.zip -d /opt/" do - not_if {File.directory?("/opt/sonar-#{node['sonar']['version']}/")} +execute "unzip #{node['sonar']['dir']}/sonar-#{node['sonar']['version']}.zip -d #{node['sonar']['dir']}/" do + not_if {File.directory?("#{node['sonar']['dir']}/sonar-#{node['sonar']['version']}/")} end -link "/opt/sonar" do - to "/opt/sonar-#{node['sonar']['version']}" +link "#{node['sonar']['dir']}/sonar" do + to "#{node['sonar']['dir']}/sonar-#{node['sonar']['version']}" end service "sonar" do - stop_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh stop" - start_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh start" - status_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh status" - restart_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh restart" + stop_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh stop" + start_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh start" + status_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh status" + restart_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh restart" action :start end template "sonar.properties" do - path "/opt/sonar/conf/sonar.properties" + path "#{node['sonar']['dir']}/sonar/conf/sonar.properties" source "sonar.properties.erb" owner "root" group "root" @@ -54,7 +54,7 @@ end template "wrapper.conf" do - path "/opt/sonar/conf/wrapper.conf" + path "#{node['sonar']['dir']}/sonar/conf/wrapper.conf" source "wrapper.conf.erb" owner "root" group "root" diff --git a/recipes/plugin_php.rb b/recipes/plugin_php.rb new file mode 100644 index 0000000..0b26b9b --- /dev/null +++ b/recipes/plugin_php.rb @@ -0,0 +1,86 @@ +# +# Cookbook Name:: sonar +# Recipe:: default +# +# Copyright 2012, Fabien Udriot +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe "php" + +# INSTALL PHP MODULE FROM PACKAGE +package "php5-mysql" +package "php5-xdebug" +package "make" + +# UPGRADE PEAR +php_pear "PEAR" do + action :upgrade +end + +# REGISTER NEW PEAR CHANNELS +['pear.phpqatools.org', 'pear.symfony-project.com', 'pear.phpunit.de', 'pear.phpmd.org', 'pear.pdepend.org', 'components.ez.no', 'pear.typo3.org'].each do |channel| + php_pear_channel channel do + #action [:discover, :update] + action :discover + end +end + +# INSTALL PACKAGE +php_pear "phpqatools" do + channel "pear.phpqatools.org" + options "--alldeps" + action :install +end + +php_pear "PHP_CodeSniffer" do + channel "pear.php.net" + options "--alldeps" + action :install +end + +php_pear "PHPUnit" do + channel "pear.phpunit.de" + options "--alldeps" + action :install +end + +php_pear "PHP_PMD" do + channel "pear.phpmd.org" + options "--alldeps" + action :install +end + +php_pear "PHPCS_TYPO3_SniffPool" do + channel "pear.typo3.org" + options "--alldeps" + action :install +end + +php_pear "PHPCS_TYPO3v4_Standard" do + channel "pear.typo3.org" + options "--alldeps" + action :install +end + +bash "install-plugin-php" do + code <<-EOH +(cd #{node['sonar']['dir']}/sonar/extensions/plugins; wget #{node['sonar']['plugin_php']['url']}) +EOH + notifies :restart, resources(:service => "sonar") +end + +#service "sonar" do +# action :restart +#end diff --git a/recipes/proxy_apache.rb b/recipes/proxy_apache.rb index 51102c4..45710a8 100644 --- a/recipes/proxy_apache.rb +++ b/recipes/proxy_apache.rb @@ -39,7 +39,7 @@ include_recipe "apache2" template "sonar_server.conf" do - path "#{node[:nginx][:dir]}/sites-enabled/" + path "#{node[:apache][:dir]}/sites-available/sonar" source "apache_site.erb" owner "root" group "root" @@ -48,10 +48,12 @@ if node['sonar']['enable_mod_proxy_ajp'] == true include_recipe "apache2::mod_proxy_ajp" -else +else include_recipe "apache2::mod_proxy" end -apache_site "sonar_server.conf" do - enable :true -end \ No newline at end of file +apache_site "sonar" do + enable true + notifies :restart, resources(:service => "apache2") +end + diff --git a/templates/default/apache_site.erb b/templates/default/apache_site.erb index 4e70d88..02253e3 100644 --- a/templates/default/apache_site.erb +++ b/templates/default/apache_site.erb @@ -1,10 +1,20 @@ -ProxyRequests Off -ProxyPreserveHost On ServerName <%= node['sonar']['web_domain'] %> ServerAdmin admin@<%= node['sonar']['web_domain'] %> - ProxyPass / http://<%= node['sonar']['web_host'] %>:<%= node['sonar']['web_port'] %>/ - ProxyPassReverse / http://<%= node['sonar']['web_host'] %>:<%= node['sonar']['web_port'] %>/ - ErrorLog logs/<%= node['sonar']['web_domain'] %>/sonar/error.log - CustomLog logs/<%= node['sonar']['web_domain'] %>/sonar/access.log common - \ No newline at end of file + ProxyRequests Off + + # Local reverse proxy authorization override + # Most unix distribution deny proxy by default + # (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu) + :9000/*> + Order deny,allow + Allow from all + + + ProxyPreserveHost On + ProxyPass / http://<%= node['sonar']['web_domain'] %>:<%= node['sonar']['web_port'] %>/ + ProxyPassReverse / http://<%= node['sonar']['web_domain'] %>:<%= node['sonar']['web_port'] %>/ + + ErrorLog /var/log/apache2/sonar.error.log + CustomLog /var/log/apache2/sonar.access.log common + diff --git a/templates/default/maven_php_settings.xml.erb b/templates/default/maven_php_settings.xml.erb new file mode 100644 index 0000000..b143b4b --- /dev/null +++ b/templates/default/maven_php_settings.xml.erb @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sonar-profile + + jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 + com.mysql.jdbc.Driver + sonar + sonar + php + true + true + true + true + true + + + + + + + + + sonar-profile + +