Install the latest nodejs from source

This commit is contained in:
Greg Karékinian 2017-01-20 03:48:01 +00:00
parent b431e75e79
commit 671a2c4421
25 changed files with 882 additions and 141 deletions

2
Batali
View File

@ -35,7 +35,7 @@ Batali.define do
cookbook 'mysql2_chef_gem'
cookbook 'omnibus_updater', '~> 1.0.4'
cookbook 'timezone-ii'
cookbook 'nodejs', '~> 2.4.4'
cookbook 'nodejs', '~> 3.0.0'
cookbook 'ark'
cookbook 'logrotate'
end

View File

@ -619,7 +619,7 @@
"version": "2.0.1",
"source": {
"url": "https://github.com/67p/application_nodejs.git",
"ref": "54f280eb627866f24901c79c86678e6218d976f0",
"ref": "0c3494b0cae87bd1e9cbf360e91f1a290b517a66",
"type": "Batali::Source::Git",
"subdirectory": null
}
@ -641,18 +641,18 @@
],
[
"apt",
">= 0.0.0"
">= 2.9.1"
],
[
"homebrew",
">= 0.0.0"
]
],
"version": "2.4.4",
"version": "3.0.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/nodejs/versions/2.4.4/download",
"version": "2.4.4"
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/nodejs/versions/3.0.0/download",
"version": "3.0.0"
}
},
{

View File

@ -22,8 +22,6 @@ include Chef::DSL::IncludeRecipe
action :before_compile do
include_recipe 'nodejs::nodejs_from_package'
r = new_resource
if new_resource.npm

49
cookbooks/nodejs/.gitignore vendored Normal file
View File

@ -0,0 +1,49 @@
*.rbc
.config
coverage
InstalledFiles
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
_Store
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
*.tmp
*.bk
*.bkup
# ruby/bundler files
.ruby-version
.ruby-gemset
.rvmrc
Gemfile.lock
.bundle
*.gem
# YARD artifacts
.yardoc
_yardoc
doc/
.idea
# chef stuff
Berksfile.lock
.kitchen
.kitchen.local.yml
vendor/
.coverage/
.zero-knife.rb
Policyfile.lock.json
# vagrant stuff
.vagrant/
.vagrant.d/
.kitchen/

View File

@ -0,0 +1,105 @@
driver:
name: vagrant
provisioner:
name: chef_zero
verifier:
name: inspec
driver_config:
customize:
memory: 512
cpus: 4
platforms:
- name: centos-5.11
- name: centos-6.8
- name: centos-7.2
- name: debian-7.11
run_list: apt::default
- name: debian-8.5
run_list: apt::default
- name: fedora-24
run_list: yum::dnf_yum_compat
- name: ubuntu-12.04
run_list: apt::default
- name: ubuntu-14.04
run_list: apt::default
- name: ubuntu-16.04
run_list: apt::default
suites:
- name: default
run_list:
- recipe[nodejs]
- name: package
run_list:
- recipe[nodejs]
attributes:
nodejs:
install_method: package
- name: binary
run_list:
- recipe[nodejs]
attributes:
nodejs:
install_method: binary
- name: source
run_list:
- recipe[nodejs]
attributes:
nodejs:
install_method: source
excludes:
- ubuntu-12.04
- centos-5.11
- centos-6.8
- name: source-iojs
run_list:
- recipe[nodejs]
attributes:
nodejs:
engine: iojs
install_method: source
source:
checksum: 55e79cc4f4cde41f03c1e204d2af5ee4b6e4edcf14defc82e518436e939195fa
version: 2.2.1
excludes:
- ubuntu-12.04
- centos-5.11
- centos-6.8
- name: npm
run_list:
- recipe[nodejs::npm]
- recipe[nodejs_test::npm]
- name: npm_embedded
run_list:
- recipe[nodejs::npm]
- recipe[nodejs_test::npm]
attributes:
nodejs:
npm:
install_method: embedded
- name: npm_source
run_list:
- recipe[nodejs::npm]
- recipe[nodejs_test::npm]
attributes:
nodejs:
npm:
install_method: source
excludes:
- ubuntu-12.04
- centos-5.11
- centos-6.8
- name: npm_packages
run_list: recipe[nodejs]
attributes:
nodejs:
npm_packages:
- name: express
- name: socket.io
version: 1.0.4
- name: express
action: uninstall

View File

@ -0,0 +1,25 @@
# Use Travis's cointainer based infrastructure
sudo: false
addons:
apt:
sources:
- chef-current-precise
packages:
- chefdk
# Don't `bundle install`
install: echo "skip bundle install"
branches:
only:
- master
# Ensure we make ChefDK's Ruby the default
before_script:
- eval "$(/opt/chefdk/bin/chef shell-init bash)"
script:
- /opt/chefdk/embedded/bin/chef --version
- /opt/chefdk/embedded/bin/cookstyle --version
- /opt/chefdk/embedded/bin/foodcritic --version
- /opt/chefdk/bin/chef exec rake

View File

@ -0,0 +1,9 @@
source 'https://supermarket.chef.io'
metadata
group :integration do
cookbook 'yum'
cookbook 'apt'
cookbook 'nodejs_test', path: './test/cookbooks/nodejs_test'
end

View File

@ -1,99 +1,134 @@
# NodeJS Cookbook Changelog
## 3.0.0 (2016-11-02)
- Updated the default release to the nodejs 6.9.1\. This requires C++11 extensions to compile, which are only present in GCC 4.8+. Due to this RHEL 5/6 and Ubuntu 12.04 are not supported if using this version.
- Switched the download URLs to the .xz packages since the .tar.gz packages are no longer being created
- Improvements to the readme examples and requirements sections
- Removed installation of apt-transport-https and instead rely on an apt cookbook that will do the same
- Fixed the ChefSpec matchers
- Added Scientific, Oracle, and Amazon as supported distros in the metadata
- Added chef_version metadata
- Removed conflicts and suggests metadata which aren't implemented or recommended for use
- Removed Chef 10 compatibility code
- Switched Integration testing to Inspec from bats
- Added the Apache 2.0 license file to the repo
- Expanded Test Kitchen testing
- Switched from Rubocop to Cookstyle and resolved all warnings
- Switched Travis to testing using ChefDK
## 2.4.4
* Use HTTPS prefix URLs for node download #98
* Update NPM symlink when installing from source #105
* Add support for NPM private modules #107
- Use HTTPS prefix URLs for node download #98
- Update NPM symlink when installing from source #105
- Add support for NPM private modules #107
## v2.4.2
* Fix check version
* Support iojs package install
- Fix check version
- Support iojs package install
## v2.4.0
* Move `npm_packages` to his own recipe
* Fix different race conditions when using direct recipe call
* Fix npm recipe
- Move `npm_packages` to his own recipe
- Fix different race conditions when using direct recipe call
- Fix npm recipe
## v2.3.2
* Fix package recipe
- Fix package recipe
## v2.3.0
* Support io.js. Use node['nodejs']['engine'].
* Add MacOS support via homebrew
- Support io.js. Use node['nodejs']['engine'].
- Add MacOS support via homebrew
## v2.2.0
* Add node['nodejs']['keyserver']
* Update arm checksum
* Fix `npm_packages` JSON
- Add node['nodejs']['keyserver']
- Update arm checksum
- Fix `npm_packages` JSON
## v2.1.0
* Use official nodesource repository
* Add node['nodejs']['npm_packages'] to install npm package with `default` recipe
## v2.0.0
* Travis integration
* Gems updated
* Rewrite cookbook dependencies
* Added complete test-kitchen integration : Rake, rubocop, foodcritic, vagrant, bats testing ...
* Added NodeJS ```install_method``` option (sources, bins or packages)
* Added NPM ```install_method``` option (sources or packages)
* NPM version can now be chosen independently from nodejs' embedded version
* Added a ```nodejs_npm``` LWRP to manage, install and resolve NPM packages
- Use official nodesource repository
- Add node['nodejs']['npm_packages'] to install npm package with `default` recipe
## v2.0.0
- Travis integration
- Gems updated
- Rewrite cookbook dependencies
- Added complete test-kitchen integration : Rake, rubocop, foodcritic, vagrant, bats testing ...
- Added NodeJS `install_method` option (sources, bins or packages)
- Added NPM `install_method` option (sources or packages)
- NPM version can now be chosen independently from nodejs' embedded version
- Added a `nodejs_npm` LWRP to manage, install and resolve NPM packages
## v1.3.0
* update default versions to the latest: node - v0.10.15 and npm - v1.3.5
* default to package installation of nodejs on smartos ([@wanelo-pair][])
* Add Raspberry pi support ([@robertkowalski][])
- update default versions to the latest: node - v0.10.15 and npm - v1.3.5
- default to package installation of nodejs on smartos ([@wanelo-pair])
- Add Raspberry pi support ([@robertkowalski])
## v1.2.0
* implement installation from package on RedHat - ([@vaskas][])
- implement installation from package on RedHat - ([@vaskas])
## v1.1.3:
* update default version of node to 0.10.13 - and npm - v1.3.4 ([@jodosha][])
- update default version of node to 0.10.13 - and npm - v1.3.4 ([@jodosha][])
## v1.1.2:
* update default version of node to 0.10.2 - ([@bakins][])
* fully migrated to test-kitchen 1.alpha and vagrant 1.1.x/berkshelf 1.3.1
- update default version of node to 0.10.2 - ([@bakins])
- fully migrated to test-kitchen 1.alpha and vagrant 1.1.x/berkshelf 1.3.1
## v1.1.1:
* update default versions to the latest: node - v0.10.0 and npm - v1.2.14
* `make_thread` is now a real attribute - ([@ChrisLundquist][])
- update default versions to the latest: node - v0.10.0 and npm - v1.2.14
- `make_thread` is now a real attribute - ([@ChrisLundquist])
## v1.1.0:
* rewrite the package install; remove rpm support since there are no longer any packages available anywhere
* add support to install `legacy_packages` from ubuntu repo as well as the latest 0.10.x branch (this is default).
- rewrite the package install; remove rpm support since there are no longer any packages available anywhere
- add support to install `legacy_packages` from ubuntu repo as well as the latest 0.10.x branch (this is default).
## v1.0.4:
* add support for binary installation method ([@JulesAU][])
- add support for binary installation method ([@JulesAU])
## v1.0.3:
- unreleased
- unreleased
## v1.0.2:
* add smartos support for package install ([@sax][])
* support to compile with all processors available (default 2 if unknown) - ([@ChrisLundquist][])
* moved to `platform_family` syntax
* ensure npm recipe honours the 'source' or 'package' setting - ([@markbirbeck][])
* updated the default versions to the latest stable node/npm
- add smartos support for package install ([@sax])
- support to compile with all processors available (default 2 if unknown) - ([@ChrisLundquist])
- moved to `platform_family` syntax
- ensure npm recipe honours the 'source' or 'package' setting - ([@markbirbeck])
- updated the default versions to the latest stable node/npm
## v1.0.1:
* fixed bug that prevented overwritting the node/npm versions (moved the `src_url`s as local variables instead of attributes) - ([@johannesbecker][])
* updated the default versions to the latest node/npm
- fixed bug that prevented overwritting the node/npm versions (moved the `src_url`s as local variables instead of attributes) - ([@johannesbecker])
- updated the default versions to the latest node/npm
## v1.0.0:
* added packages installation support ([@smith][])
- added packages installation support ([@smith])
[@JulesAU]: https://github.com/JulesAU
[@sax]: https://github.com/sax
[@ChrisLundquist]: https://github.com/ChrisLundquist
[@markbirbeck]: https://github.com/markbirbeck
[@johannesbecker]: https://github.com/johannesbecker
[@smith]: https://github.com/smith
[@bakins]: https://github.com/bakins
[@vaskas]: https://github.com/vaskas
[@robertkowalski]: https://github.com/robertkowalski
[@wanelo-pair]: https://github.com/wanelo-pair
[@predominant]: https://github.com/predominant
[@sjlu]: https://github.com/sjlu
[@chrislundquist]: https://github.com/ChrisLundquist
[@gmccue]: https://github.com/gmccue
[@johannesbecker]: https://github.com/johannesbecker
[@julesau]: https://github.com/JulesAU
[@markbirbeck]: https://github.com/markbirbeck
[@predominant]: https://github.com/predominant
[@robertkowalski]: https://github.com/robertkowalski
[@sax]: https://github.com/sax
[@sjlu]: https://github.com/sjlu
[@smith]: https://github.com/smith
[@vaskas]: https://github.com/vaskas
[@wanelo-pair]: https://github.com/wanelo-pair

20
cookbooks/nodejs/Gemfile Normal file
View File

@ -0,0 +1,20 @@
source 'https://rubygems.org'
gem 'rake'
gem 'stove'
group :lint do
gem 'foodcritic', '~> 8.1'
gem 'cookstyle'
end
group :unit do
gem 'berkshelf', '~> 5.1'
gem 'chefspec', '~> 5.2'
end
group :kitchen do
gem 'test-kitchen', '~> 1.13'
gem 'kitchen-vagrant', '~> 0.20'
gem 'kitchen-inspec', '~> 0.15'
end

202
cookbooks/nodejs/LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.

View File

@ -1,14 +1,34 @@
# [nodejs-cookbook](https://github.com/redguide/nodejs)
[![CK Version](http://img.shields.io/cookbook/v/nodejs.svg)](https://supermarket.getchef.com/cookbooks/nodejs) [![Build Status](https://img.shields.io/travis/redguide/nodejs.svg)](https://travis-ci.org/redguide/nodejs)
[![Gitter chat](https://badges.gitter.im/redguide/nodejs.png)](https://gitter.im/redguide/nodejs)
## DESCRIPTION
[![CK Version](http://img.shields.io/cookbook/v/nodejs.svg?branch=master)](https://supermarket.getchef.com/cookbooks/nodejs) [![Build Status](https://img.shields.io/travis/redguide/nodejs.svg)](https://travis-ci.org/redguide/nodejs) [![Gitter chat](https://badges.gitter.im/redguide/nodejs.svg)](https://gitter.im/redguide/nodejs)
Installs node.js/io.js and manage npm
Installs node.js/io.js and manages npm
## USAGE
## Requirements
### Platforms
- Debian/Ubuntu
- RHEL/CentOS/Scientific/Amazon/Oracle
Note: Source installs require GCC 4.8+, which is not included on older distro releases
### Chef
- Chef 11+
### Cookbooks
- yum-epel
- build-essential
- ark
- apt
- homebrew
## Usage
Include the nodejs recipe to install node on your system based on the default installation method:
```chef
include_recipe "nodejs"
```
@ -16,6 +36,7 @@ include_recipe "nodejs"
### Engine
You can select different engine by setting `node['nodejs']['engine']`
```
node['nodejs']['engine'] => 'node' # default
node['nodejs']['engine'] => 'iojs'
@ -35,22 +56,28 @@ include_recipe "nodejs"
# Or
include_recipe "nodejs::nodejs_from_package"
```
Note that only apt (Ubuntu, Debian) appears to have up to date packages available.
Centos, RHEL, etc are non-functional (try `nodejs_from_binary` for those).
Note that only apt (Ubuntu, Debian) appears to have up to date packages available. Centos, RHEL, etc are non-functional (try `nodejs_from_binary` for those).
#### Binary
Install node from official prebuilt binaries:
```chef
node['nodejs']['install_method'] = 'binary'
include_recipe "nodejs"
# Or
include_recipe "nodejs::nodejs_from_binary"
# Or set a specific version of nodejs to be installed
node.default['nodejs']['install_method'] = 'binary'
node.default['nodejs']['version'] = '5.9.0'
node.default['nodejs']['binary']['checksum'] = '99c4136cf61761fac5ac57f80544140a3793b63e00a65d4a0e528c9db328bf40'
```
#### Source
Install node from sources:
```chef
node['nodejs']['install_method'] = 'source'
include_recipe "nodejs"
@ -60,36 +87,43 @@ include_recipe "nodejs::nodejs_from_source"
## NPM
Npm is included in nodejs installs by default.
By default, we are using it and call it `embedded`.
Adding recipe `nodejs::npm` assure you to have npm installed and let you choose install method with `node['nodejs']['npm']['install_method']`
Npm is included in nodejs installs by default. By default, we are using it and call it `embedded`. Adding recipe `nodejs::npm` assure you to have npm installed and let you choose install method with `node['nodejs']['npm']['install_method']`
```chef
include_recipe "nodejs::npm"
```
_Warning:_ This recipe will include the `nodejs` recipe, which by default includes `nodejs::nodejs_from_package` if you did not set `node['nodejs']['install_method']`.
## LWRP
## Custom Resources (Providers)
### nodejs_npm
`nodejs_npm` let you install npm packages from various sources:
* npm registry:
* name: `attribute :package`
* version: `attribute :version` (optionnal)
* url: `attribute :url`
* for git use `git://{your_repo}`
* from a json (packages.json by default): `attribute :json`
* use `true` for default
* use a `String` to specify json file
- npm registry:
- name: `attribute :package`
- version: `attribute :version` (optional)
- url: `attribute :url`
- for git use `git://{your_repo}`
- from a json (package.json by default): `attribute :json`
- use `true` for default
- use a `String` to specify json file
Packages can be installed globally (by default) or in a directory (by using `attribute :path`)
You can specify an `NPM_TOKEN` environment variable for accessing [NPM private modules](https://docs.npmjs.com/private-modules/intro) by using `attribute :npm_token`
You can append more specific options to npm command with `attribute :options` array :
* use an array of options (w/ dash), they will be added to npm call.
* ex: `['--production','--force']` or `['--force-latest']`
You can append more specific options to npm command with `attribute :options` array :
- use an array of options (w/ dash), they will be added to npm call.
- ex: `['--production','--force']` or `['--force-latest']`
This LWRP attempts to use vanilla npm as much as possible (no custom wrapper).
### Packages
@ -119,6 +153,7 @@ nodejs_npm "my_private_module" do
options ['--production'] # Only install dependencies. Skip devDependencies
end
```
[Working Examples](test/cookbooks/nodejs_test/recipes/npm.rb)
Or add packages via attributes (which accept the same attributes as the LWRP above):
@ -147,9 +182,22 @@ Or add packages via attributes (which accept the same attributes as the LWRP abo
}
```
## AUTHORS
## License & Authors
* Marius Ducea (marius@promethost.com)
* Nathan L Smith (nlloyds@gmail.com)
* Guilhem Lettron (guilhem@lettron.fr)
* Barthelemy Vessemont (bvessemont@gmail.com)
**Author:** Marius Ducea (marius@promethost.com) **Author:** Nathan L Smith (nlloyds@gmail.com) **Author:** Guilhem Lettron (guilhem@lettron.fr) **Author:** Barthelemy Vessemont (bvessemont@gmail.com)
**Copyright:** 2008-2016, Chef Software, Inc.
```
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.
```

67
cookbooks/nodejs/Rakefile Normal file
View File

@ -0,0 +1,67 @@
#!/usr/bin/env rake
# Style tests. cookstyle (rubocop) and Foodcritic
namespace :style do
begin
require 'cookstyle'
require 'rubocop/rake_task'
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
begin
require 'foodcritic'
desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
progress: true
}
end
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end
desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']
# ChefSpec
begin
require 'rspec/core/rake_task'
desc 'Run ChefSpec examples'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
# Integration tests. Kitchen.ci
namespace :integration do
begin
require 'kitchen/rake_tasks'
desc 'Run kitchen integration tests'
Kitchen::RakeTasks.new
rescue StandardError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end
namespace :supermarket do
begin
require 'stove/rake_task'
desc 'Publish cookbook to Supermarket with Stove'
Stove::RakeTask.new
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end
# Default
task default: %w(style spec)

View File

@ -26,17 +26,17 @@ end
default['nodejs']['engine'] = 'node' # or iojs
default['nodejs']['version'] = '0.10.26'
default['nodejs']['version'] = '6.9.1'
default['nodejs']['prefix_url']['node'] = 'https://nodejs.org/dist/'
default['nodejs']['prefix_url']['iojs'] = 'https://iojs.org/dist/'
default['nodejs']['source']['url'] = nil # Auto generated
default['nodejs']['source']['checksum'] = 'ef5e4ea6f2689ed7f781355012b942a2347e0299da0804a58de8e6281c4b1daa'
default['nodejs']['source']['checksum'] = '0bdd8d1305777cc8cd206129ea494d6c6ce56001868dd80147aff531d6df0729'
default['nodejs']['binary']['url'] = nil # Auto generated
default['nodejs']['binary']['checksum']['linux_x64'] = '305bf2983c65edea6dd2c9f3669b956251af03523d31cf0a0471504fd5920aac'
default['nodejs']['binary']['checksum']['linux_x86'] = '8fa2d952556c8b5aa37c077e2735c972c522510facaa4df76d4244be88f4dc0f'
default['nodejs']['binary']['checksum']['linux_arm-pi'] = '52a0f6ed9c0be1ea5f79de6527c481c1b803edbea6413a4fdc65a45ad401565d'
default['nodejs']['binary']['checksum']['linux_x64'] = 'd4eb161e4715e11bbef816a6c577974271e2bddae9cf008744627676ff00036a'
default['nodejs']['binary']['checksum']['linux_x86'] = 'f9b2ca03016e45bc35d2441a63a73db94d3e7b92350f15577d796467b9f7efb0'
default['nodejs']['binary']['checksum']['linux_arm64'] = '7aa69b6c8cff578d0d97d5bd4f76941b2fade5476f0408d53828666ee427dd4e'
default['nodejs']['make_threads'] = node['cpu'] ? node['cpu']['total'].to_i : 2

View File

@ -5,8 +5,9 @@ case node['nodejs']['engine']
when 'node'
default['nodejs']['packages'] = value_for_platform_family(
'debian' => node['nodejs']['install_repo'] ? ['nodejs'] : ['nodejs', 'npm', 'nodejs-dev'],
['rhel', 'fedora'] => ['nodejs', 'nodejs-devel', 'npm'],
%w(rhel fedora) => ['nodejs', 'nodejs-devel', 'npm'],
'mac_os_x' => ['node'],
'freebsd' => %w(node npm),
'default' => ['nodejs']
)
when 'iojs'

102
cookbooks/nodejs/chefignore Normal file
View File

@ -0,0 +1,102 @@
# Put files/directories that should be ignored in this file when uploading
# to a chef-server or supermarket.
# Lines that start with '# ' are comments.
# OS generated files #
######################
.DS_Store
Icon?
nohup.out
ehthumbs.db
Thumbs.db
# SASS #
########
.sass-cache
# EDITORS #
###########
\#*
.#*
*~
*.sw[a-z]
*.bak
REVISION
TAGS*
tmtags
*_flymake.*
*_flymake
*.tmproj
.project
.settings
mkmf.log
## COMPILED ##
##############
a.out
*.o
*.pyc
*.so
*.com
*.class
*.dll
*.exe
*/rdoc/
# Testing #
###########
.watchr
.rspec
spec/*
spec/fixtures/*
test/*
features/*
examples/*
Guardfile
Procfile
.kitchen*
.rubocop.yml
spec/*
Rakefile
.travis.yml
.foodcritic
.codeclimate.yml
# SCM #
#######
.git
*/.git
.gitignore
.gitmodules
.gitconfig
.gitattributes
.svn
*/.bzr/*
*/.hg/*
*/.svn/*
# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp
# Cookbooks #
#############
CONTRIBUTING*
CHANGELOG*
TESTING*
MAINTAINERS.toml
# Strainer #
############
Colanderfile
Strainerfile
.colander
.strainer
# Vagrant #
###########
.vagrant
Vagrantfile

View File

@ -1,4 +1,6 @@
if defined?(ChefSpec)
ChefSpec.define_matcher :nodejs_npm
def install_nodejs_npm(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:nodejs_npm, :install, resource_name)
end

View File

@ -7,7 +7,7 @@ module NodeJs
require 'open-uri'
require 'json'
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, :max_nesting => false)
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, max_nesting: false)
ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
Chef::Log.debug("Npm dist #{ret}")
return ret
@ -16,13 +16,13 @@ module NodeJs
def npm_list(path = nil, environment = {})
require 'json'
if path
cmd = Mixlib::ShellOut.new('npm list -json', :cwd => path, :environment => environment)
else
cmd = Mixlib::ShellOut.new('npm list -global -json', :environment => environment)
end
cmd = if path
Mixlib::ShellOut.new('npm list -json', cwd: path, environment: environment)
else
Mixlib::ShellOut.new('npm list -global -json', environment: environment)
end
JSON.parse(cmd.run_command.stdout, :max_nesting => false)
JSON.parse(cmd.run_command.stdout, max_nesting: false)
end
def url_valid?(list, package)
@ -38,7 +38,7 @@ module NodeJs
list = npm_list(path, environment)['dependencies']
# Return true if package installed and installed to good version
(!list.nil?) && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package)
!list.nil? && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package)
end
end
end

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,20 @@
name 'nodejs'
maintainer 'redguide'
maintainer_email 'guilhem@lettron.fr'
license 'Apache 2.0'
description 'Installs/Configures node.js & io.js'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
source_url 'https://github.com/redguide/nodejs' if respond_to?(:source_url)
issues_url 'https://github.com/redguide/nodejs/issues' if respond_to?(:issues_url)
chef_version '>= 11.0' if respond_to?(:chef_version)
version '3.0.0'
depends 'yum-epel'
depends 'build-essential'
depends 'ark'
depends 'apt', '>= 2.9.1'
depends 'homebrew'
%w(debian ubuntu centos redhat scientific oracle amazon smartos mac_os_x).each do |os|
supports os
end

View File

@ -1,6 +1,6 @@
include NodeJs::Helper
use_inline_resources if defined?(use_inline_resources)
use_inline_resources
action :install do
execute "install NPM package #{new_resource.name}" do

View File

@ -20,24 +20,24 @@ Chef::Recipe.send(:include, NodeJs::Helper)
node.force_override['nodejs']['install_method'] = 'binary' # ~FC019
# Shamelessly borrowed from http://docs.opscode.com/dsl_recipe_method_platform.html
# Shamelessly borrowed from http://docs.chef.io/dsl_recipe_method_platform.html
# Surely there's a more canonical way to get arch?
if node['kernel']['machine'] =~ /armv6l/
arch = 'arm-pi' # assume a raspberry pi
else
arch = node['kernel']['machine'] =~ /x86_64/ ? 'x64' : 'x86'
end
arch = if node['kernel']['machine'] =~ /armv6l/
'arm-pi' # assume a raspberry pi
else
node['kernel']['machine'] =~ /x86_64/ ? 'x64' : 'x86'
end
# package_stub is for example: "node-v0.8.20-linux-x64.tar.gz"
# package_stub is for example: "node-v6.9.1-linux-x64.tar.xz"
version = "v#{node['nodejs']['version']}/"
prefix = node['nodejs']['prefix_url'][node['nodejs']['engine']]
if node['nodejs']['engine'] == 'iojs'
filename = "iojs-v#{node['nodejs']['version']}-linux-#{arch}.tar.gz"
filename = "iojs-v#{node['nodejs']['version']}-linux-#{arch}.tar.xz"
archive_name = 'iojs-binary'
binaries = ['bin/iojs', 'bin/node']
else
filename = "node-v#{node['nodejs']['version']}-linux-#{arch}.tar.gz"
filename = "node-v#{node['nodejs']['version']}-linux-#{arch}.tar.xz"
archive_name = 'nodejs-binary'
binaries = ['bin/node']
end

View File

@ -27,18 +27,20 @@ include_recipe 'build-essential'
case node['platform_family']
when 'rhel', 'fedora'
package 'openssl-devel'
package 'xz'
when 'debian'
package 'libssl-dev'
package 'xz-utils'
end
version = "v#{node['nodejs']['version']}/"
prefix = node['nodejs']['prefix_url'][node['nodejs']['engine']]
if node['nodejs']['engine'] == 'iojs'
filename = "iojs-v#{node['nodejs']['version']}.tar.gz"
filename = "iojs-v#{node['nodejs']['version']}.tar.xz"
archive_name = 'iojs-source'
else
filename = "node-v#{node['nodejs']['version']}.tar.gz"
filename = "node-v#{node['nodejs']['version']}.tar.xz"
archive_name = 'nodejs-source'
end

View File

@ -2,8 +2,6 @@ case node['platform_family']
when 'debian'
include_recipe 'apt'
package 'apt-transport-https'
apt_repository 'node.js' do
uri node['nodejs']['repo']
distribution node['lsb']['codename']

View File

@ -22,13 +22,13 @@
actions :install, :uninstall
default_action :install
attribute :package, :name_attribute => true
attribute :version, :kind_of => String
attribute :path, :kind_of => String
attribute :url, :kind_of => String
attribute :json, :kind_of => [String, TrueClass]
attribute :npm_token, :kind_of => String
attribute :options, :kind_of => Array, :default => []
attribute :package, name_attribute: true
attribute :version, kind_of: String
attribute :path, kind_of: String
attribute :url, kind_of: String
attribute :json, kind_of: [String, TrueClass]
attribute :npm_token, kind_of: String
attribute :options, kind_of: Array, default: []
attribute :user, :kind_of => String
attribute :group, :kind_of => String
attribute :user, kind_of: String
attribute :group, kind_of: String

View File

@ -7,12 +7,6 @@
# All rights reserved - Do Not Redistribute
#
include_recipe 'build-essential'
node.override['nodejs']['repo'] = 'https://deb.nodesource.com/node_5.x'
include_recipe 'nodejs::nodejs_from_package'
# Update npm
nodejs_npm "npm" do
version "3.5.3"
end
node.override['nodejs']['version'] = '6.9.4'
node.override['nodejs']['source']['checksum'] = 'c51d7c61db40455d57428abcadc7eb0f0a08a8878cb1d8ea3c1e211c54532c35'
include_recipe 'nodejs::nodejs_from_source'