Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

War Conversion #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Description
===========

Installs and configures Jenkins CI server & node slaves. Resource providers to support automation via jenkins-cli, including job create/update.

Changelog
=========

- 0.7 - Jenkins was binding to the ip address of the primary interface instead of listening to all addresses which caused nginx to be unable to connect over localhost to Jenkins.
- 0.8 - Convert the recipe to use only the WAR file and not the Debian package.

Requirements
============

Expand Down Expand Up @@ -40,9 +47,10 @@ Where the jenkins_login recipe is simply:
jenkins_cli "login --username #{node[:jenkins][:username]} --password #{node[:jenkins][:password]}"

Attributes
==========
----------

* jenkins[:mirror] - Base URL for downloading Jenkins (server)
* jenkins[:version] - Specify the version of jenkins used. By default it is latest
* jenkins[:mirror_url] - Specify the URL to download the WAR from
* 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
Expand All @@ -69,20 +77,20 @@ Attributes
* 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][: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)

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/war-stable WAR. 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
-----------------
Expand Down Expand Up @@ -117,8 +125,8 @@ Uses the nginx::source recipe from the nginx cookbook to install an HTTP fronten

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
-------------------------------
'jenkins_cli' resource provider

This resource can be used to execute the Jenkins cli from your recipes. For example, install plugins via update center and restart Jenkins:

Expand Down Expand Up @@ -175,14 +183,14 @@ The script to generate groovy that manages a node can be used standalone. For e
% ruby manage_node.rb name slave-hostname remote_fs /home/jenkins ... | java -jar jenkins-cli.jar -s http://jenkins:8080/ groovy =

Issues
======
------

* CLI authentication - http://issues.jenkins-ci.org/browse/JENKINS-3796

* CLI *-node commands fail with "No argument is allowed: nameofslave" - http://issues.jenkins-ci.org/browse/JENKINS-5973

License & Author
================
License & Author(s):
-------------------

This is a downstream fork of Doug MacEachern's Hudson cookbook (https://github.com/dougm/site-cookbooks) and therefore deserves all the glory.

Expand All @@ -192,6 +200,7 @@ Contributor:: AJ Christensen <[email protected]>
Contributor:: Fletcher Nichol <[email protected]>
Contributor:: Roman Kamyk <[email protected]>
Contributor:: Darko Fabijan <[email protected]>
Contributor:: Scott Likens <[email protected]>

Copyright:: 2010, VMware, Inc

Expand Down
6 changes: 3 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# limitations under the License.
#

default[:jenkins][:mirror] = "http://mirrors.jenkins-ci.org"
default[:jenkins][:package_url] = "http://pkg.jenkins-ci.org"
default[:jenkins][:version]="latest"
default[:jenkins][:mirror_url] = "http://mirrors.jenkins-ci.org/war-stable"
default[:jenkins][:java_home] = ENV['JAVA_HOME']

default[:jenkins][:server][:home] = "/var/lib/jenkins"
Expand All @@ -36,7 +36,7 @@
end

default[:jenkins][:server][:port] = 8080
default[:jenkins][:server][:host] = node[:fqdn]
default[:jenkins][:server][:host] = "0.0.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double-plus-good!

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

default[:jenkins][:iptables_allow] = "disable"
Expand Down
8 changes: 4 additions & 4 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
maintainer "AJ Christensen"
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.md'))
version "0.6.3"
version "0.8"

%w(runit java).each { |cb| depends cb }
%w(iptables yum apt).each { |cb| recommends cb }
%w(runit java nginx).each { |cb| depends cb }
%w(iptables apt).each { |cb| recommends cb }
1 change: 1 addition & 0 deletions providers/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def action_run
jenkins_execute command do
cwd home
block { |stdout| new_resource.block.call(stdout) } if new_resource.block
only_if new_resource.only_if
end
end
3 changes: 2 additions & 1 deletion providers/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def post_job(url)
res.error! unless res.kind_of?(Net::HTTPSuccess)
end

#could also use: jenkins_cli "create-job #{@new_resource.job_name} < #{@new_resource.config}"
def action_create
unless job_exists
jenkins_cli "create-job #{@new_resource.job_name} < #{@new_resource.config}"
post_job(new_job_url)
end
end

Expand Down
81 changes: 32 additions & 49 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:: Scott Likens <[email protected]>
# Author:: AJ Christensen <[email protected]>
# Author:: Doug MacEachern <[email protected]>
# Author:: Fletcher Nichol <[email protected]>
Expand All @@ -21,7 +22,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

pid_file = "/var/run/jenkins/jenkins.pid"
pkey = "#{node[:jenkins][:server][:home]}/.ssh/id_rsa"
tmp = "/tmp"

Expand Down Expand Up @@ -65,43 +66,25 @@
backup false
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
action :create_if_missing
end
end

case node.platform
when "ubuntu", "debian"
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"
include_recipe "yum"

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

yum_key "jenkins" do
url "#{node.jenkins.package_url}/redhat/jenkins-ci.org.key"
action :add
end
directory "/usr/share/jenkins" do
action :create
owner "nobody"
group "nogroup"
recursive true
end

yum_repository "jenkins" do
description "repository for jenkins"
url "#{node.jenkins.package_url}/redhat/"
key "jenkins"
action :add
end
remote_file "/usr/share/jenkins/jenkins.war" do
source "#{node[:jenkins][:mirror_url]}/#{node[:jenkins][:version]}/jenkins.war"
owner "root"
group "root"
mode 0644
end

package "daemon"
include_recipe "java"
#"jenkins stop" may (likely) exit before the process is actually dead
#so we sleep until nothing is listening on jenkins.server.port (according to netstat)
ruby_block "netstat" do
Expand All @@ -119,12 +102,6 @@
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 @@ -145,20 +122,17 @@
action :nothing
end

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

template "/etc/default/jenkins"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this needs a notifies :restart, "service[jenkins]" or something, or is this one of the benefits of using WAR?


package "jenkins" do
template "/etc/init.d/jenkins" do
source "jenkins"
mode 0755
end

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

# restart if this run only added new plugins
Expand Down Expand Up @@ -198,3 +172,12 @@
end
end
end
service "jenkins" do
supports [ :stop, :start, :restart, :status ]
status_command "test -f #{pid_file} && kill -0 `cat #{pid_file}`"
action [:start,:enable]
end
execute "start jenkins" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by this execute block here. Why do we have to explicitly try to start it? Shouldn't that be handled by the service block directly above? Also, why do we now have two service blocks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These'll be purged when I add the s6 supervisor support. Cheers!

command "/etc/init.d/jenkins start"
not_if 'ps auxwww | grep [j]enkins'
end
3 changes: 3 additions & 0 deletions recipes/proxy_nginx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@
enable false
end
end
service "nginx" do
action [:start, :enable]
end
Loading