Home

Awesome

Poise-Javascript Cookbook

Build Status Gem Version Cookbook Version Coverage Gemnasium License

A Chef cookbook to provide a unified interface for installing server-side JavaScript runtimes like Node.js and io.js.

Quick Start

To install the latest available version of Node.js 0.12:

javascript_runtime '0.12'

Supported JavaScript Runtimes

This cookbook can install Node.js and io.js on Linux and OS X.

Requirements

Chef 12.1 or newer is required.

Attributes

Attributes are used to configure the default recipe.

Recipes

default

The default recipe installs Node.js or io.js based on the node attributes. It is entirely optional and can be ignored in favor of direct use of the javascript_runtime resource.

Resources

javascript_runtime

The javascript_runtime resource installs a JavaScript interpreter.

javascript_runtime '0.12'

Actions

Properties

Provider Options

The poise-javascript library offers an additional way to pass configuration information to the final provider called "options". Options are key/value pairs that are passed down to the javascript_runtime provider and can be used to control how it installs JavaScript. These can be set in the javascript_runtime resource using the options method, in node attributes or via the javascript_runtime_options resource. The options from all sources are merged together in to a single hash.

When setting options in the resource you can either set them for all providers:

javascript_runtime 'myapp' do
  version '0.10'
  options dev_package: false
end

or for a single provider:

javascript_runtime 'myapp' do
  version '0.10'
  options :system, dev_package: false
end

Setting via node attributes is generally how an end-user or application cookbook will set options to customize installations in the library cookbooks they are using. You can set options for all installations or for a single runtime:

# Global, for all installations.
override['poise-javascript']['options']['version'] = '0.10'
# Single installation.
override['poise-javascript']['myapp']['version'] = 'iojs'

The javascript_runtime_options resource is also available to set node attributes for a specific installation in a DSL-friendly way:

javascript_runtime_options 'myapp' do
  version 'iojs'
end

Unlike resource attributes, provider options can be different for each provider. Not all providers support the same options so make sure to the check the documentation for each provider to see what options the use.

javascript_runtime_options

The javascript_runtime_options resource allows setting provider options in a DSL-friendly way. See the Provider Options section for more information about provider options overall.

javascript_runtime_options 'myapp' do
  version 'iojs'
end

Actions

Properties

All other attribute keys will be used as options data.

javascript_execute

The javascript_execute resource executes a JavaScript script using the configured runtime.

javascript_execute 'myapp.js' do
  user 'myuser'
end

This uses the built-in execute resource and supports all the same properties.

Actions

Properties

For other properties see the Chef documentation.

node_package

The node_package resource installs Node.js packages using NPM.

node_package 'express' do
  version '4.13.3'
end

This uses the built-in package resource and supports the same actions and properties. Multi-package installs are supported using the standard syntax.

Actions

The :purge and :reconfigure actions are not supported.

Properties

For other properties see the Chef documentation. The response_file, response_file_variables, and source properties are not supported.

npm_install

The npm_install resource runs npm install for a package.

npm_install '/opt/myapp'

The underlying npm install command will run on every converge, but notifications will only be triggered if a package is actually installed.

Actions

Properties

Javascript Providers

Common Options

These provider options are supported by all providers.

system

The system provider installs Node.js using system packages. This is currently only tested on platforms using apt-get and yum (Debian, Ubuntu, RHEL, CentOS Amazon Linux, and Fedora). It may work on other platforms but is untested.

javascript_runtime 'myapp' do
  provider :system
  version '0.10'
end

Options

scl

The scl provider installs Node.js using the Software Collections packages. This is only available on RHEL and CentOS. SCL offers more recent versions of Node.js than the system packages for the most part. If an SCL package exists for the requests version, it will be used in preference to the system provider.

javascript_runtime 'myapp' do
  provider :scl
  version '0.10'
end

nodejs

The nodejs provider installs Node.js from the static binaries on nodejs.org. Support is included for Linux and OS X.

javascript_runtime 'myapp' do
  provider :nodejs
  version '0.12'
end

Options

iojs

The iojs provider installs io.js from the static binaries on iojs.org. Support is included for Linux and OS X.

javascript_runtime 'myapp' do
  provider :iojs
  version '3'
end

Options

Sponsors

The Poise test server infrastructure is sponsored by Rackspace.

License

Copyright 2015-2017, Noah Kantrowitz

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.