Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Aug 14, 2012
0 parents commit 8cbd033
Show file tree
Hide file tree
Showing 54 changed files with 4,493 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.vagrant
83 changes: 83 additions & 0 deletions README.md
@@ -0,0 +1,83 @@
# A Virtual Machine for Ruby on Rails Core Development

## Introduction

This project automates the setup of a development environment for Ruby on Rails core development. This is the easiest way to build a box with everything ready to start hacking on your pull request, all in an isolated virtual machine.

## Requirements

### VirtualBox

The virtual machine runs on top of [VirtualBox](https://www.virtualbox.org).

### Vagrant

We use [Vagrant](http://vagrantup.com) to build and provision the virtual machine:

gem install vagrant

Please install the "precise32" base box if you don't have it already (`vagrant box list` would tell you):

vagrant box add precise32 http://files.vagrantup.com/precise32.box

That's done only once.

## How To Build The Virtual Machine

Building the virtual machine is this easy:

git clone https://github.com/rails/rails-dev-box.git
cd rails-dev-box
vagrant up

That's it.

This initial setup takes about 3 minutes in my MacBook Air. Once the installation has finished, you can access the virtual machine with

vagrant ssh

Port 3000 in the host computer is forwarded to port 3000 in the virtual machine. Thus, applications running in the virtual machine can be accessed via localhost:3000 in the host computer.

## What's In The Box

* Git

* Ruby 1.9.3

* Bundler

* SQLite3, MySQL, and Postgres

* System dependencies for nokogiri, sqlite3, mysql, mysql2, and pg

* Databases and users needed to run the Active Record test suite

* therubyracer

* Memcached

## Virtual Machine Management

Once you are done just log out with `^D` and suspend the virtual machine

vagrant suspend

then, resume to hack again

vagrant resume

Run

vagrant halt

to shutdown the virtual machine, and

vagrant up

to boot it again.

And to completely wipe the virtual machine from the disk **destroying all its contents**:

vagrant destroy # DANGER: all is gone

Please check the [Vagrant documentation](http://vagrantup.com/v1/docs/index.html) for more information on Vagrant.
14 changes: 14 additions & 0 deletions Vagrantfile
@@ -0,0 +1,14 @@
Vagrant::Config.run do |config|
# Run:
#
# vagrant box add precise32 http://files.vagrantup.com/precise32.box
#
# if needed (you need that only once).
config.vm.box = 'precise32'

config.vm.forward_port 3000, 3000

config.vm.provision :puppet,
:manifests_path => 'puppet/manifests',
:module_path => 'puppet/modules'
end
112 changes: 112 additions & 0 deletions puppet/manifests/default.pp
@@ -0,0 +1,112 @@
$ar_databases = ['activerecord_unittest', 'activerecord_unittest2']

# Make sure apt-get -y update runs before anything else.
stage { 'preinstall':
before => Stage['main']
}

class apt_get_update {
exec { '/usr/bin/apt-get -y update':
user => 'root'
}
}
class { 'apt_get_update':
stage => preinstall
}

class install_sqlite3 {
package { 'sqlite3':
ensure => installed;
}

package { 'libsqlite3-dev':
ensure => installed;
}
}
class { 'install_sqlite3': }

class install_mysql {
class { 'mysql': }

class { 'mysql::server':
config_hash => { 'root_password' => '' }
}

database { $ar_databases:
ensure => present,
charset => 'utf8',
require => Class['mysql::server']
}

database_user { 'rails@localhost':
ensure => present,
require => Class['mysql::server']
}

database_grant { ['rails@localhost/activerecord_unittest', 'rails@localhost/activerecord_unittest2']:
privileges => ['all'],
require => Database_user['rails@localhost']
}

package { 'libmysqlclient15-dev':
ensure => installed
}
}
class { 'install_mysql': }

class install_postgres {
class { 'postgresql': }

class { 'postgresql::server': }

pg_database { $ar_databases:
ensure => present,
encoding => 'UTF8',
require => Class['postgresql::server']
}

pg_user { 'rails':
ensure => present,
require => Class['postgresql::server']
}

package { "libpq-dev":
ensure => installed
}
}
class { 'install_postgres': }

class install_core_packages {
package { ['build-essential', 'git-core']:
ensure => installed
}
}
class { 'install_core_packages': }

class install_ruby {
package { 'ruby1.9.3':
ensure => installed
}

exec { '/usr/bin/gem install bundler --no-rdoc --no-ri':
unless => '/usr/bin/gem list | grep bundler',
user => 'root',
require => Package['ruby1.9.3']
}

exec { '/usr/bin/gem install therubyracer --no-rdoc --no-ri':
unless => '/usr/bin/gem list | grep therubyracer',
user => 'root',
require => [Package['ruby1.9.3'], Package['build-essential']]
}
}
class { 'install_ruby': }

class install_nokogiri_dependencies {
package { ['libxml2', 'libxml2-dev', 'libxslt1-dev']:
ensure => installed
}
}
class { 'install_nokogiri_dependencies': }

class { 'memcached': }
2 changes: 2 additions & 0 deletions puppet/modules/memcached/.gitignore
@@ -0,0 +1,2 @@
pkg/
*.swp
8 changes: 8 additions & 0 deletions puppet/modules/memcached/Modulefile
@@ -0,0 +1,8 @@
name 'saz-memcached'
version '2.0.2'
source 'git://github.com/saz/puppet-memcached.git'
author 'saz'
license 'Apache License, Version 2.0'
summary 'UNKNOWN'
description 'Manage memcached via Puppet'
project_page 'https://github.com/saz/puppet-memcached'
29 changes: 29 additions & 0 deletions puppet/modules/memcached/README.md
@@ -0,0 +1,29 @@

# puppet-memcached

Manage memcached via Puppet

## How to use

### Use roughly 90% of memory

```
class { 'memcached': }
```

### Set a fixed memory limit in MB

```
class { 'memcached':
max_memory => 2048
}
```

### Other class parameters

* $logfile = '/var/log/memcached.log'
* $listen_ip = '0.0.0.0'
* $tcp_port = 11211
* $udp_port = 11211
* $user = '' (OS specific setting, see params.pp)
* $max_connections = 8192
33 changes: 33 additions & 0 deletions puppet/modules/memcached/manifests/init.pp
@@ -0,0 +1,33 @@
class memcached(
$package_ensure = 'present',
$logfile = '/var/log/memcached.log',
$max_memory = false,
$listen_ip = '0.0.0.0',
$tcp_port = 11211,
$udp_port = 11211,
$user = $::memcached::params::user,
$max_connections = '8192',
$verbosity = undef,
$unix_socket = undef
) inherits memcached::params {

package { $memcached::params::package_name:
ensure => $package_ensure,
}

file { $memcached::params::config_file:
owner => 'root',
group => 'root',
mode => '0644',
content => template($memcached::params::config_tmpl),
require => Package[$memcached::params::package_name],
}

service { $memcached::params::service_name:
ensure => running,
enable => true,
hasrestart => true,
hasstatus => false,
subscribe => File[$memcached::params::config_file],
}
}
21 changes: 21 additions & 0 deletions puppet/modules/memcached/manifests/params.pp
@@ -0,0 +1,21 @@
class memcached::params {
case $::osfamily {
'Debian': {
$package_name = 'memcached'
$service_name = 'memcached'
$config_file = '/etc/memcached.conf'
$config_tmpl = "${module_name}/memcached.conf.erb"
$user = 'nobody'
}
'RedHat': {
$package_name = 'memcached'
$service_name = 'memcached'
$config_file = '/etc/sysconfig/memcached'
$config_tmpl = "${module_name}/memcached_sysconfig.erb"
$user = 'memcached'
}
default: {
fail("Unsupported platform: ${::osfamily}")
}
}
}
46 changes: 46 additions & 0 deletions puppet/modules/memcached/templates/memcached.conf.erb
@@ -0,0 +1,46 @@
# File managed by puppet

# Run memcached as a daemon.
-d

# pidfile
-P /var/run/memcached.pid

# Log memcached's output
logfile <%= logfile %>
<% if @verbosity -%>
# Verbosity
-<%= verbosity %>
<% end -%>

# Use <num> MB memory max to use for object storage.
<% if max_memory -%>
-m <%= max_memory %>
<% else -%>
-m <%= ((memorysize.to_f*1024)*0.95).floor %>
<% end -%>
<% if @unix_socket -%>
# UNIX socket path to listen on
-s <%= unix_socket %>
<% else -%>

# IP to listen on
-l <%= listen_ip %>

# TCP port to listen on
-p <%= tcp_port %>

# UDP port to listen on
-U <%= udp_port %>
<% end -%>

# Run daemon as user
-u <%= user %>

# Limit the number of simultaneous incoming connections.
-c <%= max_connections %>

# Number of threads to use to process incoming requests.
-t <%= processorcount %>
5 changes: 5 additions & 0 deletions puppet/modules/memcached/templates/memcached_sysconfig.erb
@@ -0,0 +1,5 @@
PORT="<%= udp_port %>"
USER="<%= user %>"
MAXCONN="<%= max_connections %>"
CACHESIZE="<%= max_memory %>"
OPTIONS=""
3 changes: 3 additions & 0 deletions puppet/modules/mysql/.fixtures.yml
@@ -0,0 +1,3 @@
fixtures:
symlinks:
"mysql": "#{source_dir}"
5 changes: 5 additions & 0 deletions puppet/modules/mysql/.gemfile
@@ -0,0 +1,5 @@
source :rubygems

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'

0 comments on commit 8cbd033

Please sign in to comment.