Skip to content

Commit

Permalink
## v0.7.0
Browse files Browse the repository at this point in the history
* General clean up, per Foodcritic compliance
* Fix several minor platform bugs on RedHat/CentOS
* Change service assumptions regarding Redhat/Centos
* Added several missing dependencies
* Fenced off debian/ubuntu specific cases in case switches
* Changed sshkey generation to use pure Ruby via gem, instead of execute.
* Made basic auth optional in proxy_apache2, as Jenkins comes with several of its own auth plugins
  • Loading branch information
Eric G. Wolfe committed May 25, 2012
1 parent f91495d commit dde35c2
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 333 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## v0.7.0

* General clean up, per Foodcritic compliance
* Fix several minor platform bugs on RedHat/CentOS
* Change service assumptions regarding Redhat/Centos
* Added several missing dependencies
* Fenced off debian/ubuntu specific cases in case switches
* Changed sshkey generation to use pure Ruby via gem, instead of execute.
* Made basic auth optional in proxy_apache2, as Jenkins comes with several of its own auth plugins
89 changes: 46 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,60 @@ If your Jenkins instance requires authentication, you'll either need to embed us

Where the jenkins_login recipe is simply:

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

Attributes
==========

* jenkins[:mirror] - Base URL for downloading Jenkins (server)
* jenkins[:java_home] - Java install path, used for for cli commands
* jenkins[:server][:home] - JENKINS_HOME directory
* jenkins[:server][:user] - User the Jenkins server runs as
* jenkins[:server][:group] - Jenkins user primary group
* jenkins[:server][:port] - TCP listen port for the Jenkins server
* jenkins[:server][:url] - Base URL of the Jenkins server
* jenkins[:server][:plugins] - Download the latest version of plugins in this list, bypassing update center
* jenkins[:node][:name] - Name of the node within Jenkins
* jenkins[:node][:description] - Jenkins node description
* jenkins[:node][:executors] - Number of node executors
* jenkins[:node][:home] - Home directory ("Remote FS root") of the node
* jenkins[:node][:labels] - Node labels
* jenkins[:node][:mode] - Node usage mode, "normal" or "exclusive" (tied jobs only)
* 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][: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
* jenkins[:node][:ssh_port] - SSH slave port
* jenkins[:node][:ssh_user] - SSH slave user name (only required if jenkins server and slave user is different)
* jenkins[:node][:ssh_pass] - SSH slave password (not required when server is installed via default recipe)
* 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[: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)
* jenkins[:http_proxy][:host_aliases] - optional list of other host aliases to respond to (empty by default)
* jenkins[:http_proxy][:client_max_body_size] - max client upload size ("1024m" by default, nginx only)
* jenkins['mirror'] - Base URL for downloading Jenkins (server)
* jenkins['java_home'] - Java install path, used for for cli commands
* jenkins['server']['home'] - JENKINS_HOME directory
* jenkins['server']['user'] - User the Jenkins server runs as
* jenkins['server']['group'] - Jenkins user primary group
* jenkins['server']['port'] - TCP listen port for the Jenkins server
* jenkins['server']['url'] - Base URL of the Jenkins server
* jenkins['server']['plugins'] - Download the latest version of plugins in this list, bypassing update center
* jenkins['node']['name'] - Name of the node within Jenkins
* jenkins['node']['description'] - Jenkins node description
* jenkins['node']['executors'] - Number of node executors
* jenkins['node']['home'] - Home directory ("Remote FS root") of the node
* jenkins['node']['labels'] - Node labels
* jenkins['node']['mode'] - Node usage mode, "normal" or "exclusive" (tied jobs only)
* 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']['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
* jenkins['node']['ssh_port'] - SSH slave port
* jenkins['node']['ssh_user'] - SSH slave user name (only required if jenkins server and slave user is different)
* jenkins['node']['ssh_pass'] - SSH slave password (not required when server is installed via default recipe)
* 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['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)
* jenkins['http_proxy']['host_aliases'] - optional list of other host aliases to respond to (empty by default)
* jenkins['http_proxy']['client_max_body_size'] - max client upload size ("1024m" by default, nginx only)
* jenkins['http_proxy']['basic_auth'] - boolean, whether basic auth gets enabled in proxy_apache2 or not. (default true)
* jenkins['http_proxy']['basic_auth_username'] - used in the proxy_apache2 recipe, (default jenkins)
* jenkins['http_proxy']['basic_auth_password'] - used in the proxy_apache2 recipe, (defualt jenkins)

Usage
=====

'default' recipe
----------------

Installs a Jenkins CI server using the http://jenkins-ci.org/redhat RPM. The recipe also generates an ssh private key and stores the ssh public key in the node 'jenkins[:pubkey]' attribute for use by the node recipes.
Installs a Jenkins CI server using the http://jenkins-ci.org/redhat RPM. The recipe also generates an ssh private key and stores the ssh public key in the node 'jenkins['pubkey']' attribute for use by the node recipes.

'node_ssh' recipe
-----------------

Creates the user and group for the Jenkins slave to run as and sets `.ssh/authorized_keys` to the 'jenkins[:pubkey]' attribute. The 'jenkins-cli.jar'[1] is downloaded from the Jenkins server and used to manage the nodes via the 'groovy'[2] cli command. Jenkins is configured to launch a slave agent on the node using its SSH slave plugin[3].
Creates the user and group for the Jenkins slave to run as and sets `.ssh/authorized_keys` to the 'jenkins['pubkey']' attribute. The 'jenkins-cli.jar'[1] is downloaded from the Jenkins server and used to manage the nodes via the 'groovy'[2] cli command. Jenkins is configured to launch a slave agent on the node using its SSH slave plugin[3].

[1] http://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
[2] http://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
Expand All @@ -110,12 +113,12 @@ Creates the home directory for the node slave and sets 'JENKINS_HOME' and 'JENKI
'proxy_nginx' recipe
--------------------

Uses the nginx::source recipe from the nginx cookbook to install an HTTP frontend proxy. To automatically activate this recipe set the `node[:jenkins][:http_proxy][:variant]` to `nginx`.
Uses the nginx::source recipe from the nginx cookbook to install an HTTP frontend proxy. To automatically activate this recipe set the `node['jenkins']['http_proxy']['variant']` to `nginx`.

'proxy_apache2' recipe
----------------------

Uses the apache2 recipe from the apache2 cookbook to install an HTTP frontend proxy. To automatically activate this recipe set the `node[:jenkins][:http_proxy][:variant]` to `apache2`.
Uses the apache2 recipe from the apache2 cookbook to install an HTTP frontend proxy. To automatically activate this recipe set the `node['jenkins']['http_proxy']['variant']` to `apache2`.

'jenkins_cli' resource provider
-------------------------------
Expand All @@ -132,12 +135,12 @@ This resource can be used to execute the Jenkins cli from your recipes. For exa

This resource can be used to configure nodes as the 'node_ssh' and 'node_windows' recipes do or "Launch slave via execution of command on the Master".

jenkins_node node[:fqdn] do
jenkins_node node['fqdn'] do
description "My node for things, stuff and whatnot"
executors 5
remote_fs "/var/jenkins"
launcher "command"
command "ssh -i my_key #{node[:fqdn]} java -jar #{remote_fs}/slave.jar"
command "ssh -i my_key #{node['fqdn']} java -jar #{remote_fs}/slave.jar"
env "ANT_HOME" => "/usr/local/ant", "M2_REPO" => "/dev/null"
end

Expand All @@ -151,9 +154,9 @@ This resource manages jenkins jobs, supporting the following actions:
The 'create' and 'update' actions require a jenkins job config.xml. Example:

git_branch = 'master'
job_name = "sigar-#{branch}-#{node[:os]}-#{node[:kernel][:machine]}"
job_name = "sigar-#{branch}-#{node['os']}-#{node['kernel']['machine']}"

job_config = File.join(node[:jenkins][:node][:home], "#{job_name}-config.xml")
job_config = File.join(node['jenkins']['node']['home'], "#{job_name}-config.xml")

jenkins_job job_name do
action :nothing
Expand All @@ -162,7 +165,7 @@ The 'create' and 'update' actions require a jenkins job config.xml. Example:

template job_config do
source "sigar-jenkins-config.xml"
variables :job_name => job_name, :branch => git_branch, :node => node[:fqdn]
variables :job_name => job_name, :branch => git_branch, :node => node['fqdn']
notifies :update, resources(:jenkins_job => job_name), :immediately
notifies :build, resources(:jenkins_job => job_name), :immediately
end
Expand Down
114 changes: 61 additions & 53 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,105 +21,113 @@
# limitations under the License.
#

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"
default[:jenkins][:server][:user] = "jenkins"

case node[:platform]
when "debian", "ubuntu"
default[:jenkins][:server][:group] = "nogroup"
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"
default['jenkins']['server']['user'] = "jenkins"

case node['platform']
when "debian", "ubuntu"
default['jenkins']['server']['group'] = "nogroup"
default['jenkins']['install_starts_service'] = true
default['jenkins']['pid_file'] = "/var/run/jenkins/jenkins.pid"
when "redhat", "centos", "scientific", "amazon"
default['jenkins']['install_starts_service'] = true
default['jenkins']['server']['group'] = node['jenkins']['server']['user']
default['jenkins']['pid_file'] = "/var/run/jenkins.pid"
else
default[:jenkins][:server][:group] = node[:jenkins][:server][:user]
default['jenkins']['install_starts_service'] = false
default['jenkins']['server']['group'] = node['jenkins']['server']['user']
end

default[:jenkins][:server][:port] = 8080
default[:jenkins][:server][:host] = node[:fqdn]
default[:jenkins][:server][:url] = "http://#{node[:jenkins][:server][:host]}:#{node[:jenkins][:server][:port]}"
default['jenkins']['server']['port'] = 8080
default['jenkins']['server']['host'] = node['fqdn']
default['jenkins']['server']['url'] = "http://#{node['jenkins']['server']['host']}:#{node['jenkins']['server']['port']}"

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

#download the latest version of plugins, bypassing update center
#example: ["git", "URLSCM", ...]
default[:jenkins][:server][:plugins] = []
default['jenkins']['server']['plugins'] = []

#working around: http://tickets.opscode.com/browse/CHEF-1848
#set to true if you have the CHEF-1848 patch applied
default[:jenkins][:server][:use_head] = false
default['jenkins']['server']['use_head'] = false

#See Jenkins >> Nodes >> $name >> Configure

#"Name"
default[:jenkins][:node][:name] = node[:fqdn]
default['jenkins']['node']['name'] = node['fqdn']

#"Description"
default[:jenkins][:node][:description] =
"#{node[:platform]} #{node[:platform_version]} " <<
"[#{node[:kernel][:os]} #{node[:kernel][:release]} #{node[:kernel][:machine]}] " <<
"slave on #{node[:hostname]}"
default['jenkins']['node']['description'] =
"#{node['platform']} #{node['platform_version']} " <<
"[#{node['kernel']['os']} #{node['kernel']['release']} #{node['kernel']['machine']}] " <<
"slave on #{node['hostname']}"

#"# of executors"
default[:jenkins][:node][:executors] = 1
default['jenkins']['node']['executors'] = 1

#"Remote FS root"
if node[:os] == "windows"
default[:jenkins][:node][:home] = "C:/jenkins"
elsif node[:os] == "darwin"
default[:jenkins][:node][:home] = "/Users/jenkins"
if node['os'] == "windows"
default['jenkins']['node']['home'] = "C:/jenkins"
elsif node['os'] == "darwin"
default['jenkins']['node']['home'] = "/Users/jenkins"
else
default[:jenkins][:node][:home] = "/home/jenkins"
default['jenkins']['node']['home'] = "/home/jenkins"
end

#"Labels"
default[:jenkins][:node][:labels] = (node[:tags] || []).join(" ")
default['jenkins']['node']['labels'] = (node['tags'] || []).join(" ")

#"Usage"
# "Utilize this slave as much as possible" -> "normal"
# "Leave this machine for tied jobs only" -> "exclusive"
default[:jenkins][:node][:mode] = "normal"
default['jenkins']['node']['mode'] = "normal"

#"Launch method"
# "Launch slave agents via JNLP" -> "jnlp"
# "Launch slave via execution of command on the Master" -> "command"
# "Launch slave agents on Unix machines via SSH" -> "ssh"
if node[:os] == "windows"
default[:jenkins][:node][:launcher] = "jnlp"
if node['os'] == "windows"
default['jenkins']['node']['launcher'] = "jnlp"
else
default[:jenkins][:node][:launcher] = "ssh"
default['jenkins']['node']['launcher'] = "ssh"
end

#"Availability"
# "Keep this slave on-line as much as possible" -> "always"
# "Take this slave on-line when in demand and off-line when idle" -> "demand"
default[:jenkins][:node][:availability] = "always"
default['jenkins']['node']['availability'] = "always"

# "In demand delay"
default[:jenkins][:node][:in_demand_delay] = 0
default['jenkins']['node']['in_demand_delay'] = 0
# "Idle delay"
default[:jenkins][:node][:idle_delay] = 1
default['jenkins']['node']['idle_delay'] = 1

#"Node Properties"
#[x] "Environment Variables"
default[:jenkins][:node][:env] = nil
default['jenkins']['node']['env'] = nil

default[:jenkins][:node][:user] = "jenkins-node"
default['jenkins']['node']['user'] = "jenkins-node"

#SSH options
default[:jenkins][:node][:ssh_host] = node[:fqdn]
default[:jenkins][:node][:ssh_port] = 22
default[:jenkins][:node][:ssh_user] = default[:jenkins][:node][:user]
default[:jenkins][:node][:ssh_pass] = nil
default[:jenkins][:node][:jvm_options] = nil
default['jenkins']['node']['ssh_host'] = node['fqdn']
default['jenkins']['node']['ssh_port'] = 22
default['jenkins']['node']['ssh_user'] = default['jenkins']['node']['user']
default['jenkins']['node']['ssh_pass'] = nil
default['jenkins']['node']['jvm_options'] = nil
#jenkins master defaults to: "#{ENV['HOME']}/.ssh/id_rsa"
default[:jenkins][:node][:ssh_private_key] = nil

default[:jenkins][:http_proxy][:variant] = nil
default[:jenkins][:http_proxy][:www_redirect] = "disable"
default[:jenkins][:http_proxy][:listen_ports] = [ 80 ]
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"
default['jenkins']['node']['ssh_private_key'] = nil

default['jenkins']['http_proxy']['variant'] = nil
default['jenkins']['http_proxy']['www_redirect'] = "disable"
default['jenkins']['http_proxy']['listen_ports'] = [ 80 ]
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'] = true
default['jenkins']['http_proxy']['basic_auth_username'] = "jenkins"
default['jenkins']['http_proxy']['basic_auth_password'] = "jenkins"
22 changes: 22 additions & 0 deletions attributes/proxy_apache2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Cookbook Name:: jenkins
# Attirbutes:: proxy_apache2
#
# Author:: Fletcher Nichol <[email protected]>
#
# Copyright 2011, Fletcher Nichol
#
# 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.
#

include_attribute "apache2"
21 changes: 21 additions & 0 deletions attributes/proxy_nginx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Cookbook Name:: jenkins
# Attributes:: proxy_nginx
#
# Author:: Fletcher Nichol <[email protected]>
#
# Copyright 2011, Fletcher Nichol
#
# 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.
#
include_attribute "nginx"
Loading

0 comments on commit dde35c2

Please sign in to comment.