diff --git a/.gitignore b/.gitignore index 32c4421..a6d6194 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .project -.buildpath \ No newline at end of file +.buildpath +.kitchen +.vagrant diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..5545e58 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,66 @@ +--- +driver_plugin: vagrant +driver_config: + require_chef_omnibus: true + +platforms: +- name: ubuntu-12.04 + driver_config: + box: opscode-ubuntu-12.04 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box +- name: ubuntu-10.04 + driver_config: + box: opscode-ubuntu-10.04 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box +- name: centos-6.4 + driver_config: + box: opscode-centos-6.4 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box +- name: centos-5.9 + driver_config: + box: opscode-centos-5.9 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box + +suites: +- name: default + run_list: + - recipe[minitest-handler] + - recipe[sonar_test] + attributes: + sonar: + os_kernel: "linux-x86-64" +- name: database_mysql + run_list: + - recipe[minitest-handler] + - recipe[sonar_test] + - recipe[sonar_test::database_mysql] + attributes: + sonar: + os_kernel: "linux-x86-64" + jdbc_url: "jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" + jdbc_driverClassName: "com.mysql.jdbc.Driver" + jdbc_validationQuery: "select 1" + mysql: + access_ips: + - "localhost" + - "%" + mysql: + server_debian_password: "test" + server_root_password: "test" + server_repl_password: "test" +- name: proxy_nginx + run_list: + - recipe[minitest-handler] + - recipe[sonar_test] + - recipe[sonar_test::proxy_nginx] + attributes: + sonar: + os_kernel: "linux-x86-64" +- name: proxy_apache + run_list: + - recipe[minitest-handler] + - recipe[sonar_test] + - recipe[sonar_test::proxy_apache] + attributes: + sonar: + os_kernel: "linux-x86-64" diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..89c17c4 --- /dev/null +++ b/Berksfile @@ -0,0 +1,6 @@ +site :opscode + +metadata + +cookbook "minitest-handler" +cookbook "sonar_test", :path => "./test/cookbooks/sonar_test" diff --git a/Berksfile.lock b/Berksfile.lock new file mode 100644 index 0000000..b86c3ef --- /dev/null +++ b/Berksfile.lock @@ -0,0 +1,61 @@ +{ + "sources": { + "sonar": { + "path": "." + }, + "minitest-handler": { + "locked_version": "0.2.1" + }, + "sonar_test": { + "path": "./test/cookbooks/sonar_test" + }, + "apt": { + "locked_version": "2.1.1" + }, + "openssl": { + "locked_version": "1.0.2" + }, + "database": { + "locked_version": "1.4.0" + }, + "mysql": { + "locked_version": "3.0.2" + }, + "build-essential": { + "locked_version": "1.4.2" + }, + "postgresql": { + "locked_version": "3.0.4" + }, + "aws": { + "locked_version": "0.101.4" + }, + "xfs": { + "locked_version": "1.1.0" + }, + "apache2": { + "locked_version": "1.7.0" + }, + "nginx": { + "locked_version": "1.7.0" + }, + "yum": { + "locked_version": "2.3.0" + }, + "runit": { + "locked_version": "1.1.6" + }, + "ohai": { + "locked_version": "1.1.10" + }, + "java": { + "locked_version": "1.12.0" + }, + "windows": { + "locked_version": "1.10.0" + }, + "chef_handler": { + "locked_version": "1.1.4" + } + } +} diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e1a397e --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem 'berkshelf' +gem 'test-kitchen', :group => :integration +gem 'kitchen-vagrant', :group => :integration diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..a36f819 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,148 @@ +GEM + remote: https://rubygems.org/ + specs: + activesupport (3.2.13) + i18n (= 0.6.1) + multi_json (~> 1.0) + addressable (2.3.5) + akami (1.2.0) + gyoku (>= 0.4.0) + nokogiri (>= 1.4.0) + berkshelf (2.0.9) + activesupport (~> 3.2.0) + addressable (~> 2.3.4) + buff-shell_out (~> 0.1) + celluloid (>= 0.14.0) + chozo (>= 0.6.1) + faraday (>= 0.8.5) + hashie (>= 2.0.2) + minitar (~> 0.5.4) + rbzip2 (~> 0.2.0) + retryable (~> 1.3.3) + ridley (~> 1.5.0) + solve (>= 0.5.0) + thor (~> 0.18.0) + buff-config (0.4.0) + buff-extensions (~> 0.3) + varia_model (~> 0.1) + buff-extensions (0.5.0) + buff-ignore (1.1.0) + buff-ruby_engine (0.1.0) + buff-shell_out (0.1.0) + buff-ruby_engine (~> 0.1.0) + builder (3.2.2) + celluloid (0.14.1) + timers (>= 1.0.0) + celluloid-io (0.14.1) + celluloid (>= 0.14.1) + nio4r (>= 0.4.5) + chozo (0.6.1) + activesupport (>= 3.2.0) + hashie (>= 2.0.2) + multi_json (>= 1.3.0) + coderay (1.0.9) + erubis (2.7.0) + faraday (0.8.8) + multipart-post (~> 1.2.0) + ffi (1.7.0) + gssapi (1.0.3) + ffi (>= 1.0.1) + gyoku (1.0.0) + builder (>= 2.1.2) + hashie (2.0.5) + httpclient (2.2.0.2) + httpi (0.9.7) + rack + i18n (0.6.1) + json (1.8.0) + kitchen-vagrant (0.11.0) + test-kitchen (~> 1.0.0.beta.1) + little-plugger (1.1.3) + logging (1.6.2) + little-plugger (>= 1.1.3) + method_source (0.8.1) + minitar (0.5.4) + mixlib-authentication (1.3.0) + mixlib-log + mixlib-log (1.6.0) + mixlib-shellout (1.1.0) + multi_json (1.7.7) + multipart-post (1.2.0) + net-http-persistent (2.9) + net-scp (1.1.1) + net-ssh (>= 2.6.5) + net-ssh (2.6.7) + nio4r (0.5.0) + nokogiri (1.5.10) + nori (1.1.5) + pry (0.9.12) + coderay (~> 1.0.5) + method_source (~> 0.8) + slop (~> 3.4) + rack (1.4.5) + rbzip2 (0.2.0) + retryable (1.3.3) + ridley (1.5.2) + addressable + buff-config (~> 0.2) + buff-extensions (~> 0.3) + buff-ignore (~> 1.1) + buff-shell_out (~> 0.1) + celluloid (~> 0.14.0) + celluloid-io (~> 0.14.0) + erubis + faraday (>= 0.8.4) + hashie (>= 2.0.2) + json (>= 1.7.7) + mixlib-authentication (>= 1.3.0) + net-http-persistent (>= 2.8) + net-ssh + nio4r (>= 0.5.0) + retryable + solve (>= 0.4.4) + varia_model (~> 0.1) + winrm (~> 1.1.0) + rubyntlm (0.1.1) + safe_yaml (0.9.5) + savon (0.9.5) + akami (~> 1.0) + builder (>= 2.1.2) + gyoku (>= 0.4.0) + httpi (~> 0.9) + nokogiri (>= 1.4.0) + nori (~> 1.0) + wasabi (~> 1.0) + slop (3.4.4) + solve (0.8.1) + test-kitchen (1.0.0.beta.2) + celluloid + mixlib-shellout + net-scp + net-ssh + pry + safe_yaml (~> 0.9.3) + thor + thor (0.18.1) + timers (1.1.0) + uuidtools (2.1.4) + varia_model (0.2.0) + buff-extensions (~> 0.2) + hashie (>= 2.0.2) + wasabi (1.0.0) + nokogiri (>= 1.4.0) + winrm (1.1.2) + gssapi (~> 1.0.0) + httpclient (~> 2.2.0.2) + logging (~> 1.6.1) + nokogiri (~> 1.5.0) + rubyntlm (~> 0.1.1) + savon (= 0.9.5) + uuidtools (~> 2.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + berkshelf + kitchen-vagrant + test-kitchen diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..51fca54 --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +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. diff --git a/README.md b/README.md index 9da9c23..e8860e8 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,25 @@ 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. +# RUNNING TESTS: + +You'll need the following installed: +* VirtualBox - https://www.virtualbox.org (tested with 4.2.16) +* Vagrant - http://www.vagrantup.com (tested with 1.2.4) +* The following gems: + * `gem install test-kitchen --pre` (tested with 1.0.0.beta.2) + * `gem install berkshelf` (tested with 2.0.10) + * `gem install kitchen-vagrant` (tested with 0.11.0) +* The following Vagrant plugins: + * `vagrant plugin install vagrant-berkshelf` (tested with 1.3.3) + * `vagrant plugin install vagrant-omnibus` (tested with 1.1.0) + * `vagrant plugin install vagrant-vbguest` (tested with 0.8.0) + +Running the tests: +* `kitchen list` will list test suites on various platforms. +* `kitchen test` will run ALL the tests. +* `kitchen test TEST_NAME` (e.g. `kitchen test default-centos-64`) will run only that given test. + # Todos * Implement `dir` attribute to make installation path more flexible diff --git a/Thorfile b/Thorfile new file mode 100644 index 0000000..b23ee16 --- /dev/null +++ b/Thorfile @@ -0,0 +1,12 @@ +# encoding: utf-8 + +require 'bundler' +require 'bundler/setup' +require 'berkshelf/thor' + +begin + require 'kitchen/thor_tasks' + Kitchen::ThorTasks.new +rescue LoadError + puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] +end diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..db88469 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,106 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + # All Vagrant configuration is done here. The most common configuration + # options are documented and commented below. For a complete reference, + # please see the online documentation at vagrantup.com. + + config.vm.hostname = "sonar-berkshelf" + + # Every Vagrant virtual environment requires a box to build off of. + config.vm.box = "centos-6.4-x86_64" + + # The url from where the 'config.vm.box' box will be fetched if it + # doesn't already exist on the user's system. + # config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box" + config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box" + + # Assign this VM to a host-only network IP, allowing you to access it + # via the IP. Host-only networks can talk to the host machine as well as + # any other machines on the same network, but cannot be accessed (through this + # network interface) by any external networks. + # Note that iptables may initially block access to the IP below. If you + # can't access the following IP, try doing a 'vagrant ssh' and run + # 'sudo service iptables stop' and try again. + config.vm.network :private_network, ip: "33.33.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + + # config.vm.network :public_network + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + + # Forward 9080 on host machine to 80 on guest to be able to test proxies + #config.vm.network :forwarded_port, guest: 80, host: 9080 + + # Forward 9000 on host machine to 9000 on guest to be able to test standalone Sonar app + #config.vm.network :forwarded_port, guest: 9000, host: 9000 + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider :virtualbox do |vb| + # # Don't boot with headless mode + # vb.gui = true + # + # # Use VBoxManage to customize the VM. For example to change memory: + # vb.customize ["modifyvm", :id, "--memory", "1024"] + # end + # + # View the documentation for the provider you're using for more + # information on available options. + + config.ssh.max_tries = 40 + config.ssh.timeout = 120 + + # The path to the Berksfile to use with Vagrant Berkshelf + # config.berkshelf.berksfile_path = "./Berksfile" + + # Enabling the Berkshelf plugin. To enable this globally, add this configuration + # option to your ~/.vagrant.d/Vagrantfile file + config.berkshelf.enabled = true + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to exclusively install and copy to Vagrant's shelf. + # config.berkshelf.only = [] + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to skip installing and copying to Vagrant's shelf. + # config.berkshelf.except = [] + + config.vm.provision :chef_solo do |chef| + chef.json = { + :mysql => { + :server_root_password => 'rootpass', + :server_debian_password => 'debpass', + :server_repl_password => 'replpass' + }, + :sonar => { + :os_kernel => 'linux-x86-64', + :web_domain => '33.33.33.10' + } + } + + chef.run_list = [ + "recipe[sonar_test::default]", + "recipe[sonar_test::database_mysql]", + "recipe[sonar_test::proxy_apache]" +# "recipe[sonar_test::proxy_nginx]" + ] + end + + # iptables keeps us from hitting the web server, etc, so lets turn that off + config.vm.provision :shell, :inline => "service iptables stop" +end diff --git a/attributes/default.rb b/attributes/default.rb index d802e6d..1d63e1c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,3 +1,8 @@ +# +# Cookbook Name:: sonar +# Attributes:: default +# + # General settings default['sonar']['dir'] = "/opt/sonar" default['sonar']['version'] = "2.11" @@ -23,6 +28,13 @@ default['sonar']['jdbc_driverClassName'] = "org.apache.derby.jdbc.ClientDriver" default['sonar']['jdbc_validationQuery'] = "values(1)" +# Allow direct access to the Sonar database via these IPs. Default only allows access +# from localhost. If you use things that write directly to the Sonar DB from remote +# locations (e.g. the sonar-maven-plugin), you may want to allow additional specific +# IPs (or '%', which allows open remote access). Note that node['mysql']['bind_address'] +# also controls who can actually connect to mysql. +default['sonar']['mysql']['access_ips'] = [ 'localhost' ] + # Wrapper settings eg. for performance improvements # @see http://docs.codehaus.org/display/SONAR/Performances default['sonar']['java_additional'] = "-server" @@ -33,4 +45,4 @@ default['sonar']['logfile_maxsize'] = "0" default['sonar']['syslog_loglevel'] = "NONE" -default['sonar']['options'] = {} +default['sonar']['options'] = {} \ No newline at end of file diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..a6de142 --- /dev/null +++ b/chefignore @@ -0,0 +1,96 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING +CHANGELOG* + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/files/default/tests/minitest/default_test.rb b/files/default/tests/minitest/default_test.rb deleted file mode 100644 index e89ad17..0000000 --- a/files/default/tests/minitest/default_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'minitest/spec' - -describe_recipe 'sonar::default' do - - # It's often convenient to load these includes in a separate - # helper along with - # your own helper methods, but here we just include them directly: - include MiniTest::Chef::Assertions - include MiniTest::Chef::Context - include MiniTest::Chef::Resources - - describe "installs" do - it "installs the files to the correct folder" do - directory(node['sonar']['dir']).must_exist - end - -# TODO ct 2012-06-27 How to check sonar process? -# it "starts the server" do -# service "sonar".must_be_running -# end - end - - describe "run_state" do - it "succeed" do - run_status.success?.must_equal true - end - end -end diff --git a/metadata.rb b/metadata.rb index 838ec8e..d59253c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,15 +1,16 @@ -maintainer "Christian Trabold" -maintainer_email "info@christian-trabold.de" -license "Apache 2.0" -description "Installs/Configures sonar" +name 'sonar' +maintainer 'Christian Trabold' +maintainer_email 'info@christian-trabold.de' +license 'Apache 2.0' +description 'Installs/Configures sonar' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.0.4" +version '0.1.0' recipe "sonar", "Includes the recipe to download and configure a sonar server" recipe "sonar::database_mysql", "Includes the recipe to install MySql-Server and create a database for sonar" recipe "sonar::proxy_apache", "Includes the recipe to install Apache-Webserver and proxy modules to access sonar. Creates a host for sonar." recipe "sonar::proxy_nginx", "Includes the recipe to install Nginx-Webserver and configures proxy to access sonar. Creates a host for sonar." -%w{ debian ubuntu }.each do |os| +%w{ debian ubuntu centos }.each do |os| supports os end @@ -17,6 +18,10 @@ depends cb end +%w{ apt openssl database mysql apache2 nginx }.each do |cb| + recommends cb +end + attribute "sonar/dir", :display_name => "Sonar directory", :description => "Path to sonar", diff --git a/recipes/database_mysql.rb b/recipes/database_mysql.rb index ba193ab..b242d31 100644 --- a/recipes/database_mysql.rb +++ b/recipes/database_mysql.rb @@ -1,17 +1,31 @@ +# +# Cookbook Name:: sonar +# Recipe:: database_mysql +# +# Adds mysql database server for use by Sonar. +# + include_recipe "mysql::server" +include_recipe "database::mysql" -# Setup sonar user -grants_path = "/opt/sonar/extras/database/mysql/create_database.sql" +mysql_connection_info = { + :host => 'localhost', + :username => 'root', + :password => node['mysql']['server_root_password'] +} -template grants_path do - source "create_mysql_database.sql.erb" - owner "root" - group "root" - mode "0600" +mysql_database 'sonar' do + connection mysql_connection_info action :create - notifies :restart, resources(:service => "sonar") end -execute "mysql-install-application-privileges" do - command "/usr/bin/mysql -u root #{node[:mysql][:server_root_password].empty? ? '' : '-p' }#{node[:mysql][:server_root_password]} < #{grants_path}" +node['sonar']['mysql']['access_ips'].each do |ip| + mysql_database_user node['sonar']['jdbc_username'] do + connection mysql_connection_info + password node['sonar']['jdbc_password'] + database_name 'sonar' + host ip + privileges [ :all ] + action :grant + end end diff --git a/recipes/default.rb b/recipes/default.rb index 27f19a5..d083e20 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -17,35 +17,45 @@ # limitations under the License. # +case node[:platform] +when "debian","ubuntu" + # update apt data to allow installation of java + include_recipe "apt" +end + include_recipe "java" package "unzip" -remote_file "/opt/sonar-#{node['sonar']['version']}.zip" do +sonar_install_path = "/opt/sonar-#{node['sonar']['version']}" +zip_file_path = "#{sonar_install_path}.zip" + +remote_file zip_file_path 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?(zip_file_path) } end -execute "unzip /opt/sonar-#{node['sonar']['version']}.zip -d /opt/" do - not_if { ::File.directory?("/opt/sonar-#{node['sonar']['version']}/") } +execute "unzip #{zip_file_path} -d /opt/" do + not_if { ::File.directory?("#{sonar_install_path}/") } end link "/opt/sonar" do - to "/opt/sonar-#{node['sonar']['version']}" + to sonar_install_path +end + +link "/etc/init.d/sonar" do + to "#{node['sonar']['dir']}/bin/#{node['sonar']['os_kernel']}/sonar.sh" 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" - action :start + supports :start => true, :stop => true, :status => true, :restart => true + action :enable end template "sonar.properties" do - path "/opt/sonar/conf/sonar.properties" + path "#{node['sonar']['dir']}/conf/sonar.properties" source "sonar.properties.erb" owner "root" group "root" @@ -57,10 +67,12 @@ end template "wrapper.conf" do - path "/opt/sonar/conf/wrapper.conf" + path "#{node['sonar']['dir']}/conf/wrapper.conf" source "wrapper.conf.erb" owner "root" group "root" mode 0644 notifies :restart, resources(:service => "sonar") end + +# wait here until sonar is up and running (listening on the given host/port) diff --git a/recipes/proxy_apache.rb b/recipes/proxy_apache.rb index 1d2075c..d505b4c 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_server.conf" source "apache_site_#{node['sonar']['web_template']}.erb" owner "root" group "root" @@ -50,8 +50,9 @@ include_recipe "apache2::mod_proxy_ajp" else include_recipe "apache2::mod_proxy" + include_recipe "apache2::mod_proxy_http" end apache_site "sonar_server.conf" do enable :true -end \ No newline at end of file +end diff --git a/templates/default/apache_site_default.erb b/templates/default/apache_site_default.erb index 4e70d88..06c90e7 100644 --- a/templates/default/apache_site_default.erb +++ b/templates/default/apache_site_default.erb @@ -3,8 +3,14 @@ ProxyPreserveHost On ServerName <%= node['sonar']['web_domain'] %> ServerAdmin admin@<%= node['sonar']['web_domain'] %> + + + Order Allow,Deny + Allow from all + + 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 + ErrorLog <%= node['apache']['log_dir'] %>/<%= node['sonar']['web_domain'] %>-error.log + CustomLog <%= node['apache']['log_dir'] %>/<%= node['sonar']['web_domain'] %>-access.log common \ No newline at end of file diff --git a/templates/default/create_mysql_database.sql.erb b/templates/default/create_mysql_database.sql.erb deleted file mode 100644 index a332df4..0000000 --- a/templates/default/create_mysql_database.sql.erb +++ /dev/null @@ -1,11 +0,0 @@ -# -# Create Sonar database and user. -# Generated by Chef. Local modifications will be overwritten. -# -# Command: mysql -u root -p < create_database.sql -# - -CREATE DATABASE IF NOT EXISTS sonar CHARACTER SET utf8 COLLATE utf8_general_ci; - -GRANT ALL ON sonar.* TO '<%= node['sonar']['jdbc_username'] %>'@'localhost' IDENTIFIED BY '<%= node['sonar']['jdbc_password'] %>'; -FLUSH PRIVILEGES; diff --git a/templates/default/nginx_site_default.erb b/templates/default/nginx_site_default.erb index 91f75b8..8cd97ed 100644 --- a/templates/default/nginx_site_default.erb +++ b/templates/default/nginx_site_default.erb @@ -15,4 +15,4 @@ server { error_log <%= node['nginx']['log_dir'] %>/sonar-error.log; access_log <%= node['nginx']['log_dir'] %>/sonar-access.log; -} +} \ No newline at end of file diff --git a/templates/default/sonar.properties.erb b/templates/default/sonar.properties.erb index f403e35..9070c38 100644 --- a/templates/default/sonar.properties.erb +++ b/templates/default/sonar.properties.erb @@ -143,4 +143,4 @@ sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 <% @options.sort.map do | option, value | -%> <%= option %>: <%= value %> <% end -%> -<% end -%> +<% end -%> \ No newline at end of file diff --git a/test/cookbooks/sonar_test/files/default/tests/minitest/database_mysql_test.rb b/test/cookbooks/sonar_test/files/default/tests/minitest/database_mysql_test.rb new file mode 100644 index 0000000..1bb9fe2 --- /dev/null +++ b/test/cookbooks/sonar_test/files/default/tests/minitest/database_mysql_test.rb @@ -0,0 +1,16 @@ +require 'minitest/spec' + +describe_recipe 'sonar::database_mysql' do + it "is currently running as a daemon" do + service(node['mysql']['service_name']).must_be_running + end + + it "added sonar database" do + result = assert_sh("mysql -u #{node['sonar']['jdbc_username']} -p#{node['sonar']['jdbc_password']} -e 'show databases;' sonar") + assert_includes result, "sonar" + end + + # TODO: Add test to make sure that all the appropriate users have been added to the database. + # it "added sonar user access to sonar database" + # end +end diff --git a/test/cookbooks/sonar_test/files/default/tests/minitest/default_test.rb b/test/cookbooks/sonar_test/files/default/tests/minitest/default_test.rb new file mode 100644 index 0000000..f56f500 --- /dev/null +++ b/test/cookbooks/sonar_test/files/default/tests/minitest/default_test.rb @@ -0,0 +1,31 @@ +require 'minitest/spec' + +describe_recipe 'sonar::default' do + + it "installs the files to the correct folder" do + directory("#{node['sonar']['dir']}-#{node['sonar']['version']}").must_exist + end + + it "symlinks to extracted directory" do + link(node['sonar']['dir']).must_exist.with( + :link_type, :symbolic).and(:to, "#{node['sonar']['dir']}-#{node['sonar']['version']}") + end + + it "creates symlink from init.d to init script" do + link("/etc/init.d/sonar").must_exist.with( + :link_type, :symbolic).and(:to, "#{node['sonar']['dir']}/bin/#{node['sonar']['os_kernel']}/sonar.sh") + end + + it "is currently running as a daemon" do + service("sonar").must_be_running + end + + it "boots on startup" do + service("sonar").must_be_enabled + end + + # TODO: Verify that Sonar application is actually working (hit + # the URL and make sure we get a 200 response code). + # it "is accessible via direct Sonar standalone app" do + # end +end diff --git a/test/cookbooks/sonar_test/files/default/tests/minitest/proxy_apache_test.rb b/test/cookbooks/sonar_test/files/default/tests/minitest/proxy_apache_test.rb new file mode 100644 index 0000000..36fb29b --- /dev/null +++ b/test/cookbooks/sonar_test/files/default/tests/minitest/proxy_apache_test.rb @@ -0,0 +1,21 @@ +require 'minitest/spec' + +describe_recipe 'sonar::proxy_apache' do + it "sonar site is enabled" do + site_enabled = "#{node['apache']['dir']}/sites-enabled/sonar_server.conf" + + site_available = "#{node['apache']['dir']}/sites-available/sonar_server.conf" + case node[:platform] + when 'ubuntu', 'debian' + site_available = "../sites-available/sonar_server.conf" + end + + link(site_enabled).must_exist.with(:link_type, :symbolic).and( + :to, site_available) + end + + # TODO: Verify that Sonar application is actually working (hit + # the proxy URL and make sure we get a 200 response code). + # it "is accessible via apache proxy" do + # end +end diff --git a/test/cookbooks/sonar_test/files/default/tests/minitest/proxy_nginx_test.rb b/test/cookbooks/sonar_test/files/default/tests/minitest/proxy_nginx_test.rb new file mode 100644 index 0000000..a37c122 --- /dev/null +++ b/test/cookbooks/sonar_test/files/default/tests/minitest/proxy_nginx_test.rb @@ -0,0 +1,15 @@ +require 'minitest/spec' + +describe_recipe 'sonar::proxy_nginx' do + it "sonar site is enabled" do + site_enabled = "#{node['nginx']['dir']}/sites-enabled/sonar_server.conf" + site_available = "#{node['nginx']['dir']}/sites-available/sonar_server.conf" + link(site_enabled).must_exist.with(:link_type, :symbolic).and( + :to, site_available) + end + + # TODO: Verify that Sonar application is actually working (hit + # the proxy URL and make sure we get a 200 response code). + # it "is accessible via nginx proxy" do + # end +end diff --git a/test/cookbooks/sonar_test/metadata.rb b/test/cookbooks/sonar_test/metadata.rb new file mode 100644 index 0000000..e7b3603 --- /dev/null +++ b/test/cookbooks/sonar_test/metadata.rb @@ -0,0 +1,10 @@ +maintainer "Paul Dunnavant" +maintainer_email "pdunnavant@gmail.com" +license "Apache 2.0" +description "Installs/Configures sonar_test" +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version "0.1.0" + +%w{ sonar openssl database nginx apache2 }.each do |cb| + depends cb +end diff --git a/test/cookbooks/sonar_test/recipes/database_mysql.rb b/test/cookbooks/sonar_test/recipes/database_mysql.rb new file mode 100644 index 0000000..27058ca --- /dev/null +++ b/test/cookbooks/sonar_test/recipes/database_mysql.rb @@ -0,0 +1,6 @@ +# +# Cookbook Name:: sonar_test +# Recipe:: database_mysql +# + +include_recipe 'sonar::database_mysql' \ No newline at end of file diff --git a/test/cookbooks/sonar_test/recipes/default.rb b/test/cookbooks/sonar_test/recipes/default.rb new file mode 100644 index 0000000..d1ae0bb --- /dev/null +++ b/test/cookbooks/sonar_test/recipes/default.rb @@ -0,0 +1,6 @@ +# +# Cookbook Name:: sonar_test +# Recipe:: default +# + +include_recipe 'sonar' \ No newline at end of file diff --git a/test/cookbooks/sonar_test/recipes/proxy_apache.rb b/test/cookbooks/sonar_test/recipes/proxy_apache.rb new file mode 100644 index 0000000..f1e0b09 --- /dev/null +++ b/test/cookbooks/sonar_test/recipes/proxy_apache.rb @@ -0,0 +1,6 @@ +# +# Cookbook Name:: sonar_test +# Recipe:: proxy_apache +# + +include_recipe 'sonar::proxy_apache' \ No newline at end of file diff --git a/test/cookbooks/sonar_test/recipes/proxy_nginx.rb b/test/cookbooks/sonar_test/recipes/proxy_nginx.rb new file mode 100644 index 0000000..20110b7 --- /dev/null +++ b/test/cookbooks/sonar_test/recipes/proxy_nginx.rb @@ -0,0 +1,6 @@ +# +# Cookbook Name:: sonar_test +# Recipe:: proxy_nginx +# + +include_recipe 'sonar::proxy_nginx' \ No newline at end of file