Skip to content

Commit

Permalink
Merge pull request #97 from skpy/sdm-01
Browse files Browse the repository at this point in the history
Parameterize package names
  • Loading branch information
cmurphy committed Dec 23, 2014
2 parents ea2830f + 52d5752 commit 0039335
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 10 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@ Install nodejs package and npm package provider for Debian, Ubuntu, Fedora, RedH

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

* node_pkg: the package to install that provides nodejs.
* npm_pkg: the package to install that provides `npm`.
* dev_pkg: the package to install that provides the nodejs development libraries.
* dev_package: whether to install optional dev packages. dev packages not available on all platforms, default: false.
* manage_repo: whether to manage the repository that provides the packages for nodejs. Defaults to "false".
* proxy: the HTTP proxy to use for nodejs.
* version: the version of nodejs packages to install. Defaults to "present".

Example:
Examples:

include nodejs

You may want to use apt::pin to pin package installation priority on squeeze. See [puppetlabs-apt](https://github.com/puppetlabs/puppetlabs-apt) for more information.
Red Hat Enterprise Linux (and derivatives) may want to install nodejs from Software Collections:

class { 'nodejs':
node_pkg => 'nodejs010',
npm_pkg => 'nodejs010-npm',
dev_pkg => 'nodejs010-devel',
dev_package => true,
}

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

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

Expand Down Expand Up @@ -64,5 +79,6 @@ 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.
* RedHat EL5.
* Debian Wheezy
* Red Hat Enterprise Linux 5
* Red Hat Enterprise Linux 6
35 changes: 31 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,40 @@
#
# Parameters:
#
# node_pkg: (string) the name of the package to install
# npm_pkg : (string) the name of the package that provides npm
# dev_pkg : (string) the name of the NodeJS development package to install
# dev_package: (bool) whether to install the dev_pkg or not
# manage_repo: (bool) whether to manage the repository
# proxy: (string) the HTTP proxy to use
# version: (string) the version of NodeJS (and associated packages) to install
#
# Actions:
#
# Requires:
#
# Usage:
# To install the default NodeJS packages as determined by your operating system
# (and as codified in nodejs::params), you can accept the default values:
#
# include nodejs
# class { 'nodejs': }
#
# To install a specific package name, you can override the parameter values. The
# following example installs NodeJS from Software Collections on a Red Hat-derived
# system:
#
# class { 'nodejs':
# node_pkg => 'nodejs010',
# npm_pkg => 'nodejs010-npm',
# dev_pkg => 'nodejs010-devel',
# dev_package => true,
# }
#
class nodejs(
$node_pkg = $::nodejs::params::node_pkg,
$npm_pkg = $::nodejs::params::npm_pkg,
$dev_pkg = $::nodejs::params::dev_pkg,
$dev_package = false,
$manage_repo = false,
$proxy = '',
Expand Down Expand Up @@ -103,8 +130,8 @@
anchor { 'nodejs::repo': }

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

Expand All @@ -131,8 +158,8 @@

default: {
package { 'npm':
name => $nodejs::params::npm_pkg,
ensure => present,
name => $npm_pkg,
require => Anchor['nodejs::repo']
}
}
Expand All @@ -146,10 +173,10 @@
}
}

if $dev_package and $nodejs::params::dev_pkg {
if $dev_package and $dev_pkg {
package { 'nodejs-dev':
name => $nodejs::params::dev_pkg,
ensure => $version,
name => $dev_pkg,
require => Anchor['nodejs::repo']
}
}
Expand Down
5 changes: 5 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Class: nodejs::parms
#
# Parameters:
# None!
#
# Actions:
# None!
#
# Requires:
#
Expand Down Expand Up @@ -40,19 +42,22 @@
}
}
$npm_pkg = 'npm'
$dev_pkg = 'nodejs-devel'
$baseurl = 'http://patches.fedorapeople.org/oldnode/stable/el$releasever/$basearch/'
}

'Fedora': {
$node_pkg = 'nodejs-compat-symlinks'
$npm_pkg = 'npm'
$dev_pkg = 'nodejs-devel'
$gpgcheck = 1
$baseurl = 'http://patches.fedorapeople.org/oldnode/stable/f$releasever/$basearch/'
}

'Amazon': {
$node_pkg = 'nodejs'
$npm_pkg = 'npm'
$dev_pkg = 'nodejs-devel'
$gpgcheck = 1
$baseurl = 'http://patches.fedorapeople.org/oldnode/stable/amzn1/$basearch/'
}
Expand Down
34 changes: 32 additions & 2 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
end

let :params do
{ :dev_package => true,:manage_repo => true}
{ :manage_repo => true}
end

context 'when manage_repo is true' do
Expand Down Expand Up @@ -141,6 +141,32 @@
should_not contain_file('nodejs_repofile')
end
end

context 'when dev_package is true' do
let (:params) {{:dev_package => true}}
it { should contain_package('nodejs-dev') }
end

context 'when node_pkg is set' do
let (:params) {{:node_pkg => 'nodejs010'}}
it { should contain_package('nodejs').with({
'name' => 'nodejs010',
'require' => 'Anchor[nodejs::repo]',
}) }
end

context 'when node_pkg and npm_pkg are set' do
let (:params) {{:node_pkg => 'nodejs010',:npm_pkg => 'nodejs010-npm'}}
it { should contain_package('nodejs').with({
'name' => 'nodejs010',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('npm').with({
'name' => 'nodejs010-npm',
'require' => 'Anchor[nodejs::repo]',
}) }
end

it { should contain_package('nodejs').with({
'name' => package,
'require' => 'Anchor[nodejs::repo]',
Expand All @@ -162,7 +188,7 @@
}
end
let :params do
{ :dev_package => true,:manage_repo => true }
{ :manage_repo => true }
end
context 'when manage_repo is true' do
it 'should remove the node-js-stable-release package' do
Expand Down Expand Up @@ -194,6 +220,10 @@
end
end

context 'when dev_package is true' do
let (:params) {{:dev_package => true}}
it { should contain_package('nodejs-dev') }
end
it { should contain_package('nodejs').with({
'require' => 'Anchor[nodejs::repo]',
}) }
Expand Down

0 comments on commit 0039335

Please sign in to comment.