Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Puppetfile Dev Environment Node.js + PostgreSQL
Exec {
path => ['/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/local/bin']
}
# --- Preinstall Stage ---------------------------------------------------------
stage { 'preinstall':
before => Stage['main']
}
class install_packages {
package { ['curl', 'build-essential', 'git', 'git-core', 'vim', 'ack-grep',
'libfontconfig1', 'python', 'python-software-properties', 'g++',
'gcc', 'make', 'wget', 'tar', 'libpq-dev', 'nodejs', 'npm']:
ensure => present
}
}
class { 'install_packages':
stage => 'preinstall'
}
# Setup your locale to avoid warnings
file { '/etc/default/locale':
content => "LANG=\"en_US.UTF-8\"\nLC_ALL=\"en_US.UTF-8\"\n"
}
# --- NodeJS -------------------------------------------------------------------
# Because of a package name collision, 'node' is called 'nodejs' in Ubuntu.
file { '/usr/bin/node':
ensure => 'link',
target => "/usr/bin/nodejs",
}
# install global NPM packages
define npm_global_install(){
exec { "npm_global_install_${name}":
command => "npm install -g ${name}",
require => Package['npm'],
timeout => 0 # disable timeout
}
}
npm_global_install {
['grunt-cli@0.1.13', 'bower@1.3.1', 'db-migrate@0.6.2']:
}
# install local NPM packages
define npm_install(){
exec { "npm_install_${name}":
command => "npm install",
cwd => $name,
require => [Package['npm']],
timeout => 0 # disable timeout
}
}
npm_install { ['/vagrant']: }
# install bower packages
define bower_install(){
exec { "bower_install_${name}":
command => "${as_vagrant} 'bower install'",
cwd => $name,
require => Npm_global_install['bower@1.3.1']
}
}
bower_install { ['/vagrant']: }
# --- PostgreSQL ---------------------------------------------------------------
class setup_postgres {
# install postgres
class {'postgresql::server':
ipv4acls => ['local all all md5', ],
}
# create vagrant user
postgresql::server::role { 'vagrant':
superuser => true,
require => Class['Postgresql::server']
}
# create dev user
postgresql::server::role { 'devuser':
password_hash => postgresql_password('devuser', 'devpd'),
require => Class['Postgresql::server']
}
# create test user
postgresql::server::role { 'testuser':
password_hash => postgresql_password('testuser', 'testpd'),
createdb => true,
require => Class['Postgresql::server']
}
# create dev database
postgresql::server::database { 'dev':
owner => 'devuser',
locale => 'en_US.UTF-8',
require => Postgresql::Server::Role['devuser']
}
# create test template database
postgresql::server::database { 'gogood_test_template':
owner => 'testuser',
locale => 'en_US.UTF-8',
require => Postgresql::Server::Role['testuser']
}
}
class { 'setup_postgres': }
# run database migrations
define migrate_database(){
exec { "migrate_database_${name}":
command => "db-migrate up --env ${name}",
cwd => "/vagrant",
require => [Class['setup_postgres'], Npm_global_install['db-migrate@0.6.2']]
}
}
migrate_database { ['development']: }
forge "http://forge.puppetlabs.com"
mod "puppetlabs/stdlib", "4.1.0"
mod "puppetlabs/apt", "1.4.2"
mod 'puppetlabs/concat', :git => 'https://github.com/puppetlabs/puppetlabs-concat.git', :ref => '1.0.0'
mod "puppetlabs/postgresql", "3.4.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment