Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created August 23, 2011 15:44
Show Gist options
  • Save nicolasblanco/1165512 to your computer and use it in GitHub Desktop.
Save nicolasblanco/1165512 to your computer and use it in GitHub Desktop.
My Sprinkle script to setup a Continuous Integration server with Ruby 1.9/Jenkins/nginx/PostgreSQL
# Sprinkle setup script for our CI server (Ruby 1.9/Git/PostgreSQL/nginx reverse proxy)
#
package :build_essential do
description 'Build tools'
apt 'build-essential' do
# Update the sources and upgrade the lists before we build essentials
pre :install, ['aptitude update', 'aptitude safe-upgrade', 'aptitude full-upgrade']
end
end
package :ruby do
description 'Ruby Virtual Machine'
version '1.9.2'
source "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz" do
post :install, "gem update --system"
end
requires :ruby_dependencies
verify do
has_executable "ruby"
end
end
package :ruby_dependencies do
description 'Ruby Virtual Machine Build Dependencies'
apt %w(bison zlib1g-dev libssl-dev libreadline5-dev libncurses5-dev file)
verify do
has_apt "bison"
has_apt "zlib1g-dev"
has_apt "libssl-dev"
has_apt "libreadline5-dev"
has_apt "libncurses5-dev"
has_apt "file"
end
end
package :git, :provides => :scm do
description 'Git'
apt 'git-core'
verify do
has_apt 'git-core'
end
end
package :postgresql, :provides => :database do
description 'PostgreSQL Database'
apt %w(postgresql postgresql-client postgresql-contrib)
verify do
has_apt "postgresql"
has_apt "postgresql-client"
has_apt "postgresql-contrib"
end
end
package :bundler do
description "Bundler manages an application's dependencies"
gem "bundler"
verify do
has_gem "bundler"
end
end
package :imagemagick do
description "Image Magick"
apt "imagemagick"
verify do
has_apt "imagemagick"
end
end
package :jenkins do
description 'Jenkins CI Server'
apt "jenkins" do
pre :install, %{apt-get update}
end
requires :jenkins_apt_repository
verify do
has_apt "jenkins"
end
end
package :jenkins_apt_repository do
describe "APT sources for Jenkins"
runner %{bash -c 'wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -'}
runner %{bash -c 'echo "deb http://pkg.jenkins-ci.org/debian binary/" > /etc/apt/sources.list.d/jenkins.list'}
verify do
has_file "/etc/apt/sources.list.d/jenkins.list"
end
end
package :nginx, :provides => :webserver do
describe "Nginx web server"
apt "nginx"
verify do
has_apt "nginx"
end
end
package :nginx_jenkins_site do
description "Nginx Jenkins site"
requires :nginx
transfer "nginx_site", "/tmp" do
post :install, ["mv /tmp/nginx_site /etc/nginx/sites-available/jenkins", "ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/jenkins"]
end
verify do
has_symlink "/etc/nginx/sites-enabled/jenkins"
end
end
policy :ci, :roles => :app do
requires :build_essential
requires :scm
requires :ruby
requires :bundler
requires :database
requires :imagemagick
requires :jenkins
requires :webserver
requires :nginx_jenkins_site
end
deployment do
delivery :capistrano do
recipes 'deploy'
end
source do
prefix '/usr/local' # where all source packages will be configured to install
archives '/usr/local/sources' # where all source packages will be downloaded to
builds '/usr/local/build' # where all source packages will be built
end
end
server {
listen 80; # Listen on port 80 for IPv4 requests
server_name ci;
root /var/lib/jenkins;
access_log /var/log/nginx/jenkins_access.log;
error_log /var/log/nginx/jenkins_error.log;
location / {
# uncomment to protect via auth_basic
#
auth_basic "Restricted";
auth_basic_user_file /etc/jenkins_passwd;
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Optional configuration to detect and redirect iPhones
if ($http_user_agent ~* '(iPhone|iPod)') {
rewrite ^/$ /view/iphone/ redirect;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment