forked from heavywater/chef-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A whole bunch of shit ripped across from pennyworth. Sorry. <3
- Loading branch information
AJ Christensen
committed
Jan 17, 2012
1 parent
317ab19
commit 0da2094
Showing
18 changed files
with
151 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Based on hudson | ||
# Recipe:: default | ||
# | ||
# Author:: AJ Christensen <[email protected]> | ||
# Author:: Doug MacEachern <[email protected]> | ||
# Author:: Fletcher Nichol <[email protected]> | ||
# | ||
|
@@ -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 | ||
|
@@ -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| | ||
|
@@ -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 | ||
|
@@ -246,6 +175,8 @@ | |
}.size > 0 | ||
end | ||
end | ||
|
||
action :nothing | ||
end | ||
|
||
# Front Jenkins with an HTTP server | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.