Skip to content

Commit

Permalink
Adding vagrant, bundler, and foreman.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale Worsley committed Feb 2, 2012
1 parent 4388fad commit 3a5a261
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .env
@@ -0,0 +1,5 @@
RAILS_ENV=development
RAILS_PORT=3000

SPHINX_PORT=9999
SPHINX_CONFIG=./config/development.sphinx.conf
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -30,3 +30,4 @@ Gemfile.lock
*.swp
*.swo
GeoLiteCity.dat
.vagrant
56 changes: 56 additions & 0 deletions Gemfile
@@ -0,0 +1,56 @@
source :rubygems
source "http://gems.github.com/"

gem "ambethia-smtp-tls", "1.0", :require => "smtp-tls", :path => 'vendor/gems/ambethia-smtp-tls-1.0'
gem "ancestry", "1.2.3", :require => "ancestry", :path => 'vendor/gems/ancestry-1.2.3'
gem "aws-s3", "0.6.2", :require => "aws/s3", :path => 'vendor/gems/aws-s3-0.6.2'
gem "babosa", "0.3.5"
gem "bluecloth", "2.1.0"
gem "builder", "2.1.2"
gem "carlosparamio-geoplanet", "0.2.2", :require => "geoplanet", :path => 'vendor/gems/carlosparamio-geoplanet-0.2.2'
gem "columnize", "0.3.4"
gem "daemon-spawn", "0.4.2", :require => "daemon_spawn"
gem "daemons", "1.1.4"
gem "dbf", "1.2.9"
gem "delayed_job", "2.0.3"
gem "delayed_paperclip", "0.6.5", :path => 'vendor/gems/delayed_paperclip-0.6.5'
gem "fastercsv", "1.5.4"
gem "flickraw", "0.8.3", :path => 'vendor/gems/flickraw-0.8.3'
gem "friendly_id", "3.2.1.1"
gem "hoptoad_notifier", "2.3.3", :path => 'vendor/gems/hoptoad_notifier-2.3.3'
gem "hpricot", "0.8.4"
gem "htmlentities", "4.0.0", :path => 'vendor/gems/htmlentities-4.0.0'
gem "i18n", "0.5.0"
gem "json", "1.6.1"
gem "koala", "1.1.0"
gem "mime-types", "1.17.1", :require => "mime/types"
gem "mojombo-chronic", "0.3.0", :require => "chronic", :path => 'vendor/gems/mojombo-chronic-0.3.0'
gem "multi_json", "1.0.3"
gem "multipart-post", "1.1.3"
gem "nofxx-georuby", "1.9.2", :require => "geo_ruby"
gem "nokogiri", "1.4.7"
gem "objectify-xml", "0.2.3", :require => "objectify_xml"
gem "omniauth", "0.2.6"
gem "paperclip", "2.3.8", :path => 'vendor/gems/paperclip-2.3.8'
gem "pg", "0.11.0"
gem "preferences", "0.4.2"
gem "rack", "1.1.2"
gem "rails", "2.3.12"
gem "rdoc"
gem "rest-client", "1.6.7", :require => "rest_client"
gem "riddle", "1.4.0"
gem "rubyist-aasm", "2.0.2", :require => "aasm", :path => 'vendor/gems/rubyist-aasm-2.0.2'
gem "spatial_adapter", "1.3.1"
gem "thinking-sphinx", "1.4.6", :require => "thinking_sphinx"
gem "ts-delayed-delta", "1.1.1", :require => "thinking_sphinx/deltas/delayed_delta"
gem "tzinfo", "0.3.30"
gem "will_paginate", "2.3.15"
gem "xml-simple", "1.0.12", :require => "xmlsimple", :path => 'vendor/gems/xml-simple-1.0.12'

group :development, :test do
gem "foreman"
gem "machinist", "1.0.6"
gem "mocha", "0.9.4", :path => 'vendor/gems/mocha-0.9.4'
gem "faker", "1.0.1"
gem "ruby-debug", "0.10.4"
end
3 changes: 3 additions & 0 deletions Procfile
@@ -0,0 +1,3 @@
web: ./script/server --environment=$RAILS_ENV --port=$RAILS_PORT
shpinx: searchd --console --port $SPHINX_PORT --config $SPHINX_CONFIG
worker: bundle exec rake jobs:work
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -10,3 +10,5 @@ require 'rdoc/task'
require 'tasks/rails'
require 'thinking_sphinx/tasks'
require 'thinking_sphinx/deltas/delayed_delta/tasks'

require 'delayed/tasks'
29 changes: 29 additions & 0 deletions Vagrantfile
@@ -0,0 +1,29 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "puppet-squeeze-64"

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://puppetlabs.s3.amazonaws.com/pub/squeeze64.box"

# Boot with a GUI so you can see the screen. (Default is headless)
config.vm.boot_mode = :gui

config.vm.forward_port 3000, 3000

# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file inaturalist.pp in the manifests_path directory.
#
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "vagrant/manifests"
puppet.module_path = "vagrant/modules"
puppet.manifest_file = "inaturalist.pp"
end

end
14 changes: 14 additions & 0 deletions config/boot.rb
Expand Up @@ -106,5 +106,19 @@ def read_environment_rb
end
end

class Rails::Boot
def run
load_initializer

Rails::Initializer.class_eval do
def load_gems
@bundler_loaded ||= Bundler.require :default, Rails.env
end
end

Rails::Initializer.run(:set_load_path)
end
end

# All that for this:
Rails.boot!
4 changes: 2 additions & 2 deletions config/environment.rb
Expand Up @@ -74,7 +74,7 @@
# Added from the acts_as_authenticated plugin 6/3/07
config.active_record.observers = :user_observer, :listed_taxon_sweeper

# Gems
# Gems, see also Gemfile
config.gem 'will_paginate', :version => '2.3.15'
config.gem 'rubyist-aasm', :lib => 'aasm', :source => 'http://gems.github.com', :version => '2.0.2'
config.gem "dbf", :version => "<= 1.2.9"
Expand Down Expand Up @@ -111,7 +111,7 @@
config.gem "friendly_id", :version => "~> 3.2.1"
config.gem "koala"
config.gem "preferences"

# Set default time zone to UTC
config.time_zone = 'UTC'
end
Expand Down
20 changes: 20 additions & 0 deletions config/preinitializer.rb
@@ -0,0 +1,20 @@
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end

if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
"Run `gem install bundler` to upgrade."
end

begin
# Set up load paths for all bundled gems
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
Bundler.setup
rescue Bundler::GemNotFound
raise RuntimeError, "Bundler couldn't find some gems." +
"Did you run `bundle install`?"
end
115 changes: 115 additions & 0 deletions vagrant/manifests/inaturalist.pp
@@ -0,0 +1,115 @@
include apt
include postgresql

# The sources.list that ships with the vagrant box is no good, so just
# clobber it.
file { "/etc/apt/sources.list":
ensure => absent,
}
apt::source { "security":
source => "deb http://security.debian.org/ squeeze/updates main contrib non-free",
require => File["/etc/apt/sources.list"],
}
apt::primary_mirror {"nz":
require => Apt::Source["security"],
before => Package["postgresql-8.4"],
}

# Make sure the apt mirro is set up before any packages are installed
#Package <| |> -> Apt::Primary_mirror["nz"]

package {"postgresql-8.4-postgis": require => Package["postgresql-8.4"]}
postgresql::db { "template_postgis":
is_template => true,
user => 'vagrant',
encoding => "UTF8",
require => [Postgresql::User["vagrant"], Package["postgresql-8.4-postgis"]]
}
postgresql::language { "plpgsql":
database => "template_postgis",
require => Postgresql::Db["template_postgis"],
}
postgresql::sqlfile { "/usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql":
database => "template_postgis",
require => Postgresql::Language["plpgsql"],
unless => "/usr/bin/psql -tA --command '\\df st_spheroid_in' template_postgis | grep -q st_spheroid_in",
}
postgresql::sqlfile { "/usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql":
database => "template_postgis",
require => Postgresql::Sqlfile["/usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql"],
unless => "/usr/bin/psql -tA --command 'SELECT srid FROM spatial_ref_sys WHERE srid = 3819' template_postgis | grep -q 3819",
}
postgresql::user { "vagrant":
createdb => true,
password => 'vagrant',
require => Package["postgresql-8.4"]
}
postgresql::db {["inaturalist_development", "inaturalist_test"]:
template => "template_postgis",
owner => 'vagrant',
user => 'vagrant',
encoding => 'UTF8',
require => [
Package["postgresql-8.4"],
Postgresql::Sqlfile["/usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql"],
Postgresql::User["vagrant"],
],
}
# The template_postgis database has two tables, and these seem to inherit the
# owner from the template db ('postgres') rather that the specified owner, so
# need to change the owner.
postgresql::sqlexec {"alter test template table owners":
sql => "ALTER TABLE geometry_columns OWNER TO vagrant;ALTER TABLE spatial_ref_sys OWNER TO vagrant",
database => "template_postgis",
unless => "/usr/bin/psql -At --command='\\dt geometry_columns' template_postgis | cut -d '|' -f 4 | grep '^vagrant$'",
require => [
Postgresql::User["vagrant"],
Postgresql::Sqlfile["/usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql"],
Postgresql::Db["template_postgis"],
]
}

package {["sphinxsearch", "ruby", "rubygems", "libxml2-dev", "libxslt1-dev",
"libpq-dev", "memcached", "imagemagick"]:
ensure => present,
require => Exec["aptitude_update"],
}

package {"bundler":
provider => gem,
require => Package["rubygems"],
ensure => '1.1.rc.7'
}
exec {"bundle":
command => "/var/lib/gems/1.8/bin/bundle",
cwd => '/vagrant',
require => [
Postgresql::Db["inaturalist_development"],
Package["bundler"],
Package["libxml2-dev"],
Package["libxslt1-dev"],
Package["libpq-dev"]
],
timeout => 0
#refreshonly => true,
}

exec {"inaturalist_setup":
command => "/var/lib/gems/1.8/bin/bundle exec rake inaturalist:setup",
cwd => '/vagrant',
unless => '/usr/bin/test -f "/vagrant/config/config.yml"',
require => Exec["bundle"],
}

exec {"db_setup":
command => "/var/lib/gems/1.8/bin/bundle exec rake db:setup",
cwd => '/vagrant',
require => [Postgresql::Db["inaturalist_development"], Exec["bundle"]],
}

exec {'gem_path':
command => '/bin/echo \'PATH="/var/lib/gems/1.8/bin/:$PATH"\' >> /home/vagrant/.bashrc',
cwd => '/home/vagrant/',
unless => "/bin/grep 'var/lib/gems' /home/vagrant/.bashrc"
}

11 changes: 11 additions & 0 deletions vagrant/modules/apt/manifests/init.pp
@@ -0,0 +1,11 @@
class apt {

package { "aptitude":
ensure => present
}

exec { "aptitude_update":
command => '/usr/bin/aptitude update',
refreshonly => true,
}
}
6 changes: 6 additions & 0 deletions vagrant/modules/apt/manifests/primary_mirror.pp
@@ -0,0 +1,6 @@
define apt::primary_mirror($country_code = $name, $ensure = 'present') {
apt::source {"apt-primary_mirror-$name":
source => "deb http://ftp.$country_code.debian.org/debian squeeze main non-free contrib",
ensure => $ensure,
}
}
10 changes: 10 additions & 0 deletions vagrant/modules/apt/manifests/source.pp
@@ -0,0 +1,10 @@
define apt::source ($source, $ensure = present) {

file { "/etc/apt/sources.list.d/$name.list":
content => $source,
ensure => $ensure,
before => Exec["aptitude_update"],
notify => Exec["aptitude_update"],
}

}
17 changes: 17 additions & 0 deletions vagrant/modules/postgresql/manifests/db.pp
@@ -0,0 +1,17 @@
define postgresql::db ($owner = $user, $template = 'template0',
$is_template = false, $encoding = 'SQL_ASCII',
$user = 'postgres') {

exec {"postgresql-createdb-$name":
command => "/usr/bin/createdb -O $owner -E $encoding -T $template $name",
user => $user,
unless => "/usr/bin/psql -ltA | /bin/grep -q ^$name",
}

if $is_template {
postgresql::sqlexec {"UPDATE pg_database SET datistemplate = TRUE WHERE datname = '$name'":
require => Exec["postgresql-createdb-$name"],
unless => "/usr/bin/psql -tA --command \"SELECT datname FROM pg_database WHERE datname = '$name' AND datistemplate = TRUE\" | /bin/grep -q ^$name",
}
}
}
8 changes: 8 additions & 0 deletions vagrant/modules/postgresql/manifests/init.pp
@@ -0,0 +1,8 @@
class postgresql {

package { "postgresql-8.4":
provider => aptitude,
require => Exec["aptitude_update"],
ensure => present,
}
}
7 changes: 7 additions & 0 deletions vagrant/modules/postgresql/manifests/language.pp
@@ -0,0 +1,7 @@
define postgresql::language($database, $language = $name) {
postgresql::sqlexec { "postgresql-create_language-$name-$database":
database => $database,
sql => "CREATE LANGUAGE '$language'",
unless => "/usr/bin/psql -tA -d $database --command \"SELECT lanname FROM pg_catalog.pg_language WHERE lanname = '$language'\" | grep -q ^$language",
}
}
6 changes: 6 additions & 0 deletions vagrant/modules/postgresql/manifests/sqlexec.pp
@@ -0,0 +1,6 @@
define postgresql::sqlexec ($user = 'postgres', $unless = "/bin/false", $database = '', $sql = $name) {
exec {"/usr/bin/psql --command \"$sql\" $database":
user => $user,
unless => $unless
}
}
7 changes: 7 additions & 0 deletions vagrant/modules/postgresql/manifests/sqlfile.pp
@@ -0,0 +1,7 @@
define postgresql::sqlfile ($database, $user = 'postgres',
$unless = "/bin/false") {
exec {"/usr/bin/psql -f $name -d $database":
user => $user,
unless => $unless,
}
}
26 changes: 26 additions & 0 deletions vagrant/modules/postgresql/manifests/user.pp
@@ -0,0 +1,26 @@
define postgresql::user($password, $superuser = false, $createdb = false,
$createrole = false, $login = true, $inherit = true) {
$superuser_sql = $superuser ? {
true => 'SUPERUSER',
false => 'NOSUPERUSER',
}
$createdb_sql = $createdb ? {
true => 'CREATEDB',
false => 'NOCREATEDB',
}
$createrole_sql = $createrole ? {
true => 'CREATEROLE',
false => 'NOCREATEROLE',
}
$login_sql = $login ? {
true => 'LOGIN',
false => 'NOLOGIN',
}
$inherit_sql = $inherit ? {
true => 'INHERIT',
false => 'NOINHERIT',
}
postgresql::sqlexec {"CREATE USER $name PASSWORD '$password' $superuser_sql $createdb_sql $createrole_sql $login_sql $inherit_sql":
unless => "/usr/bin/psql -tA --command '\\du $name' | /bin/grep -q ^$name",
}
}

0 comments on commit 3a5a261

Please sign in to comment.