Skip to content

Commit

Permalink
Merge pull request #12 from christianewillman/add-sonarqube-scanner-r…
Browse files Browse the repository at this point in the history
…ecipe

Add: SonarQube Scanner Recipe
  • Loading branch information
pghalliday committed Feb 16, 2016
2 parents ef71e3a + d5f2c73 commit 17e15a9
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
7 changes: 7 additions & 0 deletions attributes/scanner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default['sonarqube']['scanner']['mirror'] = 'https://sonarsource.bintray.com/Distribution/sonar-scanner-cli'
default['sonarqube']['scanner']['version'] = '2.5'
default['sonarqube']['scanner']['checksum'] = 'e2ec5f4b73aa7911f10518e304db3af0146a4347b8d06fc1d4a36b8baec0d8cc'

default['sonarqube']['scanner']['host']['username'] = nil
default['sonarqube']['scanner']['host']['password'] = nil
default['sonarqube']['scanner']['host']['url'] = 'https://localhost:9000'
63 changes: 63 additions & 0 deletions recipes/scanner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
sonarqube_scanner_mirror = node['sonarqube']['scanner']['mirror']
sonarqube_scanner_version = node['sonarqube']['scanner']['version']
sonarqube_scanner_checksum = node['sonarqube']['scanner']['checksum']

sonarqube_user = node['sonarqube']['user']
sonarqube_group = node['sonarqube']['group']

sonarqube_scanner_zipfile_destination = ::File.join(Chef::Config[:file_cache_path], "sonar-scanner-#{sonarqube_scanner_version}.zip")
sonarqube_scanner_zipfile_source = "#{sonarqube_scanner_mirror}/sonar-scanner-#{sonarqube_scanner_version}.zip"

sonarqube_scanner_root_dir = "/opt/sonar-scanner-#{sonarqube_scanner_version}"
sonarqube_scanner_bin_dir = "#{sonarqube_scanner_root_dir}/bin"
sonarqube_scanner_properties_file = "#{sonarqube_scanner_root_dir}/conf/sonar-runner.properties"
sonarqube_scanner_profile_d_file = '/etc/profile.d/sonarqube-scanner.sh'

group sonarqube_group do
system true
end

user sonarqube_user do
gid sonarqube_group
system true
end

remote_file sonarqube_scanner_zipfile_destination do
source sonarqube_scanner_zipfile_source
mode 0644
checksum sonarqube_scanner_checksum
end

package 'unzip'

bash 'unzip SonarQube Scanner' do
code <<-EOF
unzip #{sonarqube_scanner_zipfile_destination} -d /opt/
EOF
not_if { ::File.exist?(sonarqube_scanner_root_dir) }
end

directory sonarqube_scanner_root_dir do
recursive true
mode 0755
owner sonarqube_user
group sonarqube_group
end

template sonarqube_scanner_properties_file do
source 'sonar-runner.properties.erb'
mode 0700
owner sonarqube_user
group sonarqube_group
end

template sonarqube_scanner_profile_d_file do
source 'sonar-scanner.profile.d.erb'
mode 0755
owner 'root'
group 'root'
variables(
sonarqube_scanner_bin_dir: sonarqube_scanner_bin_dir,
sonarqube_scanner_root_dir: sonarqube_scanner_root_dir
)
end
12 changes: 12 additions & 0 deletions templates/default/sonar-runner.properties.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Chef for <%= node['fqdn'] %>
# Local modifications will be overwritten.

#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

sonar.host.url=<%= node['sonarqube']['scanner']['host']['url'] %>
<% if node['sonarqube']['scanner']['host']['username'] && node['sonarqube']['scanner']['host']['password'] -%>
sonar.login=<%= node['sonarqube']['scanner']['host']['username'] %>
sonar.password=<%= node['sonarqube']['scanner']['host']['password'] %>
<% end -%>
2 changes: 2 additions & 0 deletions templates/default/sonar-scanner.profile.d.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export PATH=$PATH:<%= @sonarqube_scanner_bin_dir %>
export SONAR_RUNNER_HOME=<%= @sonarqube_scanner_root_dir %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'serverspec'

set :backend, :exec

describe file('/opt/sonar-scanner-2.5') do
it { should be_directory }
it { should be_readable.by_user('sonarqube') }
it { should be_executable.by_user('sonarqube') }
end

describe file('/opt/sonar-scanner-2.5/conf/sonar-runner.properties') do
it { should be_file }
it { should be_mode 700 }
it { should be_owned_by 'sonarqube' }
end

describe file('/etc/profile.d/sonarqube-scanner.sh') do
it { should be_file }
it { should be_readable.by_user('root') }
end

0 comments on commit 17e15a9

Please sign in to comment.