diff --git a/Modulefile b/Modulefile index 1ac2f93c..2838ae4d 100644 --- a/Modulefile +++ b/Modulefile @@ -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' diff --git a/README.md b/README.md index 67ec9632..2bc5c509 100644 --- a/README.md +++ b/README.md @@ -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 } @@ -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. diff --git a/manifests/init.pp b/manifests/init.pp index aaa8d5b8..d2fe828b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -8,7 +8,9 @@ # # Usage: # -class nodejs { +class nodejs( + $dev_package = false +) inherits nodejs::params { case $::operatingsystem { 'Debian': { @@ -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'] + } } } diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 00000000..74d06b15 --- /dev/null +++ b/manifests/params.pp @@ -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}") + } + } + +} diff --git a/spec/classes/nodejs_spec.rb b/spec/classes/nodejs_spec.rb index ce9e33d4..c0055ebd 100644 --- a/spec/classes/nodejs_spec.rb +++ b/spec/classes/nodejs_spec.rb @@ -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 @@ -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