Skip to content

Commit

Permalink
Merge pull request #2 from liatrio-chef/20161020_Update
Browse files Browse the repository at this point in the history
Fixed CHILD_STATUS
  • Loading branch information
drew-holt authored Oct 27, 2016
2 parents 708d694 + 21c2e17 commit 2aaa3e4
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://supermarket.chef.io"
source 'https://supermarket.chef.io'

metadata

Expand Down
48 changes: 23 additions & 25 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

config.vm.box = "liatrio/centos7chefjava"
config.vm.box = 'liatrio/centos7chefjava'

config.berkshelf.enabled = true
config.vm.provision "chef_solo" do |chef|
Expand All @@ -13,39 +12,38 @@ Vagrant.configure(2) do |config|
chef.add_recipe "jenkins-liatrio::create_creds"
chef.add_recipe "minitest-handler"
chef.json = {
"jenkins" => {
"master" => {
"host" => "localhost",
"port" => 8080,
#"repostiroy" => "http://pkg.jenkins-ci.org/redhat"
'jenkins' => {
'master' => {
'host' => 'localhost',
'port' => 8080,
# "repostiroy" => "http://pkg.jenkins-ci.org/redhat"
}
},
"jenkins_liatrio" => {
"install_plugins" => {
"plugins_list" => %w{git github naginator sonar},
"enablearchiva" => false,
"maven_mirror" => "http://localhost:8081/repository/internal",
"enablesonar" => false,
"sonarurl" => "http://192.168.1.10:9000",
"sonarjdbcurl" => "tcp://localhost:9092/sonar",
"githuburl" => "https://github.com/drewliatro/spring-petclinic/",
"giturl" => "https://github.com/drew-liatrio/spring-petclinic.git",
"hygieiaurl" => "http://192.168.100.10:8080/api/"
'jenkins_liatrio' => {
'install_plugins' => {
'plugins_list' => %w(git github naginator sonar),
'enablearchiva' => false,
'maven_mirror' => 'http://localhost:8081/repository/internal',
'enablesonar' => false,
'sonarurl' => 'http://192.168.1.10:9000',
'sonarjdbcurl' => 'tcp://localhost:9092/sonar',
'githuburl' => 'https://github.com/drewliatro/spring-petclinic/',
'giturl' => 'https://github.com/drew-liatrio/spring-petclinic.git',
'hygieiaurl' => 'http://192.168.100.10:8080/api/'
},
"create_job" => {
"maven_goals" => "clean install"
'create_job' => {
'maven_goals' => 'clean install'
}
}
}
end

config.vm.network :private_network, ip: "192.168.100.20"
config.vm.network "forwarded_port", guest: 8080, host: 18080
config.vm.network :private_network, ip: '192.168.100.20'
config.vm.network 'forwarded_port', guest: 8080, host: 18_080

config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
end

config.vm.provision "shell", inline: "firewall-cmd --permanent --add-port=8080/tcp && firewall-cmd --reload"

config.vm.provision 'shell', inline: 'firewall-cmd --permanent --add-port=8080/tcp && firewall-cmd --reload'
end
4 changes: 2 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# Author: Drew Holt <drew@liatrio.com>
#

default[:jenkins_liatrio][:packages] = %w{java-1.8.0-openjdk-devel java-1.8.0-openjdk maven maven-war-plugin git wget}
default[:jenkins_liatrio][:packages] = %w(java-1.8.0-openjdk-devel java-1.8.0-openjdk maven maven-war-plugin git wget)
default[:jenkins_liatrio][:sleep_interval_small] = 3
default[:jenkins_liatrio][:maven_mirror] = "http://localhost:8081/repository/internal"
default[:jenkins_liatrio][:maven_mirror] = 'http://localhost:8081/repository/internal'
22 changes: 11 additions & 11 deletions attributes/install_plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# Author: Drew Holt <drew@liatrio.com>
#

default[:jenkins_liatrio][:install_plugins][:plugins_list] = %w{git github naginator sonar}
default[:jenkins_liatrio][:install_plugins][:plugins_list] = %w(git github naginator sonar)
default[:jenkins_liatrio][:install_plugins][:enablearchiva] = false
default[:jenkins_liatrio][:install_plugins][:enablesonar] = false
default[:jenkins_liatrio][:install_plugins][:enablearchiva] = false
default[:jenkins_liatrio][:install_plugins][:sonarurl] = "http://localhost:9000"
default[:jenkins_liatrio][:install_plugins][:sonarjdbcurl] = "tcp://localhost:9092/sonar"
default[:jenkins_liatrio][:install_plugins][:jenkinsdlurl] = "http://pkg.jenkins-ci.org/redhat/jenkins-1.653-1.1.noarch.rpm"
default[:jenkins_liatrio][:install_plugins][:githuburl] = "https://github.com/drewliatro/spring-petclinic/"
default[:jenkins_liatrio][:install_plugins][:giturl] = "https://github.com/drew-liatrio/spring-petclinic.git"
default[:jenkins_liatrio][:install_plugins][:hygieia_url] = "http://192.168.100.10:8080/api/"
default[:jenkins_liatrio][:install_plugins][:enablesonar] = false
default[:jenkins_liatrio][:install_plugins][:enablearchiva] = false
default[:jenkins_liatrio][:install_plugins][:sonarurl] = 'http://localhost:9000'
default[:jenkins_liatrio][:install_plugins][:sonarjdbcurl] = 'tcp://localhost:9092/sonar'
default[:jenkins_liatrio][:install_plugins][:jenkinsdlurl] = 'http://pkg.jenkins-ci.org/redhat/jenkins-1.653-1.1.noarch.rpm'
default[:jenkins_liatrio][:install_plugins][:githuburl] = 'https://github.com/drewliatro/spring-petclinic/'
default[:jenkins_liatrio][:install_plugins][:giturl] = 'https://github.com/drew-liatrio/spring-petclinic.git'
default[:jenkins_liatrio][:install_plugins][:hygieia_url] = 'http://192.168.100.10:8080/api/'

#default[:jenkins][:nexus_repo] = "nexus.local"
#default[:jenkins][:job_name] = "petclinic-auto-1"
# default[:jenkins][:nexus_repo] = "nexus.local"
# default[:jenkins][:job_name] = "petclinic-auto-1"
22 changes: 10 additions & 12 deletions files/default/test/default_test.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
require 'minitest/spec'

def service_is_listening( port, service )
def service_is_listening(port, service)
assert system "sudo netstat -lp --numeric-ports | grep \":#{port}.*LISTEN.*#{service}\""
end

def web_check_match( url, check )
def web_check_match(url, check)
assert system "wget -q -O - #{url} | grep '#{check}'"
end

describe_recipe 'jenkins-liatrio::default' do
# use port attribute for this
# it "listens for http on tcp port 8080" do
# service_is_listening("8080", "java")
# end

# use port attribute for this
# it "listens for http on tcp port 8080" do
# service_is_listening("8080", "java")
# end

#it 'must match the web check Apache' do
# it 'must match the web check Apache' do
# web_check_match("http://127.0.0.1/", "Apache")
#end

# it should test for each plugin attribute that it is installed
# end

# it should test that each job was created
# it should test for each plugin attribute that it is installed

# it should test that each job was created
end
18 changes: 8 additions & 10 deletions recipes/create_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
# Create petclinic-simple job
template '/var/lib/jenkins/jobs/petclinic-simple-config.xml' do
source 'var/lib/jenkins/jobs/petclinic-simple-config.xml.erb'
mode '0644'
mode '0644'
owner node[:jenkins][:master][:user]
group node[:jenkins][:master][:group]
variables({
:nexus_repo => node[:jenkins_liatrio][:nexus_repo]
})
variables(nexus_repo: node[:jenkins_liatrio][:nexus_repo])
end

jenkins_job 'petclinic-simple-auto-1' do
Expand All @@ -23,11 +21,11 @@
# Create deploy-tomcat job
template '/var/lib/jenkins/jobs/deploy-tomcat-config.xml' do
source 'var/lib/jenkins/jobs/deploy-tomcat-config.xml.erb'
mode '0644'
mode '0644'
owner node[:jenkins][:master][:user]
group node[:jenkins][:master][:group]
variables({
})
})
end

jenkins_job 'deploy-tomcat' do
Expand All @@ -37,11 +35,11 @@
# selenium-chrome-petclinic-test
template '/var/lib/jenkins/jobs/selenium-chrome-petclinic-test-config.xml' do
source 'var/lib/jenkins/jobs/selenium-chrome-petclinic-test-config.xml.erb'
mode '0644'
mode '0644'
owner node[:jenkins][:master][:user]
group node[:jenkins][:master][:group]
variables({
})
})
end

jenkins_job 'selenium-chrome-petclinic-test' do
Expand All @@ -51,11 +49,11 @@
# selenium-firefox-petclinic-test
template '/var/lib/jenkins/jobs/selenium-firefox-petclinic-test-config.xml' do
source 'var/lib/jenkins/jobs/selenium-firefox-petclinic-test-config.xml.erb'
mode '0644'
mode '0644'
owner node[:jenkins][:master][:user]
group node[:jenkins][:master][:group]
variables({
})
})
end

jenkins_job 'selenium-firefox-petclinic-test' do
Expand Down
25 changes: 15 additions & 10 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
# Author: Drew Holt <drew@liatrio.com>
#


# Included English based of information found in this issue at github
# https://github.com/bbatsov/rubocop/issues/1747
require 'English'

node[:jenkins_liatrio][:packages].each do |pkg|
package pkg
end

include_recipe 'jenkins::master'

directory "/var/lib/jenkins/.m2" do
directory '/var/lib/jenkins/.m2' do
action :create
recursive true
owner node[:jenkins][:master][:user]
Expand All @@ -26,22 +31,22 @@
group node[:jenkins][:master][:group]
end

ruby_block "before_wait_for_jenkins" do
ruby_block 'before_wait_for_jenkins' do
block do
while true do
loop do
puts "curl http://#{node[:jenkins][:master][:host]}:#{node[:jenkins][:master][:port]}/jnlpJars/jenkins-cli.jar"
` curl http://#{node[:jenkins][:master][:host]}:#{node[:jenkins][:master][:port]}/jnlpJars/jenkins-cli.jar -X HEAD -I -s | grep "200 OK" `
exitstatus = $?.exitstatus
( puts "+++ +++ before_wait_for_jenkins should exit!" && break ) if 0 == exitstatus
puts "+++ +++ Sleeping in before_wait_for_jenkins..."
exitstatus = $CHILD_STATUS.exitstatus
(puts '+++ +++ before_wait_for_jenkins should exit!' && break) if 0 == exitstatus
puts '+++ +++ Sleeping in before_wait_for_jenkins...'
sleep node[:jenkins_liatrio][:sleep_interval_small]
end
end
#notifies :run, 'execute[get_jenkins_cli_jar]', :immediately
# notifies :run, 'execute[get_jenkins_cli_jar]', :immediately
end

execute "get_jenkins_cli_jar" do
execute 'get_jenkins_cli_jar' do
command "wget http://#{node[:jenkins][:master][:host]}:#{node[:jenkins][:master][:port]}/jnlpJars/jenkins-cli.jar"
cwd "/opt"
not_if { ::File.exists?('/opt/jenkins-cli.jar') }
cwd '/opt'
not_if { ::File.exist?('/opt/jenkins-cli.jar') }
end
1 change: 0 additions & 1 deletion recipes/install_plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
jenkins_plugin i
end


# link maven
template '/var/lib/jenkins/hudson.tasks.Maven.xml' do
source 'var/lib/jenkins/hudson.tasks.Maven.xml.erb'
Expand Down
5 changes: 2 additions & 3 deletions recipes/install_plugins_hygieia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

cookbook_file '/var/lib/jenkins/hygieia-publisher.hpi' do
source 'hygieia-publisher.hpi'
mode '0644'
mode '0644'
owner node[:jenkins][:master][:user]
group node[:jenkins][:master][:group]
action :create
end

execute 'install-plugin-hygieia-publisher' do
command "java -jar /opt/jenkins-cli.jar -s http://#{node[:jenkins][:master][:host]}:#{node[:jenkins][:master][:port]}/ install-plugin /var/lib/jenkins/hygieia-publisher.hpi"
not_if ("java -jar /opt/jenkins-cli.jar -s http://#{node[:jenkins][:master][:host]}:#{node[:jenkins][:master][:port]}/ list-plugins| grep hygieia-publisher")
not_if "java -jar /opt/jenkins-cli.jar -s http://#{node[:jenkins][:master][:host]}:#{node[:jenkins][:master][:port]}/ list-plugins| grep hygieia-publisher"
end

template '/var/lib/jenkins/jenkins.plugins.hygieia.HygieiaPublisher.xml' do
Expand All @@ -25,4 +25,3 @@
group node[:jenkins][:master][:group]
variables({})
end

4 changes: 2 additions & 2 deletions recipes/install_plugins_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

execute 'unzip_sonar-runner' do
command 'cd /var/lib/jenkins; unzip sonar-runner-dist-2.4.zip'
not_if do ::File.exists?('/var/lib/jenkins/sonar-runner-2.4') end
not_if { ::File.exist?('/var/lib/jenkins/sonar-runner-2.4') }
end

template '/var/lib/jenkins/hudson.plugins.sonar.SonarPublisher.xml' do
Expand Down Expand Up @@ -44,7 +44,7 @@

if node[:jenkins_liatrio][:install_plugins][:enablearchiva] == true
template '/var/lib/jenkins/.m2/settings.xml' do
source 'var/lib/jenkins/.m2/settings.xml.erb'
source 'var/lib/jenkins/.m2/settings.xml.erb'
mode '0644'
owner node[:jenkins][:user]
group node[:jenkins][:group]
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'chefspec'
require 'chefspec/berkshelf'
30 changes: 30 additions & 0 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Cookbook Name: jenkins-liatrio
# Spec::default
require 'spec_helper'

describe 'jenkins-liatrio::default' do
let(:chef_run) do
ChefSpec::SoloRunner.new(
platform: 'centos',
version: '7.2.1511'
).converge(described_recipe)
end

it 'includes jenkins::master recipe' do
expect(chef_run).to include_recipe('jenkins::master')
end

it 'creates jenkins\' .m2 directory' do
expect(chef_run).to create_directory('/var/lib/jenkins/.m2').with(
mode: '0755'
)
end

it 'places the settings.xml file in \'etc/maven/\'' do
expect(chef_run).to create_template('/etc/maven/settings.xml').with(
source: 'etc/maven/settings.xml.erb',
mode: '0755'
)
end
end

0 comments on commit 2aaa3e4

Please sign in to comment.