Skip to content

Commit

Permalink
WIP on rails module
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrtv committed Apr 4, 2012
1 parent 0cce7c2 commit 7b2abc7
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 0 deletions.
Empty file.
31 changes: 31 additions & 0 deletions opdemand/manifests/framework/rails/postgresql.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class opdemand::framework::rails::postgresql {

# require opdemand common and repo
require opdemand::common
require opdemand::repo::app

# initialize dynamic parameters
class {"rails::params":
# admin
admin_name => hiera("admin/name", "Administrator"),
admin_username => hiera("admin/username", "admin"),
admin_password => hiera("admin/password", "changeme123"),
admin_email => hiera("admin/email", "admin@example.org"),
# database
database_type => hiera("database/type", "postgresql"),
# service
bind => hiera("application/bind", "0.0.0.0"),
port => hiera("application/port", "8080"),
# daemon/repository
username => hiera("application/username", "ubuntu"),
group => hiera("application/group", "ubuntu"),
home => hiera("application/home", "/home/ubuntu"),
repository_path => hiera("application/repository_path", "/home/ubuntu/repo"),
}

# include relevant classes
include rails::install
include rails::config
include rails::service

}
13 changes: 13 additions & 0 deletions rails/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2012 OpDemand LLC

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.
11 changes: 11 additions & 0 deletions rails/Modulefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name 'opdemand-rails'
version '0.0.1'
source 'UNKNOWN'
author 'opdemand'
license 'UNKNOWN'
summary 'UNKNOWN'
description 'UNKNOWN'
project_page 'UNKNOWN'

## Add dependencies, if any:
# dependency 'username/name', '>= 1.2.0'
3 changes: 3 additions & 0 deletions rails/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rails

This is the rails module.
Empty file added rails/README.md
Empty file.
11 changes: 11 additions & 0 deletions rails/manifests/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class rails::config {

require rails::params

file {"/etc/init/rails.conf":
ensure => file,
content => template("rails/rails.conf.erb"),
require => Class[Rails::Install],
}

}
19 changes: 19 additions & 0 deletions rails/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
define rails::syncdb {
exec { "sudo -u $rails::params::username rake db:migrate":
path => $path,
user => "$rails::params::username",
cwd => "$rails::params::repository_path/app",
require => Class[Rails::Install],
subscribe => Vcsrepo["$rails::params::repository_path"],
}
}

define rails::bundleinstall {
exec { "sudo -u $rails::params::username bundle install":
path => $path,
user => "$rails::params::username",
cwd => "$rails::params::repository_path/app",
require => Class[Rails::Install],
subscribe => Vcsrepo["$rails::params::repository_path"],
}
}
28 changes: 28 additions & 0 deletions rails/manifests/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class rails::install {

require rails::params

$packages = [ "curl", "openssl", "ruby1.9.1", "ruby1.9.1-dev", "build-essential", "libsqlite3-ruby1.9.1", "libsqlite3-dev", "rubygems", "libv8-dev"]
$gems = [ "bundler", "rails", "sinatra", "therubyracer" ]
$db_packages = $rails::params::database_type ? {
postgresql => [ "libpq-dev" ],
}

# install framework database packages
package { $db_packages:
ensure => latest,
}

# install framework packages
package { $packages:
ensure => latest,
}

# install gems
package { $gems:
provider => "gem",
ensure => latest,
require => Package[rubygems]
}

}
17 changes: 17 additions & 0 deletions rails/manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class rails::params (
# admin settings
$admin_email = "admin@example.com",
$admin_name = "Admin User",
$admin_username = "admin",
$admin_password = "changeme123",
# database settings
$database_type = "postgresql",
# service settings
$bind = "0.0.0.0",
$port = "8080",
# daemon settings
$username = "ubuntu",
$group = "ubuntu",
$home = "/home/ubuntu",
$repository_path = "/home/ubuntu/repo") {
}
16 changes: 16 additions & 0 deletions rails/manifests/service.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class rails::service {

require rails::params

service {"rails":
ensure => running,
name => "rails",
provider => upstart,
require => [ Class[Rails::Install], Class[Rails::Config] ],
subscribe => Vcsrepo["$rails::params::repository_path"],
} ->

rails::bundleinstall {"rails":} ->
rails::syncdb {"rails":}

}
12 changes: 12 additions & 0 deletions rails/templates/rails.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!upstart
description "rails app server"
author "OpDemand"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

script
export HOME="<%= scope.lookupvar("rails::params::home") %>"
cd $HOME/repo
exec sudo -u <%= scope.lookupvar("rails::params::username") %> rails server 2>&1 >> /var/log/rails.log
end script
1 change: 1 addition & 0 deletions rails/tests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include rails

0 comments on commit 7b2abc7

Please sign in to comment.