Skip to content

Commit

Permalink
Merge pull request voxpupuli#5 from nanliu/tb/rhel
Browse files Browse the repository at this point in the history
Add RedHat family support for Nodejs.

Reviewed by: Zach Leslie.
  • Loading branch information
nanliu committed May 15, 2012
2 parents 0c8c1b1 + d343fc9 commit a8a10b9
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 25 deletions.
1 change: 1 addition & 0 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ project_page 'https://github.com/puppetlabs/puppetlabs-nodejs'
## Add dependencies, if any:
# dependency 'username/name', '>= 1.2.0'
dependency 'puppetlabs/apt', '>= 0.0.3'
dependency 'puppetlabs/stdlib', '>= 2.0.0'
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

## Overview

Install nodejs package and npm package provider for Debian.
Install nodejs package and npm package provider for Debian, Ubuntu, Fedora, and RedHat.

## Usage

### class nodejs

Installs nodejs via sid repo per [nodejs documentation](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) and npm via the bash script per [npm documentation](https://github.com/isaacs/npm).
Installs nodejs and npm per [nodejs documentation](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager).

* dev_package: whether to install optional dev packages. dev packages not available on all platforms, default: false.

Example:

include nodejs

You may want to use apt::pin to pin package installation priority. See [puppet-apt](https://github.com/puppetlabs/puppet-apt) for more information.
You may want to use apt::pin to pin package installation priority on sqeeze. See [puppet-apt](https://github.com/puppetlabs/puppet-apt) for more information.

apt::pin { 'sid': priority => 100 }

Expand Down Expand Up @@ -62,4 +64,5 @@ nodejs::npm title consists of filepath and package name seperate via ':', and su

The module have been tested on the following operating systems. Testing and patches for other platforms are welcomed.

* Debian Wheezy
* Debian Wheezy.
* RedHat EL5.
45 changes: 32 additions & 13 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#
# Usage:
#
class nodejs {
class nodejs(
$dev_package = false
) inherits nodejs::params {

case $::operatingsystem {
'Debian': {
Expand All @@ -18,39 +20,56 @@
location => 'http://ftp.us.debian.org/debian/',
release => 'sid',
repos => 'main',
pin => 100,
include_src => false,
before => Package['nodejs'],
before => Anchor['nodejs::repo'],
}

}

'Ubuntu': {
include 'apt'

apt::ppa { 'ppa:chris-lea/node.js':
before => Package['nodejs'],
before => Anchor['nodejs::repo'],
}
}

'Fedora', 'RedHat', 'CentOS', 'Amazon': {
package { 'nodejs-stable-release':
ensure => present,
source => $nodejs::params::pkg_src,
provider => 'rpm',
before => Anchor['nodejs::repo'],
}
}

default: {
fail("Class nodejs does not support $::operatingsystem")
fail("Class nodejs does not support ${::operatingsystem}")
}
}

# anchor resource provides a consistent dependency for prereq.
anchor { 'nodejs::repo': }

package { 'nodejs':
name => $nodejs::params::node_pkg,
ensure => present,
require => Anchor['nodejs::repo']
}

package { 'curl':
ensure => present,
package { 'npm':
name => $nodejs::params::npm_pkg,
ensure => present,
require => Anchor['nodejs::repo']
}

# npm installation is a hack since there's no packages:
exec { 'install_npm':
command => 'curl http://npmjs.org/install.sh | sed "s/<\/dev\/tty//g" > /tmp/install_$$.sh; chmod 755 /tmp/install_$$.sh; /tmp/install_$$.sh',
unless => 'which npm',
path => $::path,
logoutput => 'on_failure',
require => Package['nodejs', 'curl'],
if $dev_package and $nodejs::params::dev_pkg {
package { 'nodejs-dev':
name => $nodejs::params::dev_pkg,
ensure => present,
require => Anchor['nodejs::repo']
}
}

}
49 changes: 49 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Class: nodejs::parms
#
# Parameters:
#
# Actions:
#
# Requires:
#
# Usage:
#
class nodejs::params {

case $::operatingsystem {
'Debian', 'Ubuntu': {
$node_pkg = 'nodejs'
$npm_pkg = 'npm'
$dev_pkg = 'nodejs-dev'
}

'SLES', 'OpenSuSE': {
$node_pkg = 'nodejs'
$npm_pkg = 'npm'
$dev_pkg = 'nodejs-devel'
}

'RedHat', 'CentOS': {
$node_pkg = 'nodejs-compat-symlinks'
$npm_pkg = 'npm'
$pkg_src = 'http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm'
}

'Fedora': {
$node_pkg = 'nodejs-compat-symlinks'
$npm_pkg = 'npm'
$pkg_src = 'http://nodejs.tchol.org/repocfg/fedora/nodejs-stable-release.noarch.rpm'
}

'Amazon': {
$node_pkg = 'nodejs-compat-symlinks'
$npm_pkg = 'npm'
$pkg_src = 'http://nodejs.tchol.org/repocfg/amzn1/nodejs-stable-release.noarch.rpm'
}

default: {
fail("Class nodejs does not support ${::operatingsystem}")
}
}

}
53 changes: 45 additions & 8 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
it { should contain_apt__source('sid').with({
'location' => 'http://ftp.us.debian.org/debian/',
}) }
it { should contain_package('nodejs') }
it { should contain_package('nodejs').with({
'name' => 'nodejs',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should_not contain_package('nodejs-stable-release') }
end

describe 'when deploying on ubuntu' do
Expand All @@ -28,16 +36,45 @@
it { should contain_class('apt') }
it { should contain_apt__ppa('ppa:chris-lea/node.js') }
it { should contain_package('nodejs') }
it { should contain_package('nodejs').with({
'name' => 'nodejs',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should_not contain_package('nodejs-stable-release') }
end

describe 'when deploying on RedHat' do
let :facts do
{
:operatingsystem => 'RedHat',
}
end
{ 'Redhat' => 'el',
'CentOS' => 'el',
'Fedora' => 'fedora',
'Amazon' => 'amzn1'
}.each do |os, repo|
describe 'when deploying on RedHat' do
let :facts do
{ :operatingsystem => os, }
end

it { expect { should contain_package('nodejs') }.to raise_error(Puppet::Error) }
let :params do
{ :dev_package => true, }
end

it { should contain_package('nodejs-stable-release').with({
'source' => "http://nodejs.tchol.org/repocfg/#{repo}/nodejs-stable-release.noarch.rpm",
'provider' => 'rpm',
}) }
it { should contain_package('nodejs').with({
'name' => 'nodejs-compat-symlinks',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should_not contain_package('nodejs-dev') }
end
end
end

0 comments on commit a8a10b9

Please sign in to comment.