Skip to content

Commit

Permalink
A whole bunch of shit ripped across from pennyworth. Sorry. <3
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ Christensen committed Jan 17, 2012
1 parent 317ab19 commit 0da2094
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 184 deletions.
7 changes: 4 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Where the jenkins_login recipe is simply:

jenkins_cli "login --username #{node[:jenkins][:username]} --password #{node[:jenkins][:password]}"

= ATTRIBUTES:
= ATTRIBUTES:

* jenkins[:mirror] - Base URL for downloading Jenkins (server)
* jenkins[:java_home] - Java install path, used for for cli commands
Expand All @@ -53,7 +53,7 @@ Where the jenkins_login recipe is simply:
* jenkins[:node][:launcher] - Node launch method, "jnlp", "ssh" or "command"
* jenkins[:node][:availability] - "always" keeps node on-line, "demand" off-lines when idle
* jenkins[:node][:in_demand_delay] - number of minutes for which jobs must be waiting in the queue before attempting to launch this slave.
* jenkins[:node][:idle_delay] - number of minutes that this slave must remain idle before taking it off-line.
* jenkins[:node][:idle_delay] - number of minutes that this slave must remain idle before taking it off-line.
* jenkins[:node][:env] - "Node Properties" -> "Environment Variables"
* jenkins[:node][:user] - user the slave runs as
* jenkins[:node][:ssh_host] - Hostname or IP Jenkins should connect to when launching an SSH slave
Expand All @@ -63,7 +63,7 @@ Where the jenkins_login recipe is simply:
* jenkins[:node][:ssh_private_key] - jenkins master defaults to: `~/.ssh/id_rsa` (created by the default recipe)
* jenkins[:node][:jvm_options] - SSH slave JVM options
* jenkins[:iptables_allow] - if iptables is enabled, add a rule passing 'jenkins[:server][:port]'
* jenkins[:http_proxy][:variant] - use `nginx` or `apache2` to proxy traffic to jenkins backend (`nil` by default)
* jenkins[:nginx][:http_proxy][:variant] - use `nginx` or `apache2` to proxy traffic to jenkins backend (`nil` by default)
* jenkins[:http_proxy][:www_redirect] - add a redirect rule for 'www.*' URL requests ("disable" by default)
* jenkins[:http_proxy][:listen_ports] - list of HTTP ports for the HTTP proxy to listen on ([80] by default)
* jenkins[:http_proxy][:host_name] - primary vhost name for the HTTP proxy to respond to (`node[:fqdn]` by default)
Expand Down Expand Up @@ -169,6 +169,7 @@ This is a downstream fork of Doug MacEachern's Hudson cookbook (https://github.c

Author:: Doug MacEachern (<[email protected]>)

Contributor:: AJ Christensen <[email protected]>
Contributor:: Fletcher Nichol <[email protected]>
Contributor:: Roman Kamyk <[email protected]>
Contributor:: Darko Fabijan <[email protected]>
Expand Down
7 changes: 5 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
# limitations under the License.
#

default[:jenkins][:mirror] = "http://updates.jenkins-ci.org"
default[:jenkins][:mirror] = "http://mirrors.jenkins-ci.org"
default[:jenkins][:package_url] = "http://pkg.jenkins-ci.org"
default[:jenkins][:java_home] = ENV['JAVA_HOME']

default[:jenkins][:server][:home] = "/var/lib/jenkins"
Expand All @@ -38,7 +39,7 @@
default[:jenkins][:server][:host] = node[:fqdn]
default[:jenkins][:server][:url] = "http://#{node[:jenkins][:server][:host]}:#{node[:jenkins][:server][:port]}"

default[:jenkins][:iptables_allow] = "enable"
default[:jenkins][:iptables_allow] = "disable"

#download the latest version of plugins, bypassing update center
#example: ["git", "URLSCM", ...]
Expand Down Expand Up @@ -120,3 +121,5 @@
default[:jenkins][:http_proxy][:host_name] = nil
default[:jenkins][:http_proxy][:host_aliases] = []
default[:jenkins][:http_proxy][:client_max_body_size] = "1024m"
default[:jenkins][:http_proxy][:basic_auth_username] = "jenkins"
default[:jenkins][:http_proxy][:basic_auth_password] = "jenkins"
4 changes: 2 additions & 2 deletions files/default/node_info.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.
Expand Down
4 changes: 2 additions & 2 deletions libraries/manage_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.
Expand Down
10 changes: 6 additions & 4 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
maintainer "Fletcher Nichol"
maintainer_email "[email protected]"
maintainer "AJ Christensen"
maintainer_email "[email protected]"
license "Apache 2.0"
description "Installs and configures Jenkins CI server & slaves"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.5"
%w(runit java iptables).each { |cb| depends cb }
version "0.6"

%w(runit java).each { |cb| depends cb }
%w(iptables yum apt).each { |cb| recommends cb }
4 changes: 1 addition & 3 deletions providers/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def action_run
args[:not_if] = @new_resource.not_if if @new_resource.not_if
args[:timeout] = @new_resource.timeout if @new_resource.timeout
args[:cwd] = @new_resource.cwd if @new_resource.cwd

status, stdout, stderr = output_of_command(args[:command], args)
if status.exitstatus == 0
@new_resource.block.call(stdout) if @new_resource.block
Expand All @@ -46,5 +46,3 @@ def action_run
handle_command_failures(status, command_output, args)
end
end


4 changes: 3 additions & 1 deletion providers/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#

def job_url
"#{@new_resource.url}/job/#{@new_resource.job_name}/config.xml"
job_url = "#{@new_resource.url}/job/#{@new_resource.job_name}/config.xml"
Chef::Log.debug "[jenkins_job] job_url: #{job_url}"
job_url
end

def new_job_url
Expand Down
156 changes: 49 additions & 107 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Based on hudson
# Recipe:: default
#
# Author:: AJ Christensen <[email protected]>
# Author:: Doug MacEachern <[email protected]>
# Author:: Fletcher Nichol <[email protected]>
#
Expand Down Expand Up @@ -60,81 +61,44 @@

node[:jenkins][:server][:plugins].each do |name|
remote_file "#{node[:jenkins][:server][:home]}/plugins/#{name}.hpi" do
source "#{node[:jenkins][:mirror]}/latest/#{name}.hpi"
source "#{node[:jenkins][:mirror]}/plugins/#{name}/latest/#{name}.hpi"
backup false
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
action :nothing
end

http_request "HEAD #{node[:jenkins][:mirror]}/latest/#{name}.hpi" do
message ""
url "#{node[:jenkins][:mirror]}/latest/#{name}.hpi"
action :head
if File.exists?("#{node[:jenkins][:server][:home]}/plugins/#{name}.hpi")
headers "If-Modified-Since" => File.mtime("#{node[:jenkins][:server][:home]}/plugins/#{name}.hpi").httpdate
end
notifies :create, resources(:remote_file => "#{node[:jenkins][:server][:home]}/plugins/#{name}.hpi"), :immediately
end
end

case node.platform
when "ubuntu", "debian"
# See http://jenkins-ci.org/debian/

case node.platform
when "debian"
remote = "#{node[:jenkins][:mirror]}/latest/debian/jenkins.deb"
package_provider = Chef::Provider::Package::Dpkg

package "daemon"
# These are both dependencies of the jenkins deb package
package "jamvm"
package "openjdk-6-jre"

package "psmisc"
key_url = "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key"

remote_file "#{tmp}/jenkins-ci.org.key" do
source "#{key_url}"
end

execute "add-jenkins-key" do
command "apt-key add #{tmp}/jenkins-ci.org.key"
action :nothing
end

when "ubuntu"
include_recipe "apt"
include_recipe "java"

apt_repository "jenkins" do
uri "http://pkg.jenkins-ci.org/debian"
distribution "binary/"
components [""]
key "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key"
action :add
end
end
include_recipe "apt"
include_recipe "java"

pid_file = "/var/run/jenkins/jenkins.pid"
install_starts_service = true


apt_repository "jenkins" do
uri "#{node.jenkins.package_url}/debian"
components %w[binary/]
key "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key"
action :add
end
when "centos", "redhat"
#see http://jenkins-ci.org/redhat/
key_url = "http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key"
include_recipe "yum"

remote = "#{node[:jenkins][:mirror]}/latest/redhat/jenkins.rpm"
package_provider = Chef::Provider::Package::Rpm
pid_file = "/var/run/jenkins.pid"
install_starts_service = false

execute "add-jenkins-key" do
command "rpm --import #{key_url}"
action :nothing
yum_key "jenkins" do
url "#{node.jenkins.package_url}/redhat/jenkins-ci.org.key"
action :add
end

yum_repository "jenkins" do
description "repository for jenkins"
url "#{node.jenkins.package_url}/redhat/"
key "jenkins"
action :add
end
end

#"jenkins stop" may (likely) exit before the process is actually dead
Expand All @@ -154,6 +118,12 @@
action :nothing
end

service "jenkins" do
supports [ :stop, :start, :restart, :status ]
status_command "test -f #{pid_file} && kill -0 `cat #{pid_file}`"
action :nothing
end

ruby_block "block_until_operational" do
block do
until IO.popen("netstat -lnt").entries.select { |entry|
Expand All @@ -167,68 +137,27 @@
url = URI.parse("#{node.jenkins.server.url}/job/test/config.xml")
res = Chef::REST::RESTRequest.new(:GET, url, nil).call
break if res.kind_of?(Net::HTTPSuccess) or res.kind_of?(Net::HTTPNotFound)
Chef::Log.debug "service[jenkins] not responding OK to GET /job/test/config.xml #{res.inspect}"
Chef::Log.debug "service[jenkins] not responding OK to GET / #{res.inspect}"
sleep 1
end
end
action :nothing
end

service "jenkins" do
supports [ :stop, :start, :restart, :status ]
#"jenkins status" will exit(0) even when the process is not running
status_command "test -f #{pid_file} && kill -0 `cat #{pid_file}`"
action :nothing
end

if node.platform == "ubuntu"
execute "setup-jenkins" do
command "echo w00t"
notifies :stop, "service[jenkins]", :immediately
notifies :create, "ruby_block[netstat]", :immediately #wait a moment for the port to be released
notifies :install, "package[jenkins]", :immediately
unless install_starts_service
notifies :start, "service[jenkins]", :immediately
end
notifies :create, "ruby_block[block_until_operational]", :immediately
creates "/usr/share/jenkins/jenkins.war"
end
else
local = File.join(tmp, File.basename(remote))

remote_file local do
source remote
backup false
notifies :stop, "service[jenkins]", :immediately
notifies :create, "ruby_block[netstat]", :immediately #wait a moment for the port to be released
notifies :run, "execute[add-jenkins-key]", :immediately
notifies :install, "package[jenkins]", :immediately
unless install_starts_service
notifies :start, "service[jenkins]", :immediately
end
if node[:jenkins][:server][:use_head] #XXX remove when CHEF-1848 is merged
action :nothing
end
end

http_request "HEAD #{remote}" do
only_if { node[:jenkins][:server][:use_head] } #XXX remove when CHEF-1848 is merged
message ""
url remote
action :head
if File.exists?(local)
headers "If-Modified-Since" => File.mtime(local).httpdate
end
notifies :create, "remote_file[#{local}]", :immediately
log "jenkins: install and start" do
notifies :install, "package[jenkins]", :immediately
notifies :start, "service[jenkins]", :immediately unless install_starts_service
notifies :create, "ruby_block[block_until_operational]", :immediately
not_if do
File.exists? "/usr/share/jenkins/jenkins.war"
end
end

#this is defined after http_request/remote_file because the package
#providers will throw an exception if `source' doesn't exist
template "/etc/default/jenkins"

package "jenkins" do
provider package_provider
source local if node.platform != "ubuntu"
action :nothing
notifies :create, "template[/etc/default/jenkins]", :immediately
end

# restart if this run only added new plugins
Expand All @@ -246,6 +175,8 @@
}.size > 0
end
end

action :nothing
end

# Front Jenkins with an HTTP server
Expand All @@ -255,3 +186,14 @@
when "apache2"
include_recipe "jenkins::proxy_apache2"
end

if node.jenkins.iptables_allow == "enable"
include_recipe "iptables"
iptables_rule "port_jenkins" do
if node[:jenkins][:iptables_allow] == "enable"
enable true
else
enable false
end
end
end
4 changes: 2 additions & 2 deletions recipes/node_jnlp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.
Expand Down
4 changes: 2 additions & 2 deletions recipes/node_ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.
Expand Down
4 changes: 2 additions & 2 deletions recipes/node_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.
Expand Down
Loading

0 comments on commit 0da2094

Please sign in to comment.