forked from heavywater/chef-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor nginx and Apache2 HTTP proxy support.
* Both strategies are broken out into the `proxy_nginx` and `proxy_apache2` recipes. They will be activated when the attribute `jenkins/http_proxy/variant` is set to either `nginx` or `apache2`. * The nginx family of attributes has been changed to `jenkins/http_proxy/*` so that they can work for both nginx and Apache2. * The Apache2 support has been beefed up.
- Loading branch information
Showing
6 changed files
with
171 additions
and
83 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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Cookbook Name:: jenkins | ||
# Recipe:: 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_recipe "apache2" | ||
|
||
package_provider = Chef::Provider::Package::Apt | ||
package "libapache2-mod-proxy-html" | ||
|
||
apache_module "proxy" | ||
apache_module "proxy_http" | ||
apache_module "vhost_alias" | ||
|
||
if node[:jenkins][:http_proxy][:www_redirect] == "enable" | ||
www_redirect = true | ||
apache_module "rewrite" | ||
else | ||
www_redirect = false | ||
end | ||
|
||
host_name = node[:jenkins][:http_proxy][:host_name] || node[:fqdn] | ||
|
||
template "#{node[:apache][:dir]}/sites-available/jenkins" do | ||
source "apache_jenkins.erb" | ||
owner 'root' | ||
group 'root' | ||
mode '0644' | ||
variables( | ||
:host_name => host_name, | ||
:host_aliases => node[:jenkins][:http_proxy][:host_aliases], | ||
:listen_ports => node[:jenkins][:http_proxy][:listen_ports], | ||
:www_redirect => www_redirect | ||
) | ||
|
||
if File.exists?("#{node[:apache][:dir]}/sites-enabled/jenkins") | ||
notifies :restart, 'service[apache2]' | ||
end | ||
end | ||
|
||
apache_site "000-default" do | ||
enable false | ||
end | ||
|
||
apache_site "jenkins" do | ||
if node[:jenkins][:http_proxy][:variant] == "apache2" | ||
enable true | ||
else | ||
enable false | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# | ||
# Cookbook Name:: jenkins | ||
# Recipe:: 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_recipe "nginx::source" | ||
|
||
if node[:jenkins][:http_proxy][:www_redirect] == "enable" | ||
www_redirect = true | ||
else | ||
www_redirect = false | ||
end | ||
|
||
host_name = node[:jenkins][:http_proxy][:host_name] || node[:fqdn] | ||
|
||
template "#{node[:nginx][:dir]}/sites-available/jenkins.conf" do | ||
source "nginx_jenkins.conf.erb" | ||
owner 'root' | ||
group 'root' | ||
mode '0644' | ||
variables( | ||
:host_name => host_name, | ||
:host_aliases => node[:jenkins][:http_proxy][:host_aliases], | ||
:listen_ports => node[:jenkins][:http_proxy][:listen_ports], | ||
:www_redirect => www_redirect, | ||
:max_upload_size => node[:jenkins][:http_proxy][:client_max_body_size] | ||
) | ||
|
||
if File.exists?("#{node[:nginx][:dir]}/sites-enabled/jenkins.conf") | ||
notifies :restart, 'service[nginx]' | ||
end | ||
end | ||
|
||
nginx_site "jenkins.conf" do | ||
if node[:jenkins][:http_proxy][:variant] == "nginx" | ||
enable true | ||
else | ||
enable false | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
<% if @www_redirect -%> | ||
<VirtualHost *:80> | ||
ProxyPass / http://localhost:8080/ | ||
ProxyPassReverse / http://localhost:8080/ | ||
ServerName www.<%= @host_name %> | ||
<% @host_aliases.each do |a| -%> | ||
ServerAlias www.<%= a %> | ||
<% end -%> | ||
|
||
RewriteEngine On | ||
RewriteCond %{HTTP_HOST} ^www.<%= @host_name %>$ [NC] | ||
RewriteRule ^/(.*)$ http://<%= @host_name %>/$1 [R=301,L] | ||
</VirtualHost> | ||
|
||
<% end -%> | ||
<VirtualHost *:80> | ||
ServerName <%= @host_name %> | ||
ProxyRequests Off | ||
<% @host_aliases.each do |a| -%> | ||
ServerAlias <%= a %> | ||
<% end -%> | ||
|
||
# Local reverse proxy authorization override | ||
# Most unix distribution deny proxy by default | ||
# (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu) | ||
<Proxy http://localhost:8080/*> | ||
<Proxy http://localhost:<%= node[:jenkins][:server][:port] %>/*> | ||
Order deny,allow | ||
Allow from all | ||
</Proxy> | ||
|
||
ProxyPreserveHost on | ||
ProxyPass / http://localhost:<%= node[:jenkins][:server][:port] %>/ | ||
ProxyPassReverse / http://localhost:<%= node[:jenkins][:server][:port] %>/ | ||
</VirtualHost> |