Skip to content

Commit

Permalink
Merge pull request #51 from netmanagers/master
Browse files Browse the repository at this point in the history
Add npm management support
  • Loading branch information
myii committed Mar 12, 2019
2 parents b9309db + 1904435 commit 40f0541
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 20 deletions.
38 changes: 21 additions & 17 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
packages formula
================

0.0.1 (2018-02-12)
0.1.0 (2019-03-10)

- Initial version
- Add npm support

0.0.2 (2018-02-23)
0.0.9 (2018-10-03)

- Add Fedora support
- Add support for plain files using archive

0.0.3 (2018-03-02)
0.0.8 (2018-08-23)

- Allow to hold/unhold system packages (#8)
- Add more tests
- Add archive support

0.0.4 (2018-03-06)
0.0.7 (2018-07-11)

- Allow to specify held system packages also as a list (#10)
- Fix pip/gems for FreeBSD

0.0.6 (2018-04-09)

- Add snap with classic confinement support

0.0.5 (2018-03-14)

- Add snap support

0.0.6 (2018-04-09)
0.0.4 (2018-03-06)

- Add snap with classic confinement support
- Allow to specify held system packages also as a list (#10)

0.0.7 (2018-07-11)
0.0.3 (2018-03-02)

- Fix pip/gems for FreeBSD
- Allow to hold/unhold system packages (#8)

0.0.8 (2018-08-23)
0.0.2 (2018-02-23)

- Add archive support
- Add Fedora support
- Add more tests

0.0.9 (2018-10-03)
0.0.1 (2018-02-12)

- Add support for plain files using arcihve
- Initial version
22 changes: 22 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ You can specify:
* ``required states`` on which any of the ``wanted`` packages depend for their
correct installation (ie, ``epel`` for RedHat families).

``packages.npms``
-----------------

This formula **DOES NOT** install ``nodejs/npm``, as it's outside of its scope:
nodejs/npm that comes with the distros is usually outdated, so it's required to add
a repo, run scripts, etc, and this formula manages packages :)

You can use the `nodejs-formula <https://github.com/saltstack-formulas/node-formula>`_
and add a dependency for it in the pillar `npms:required:sls` (see the pillar.example)

You can specify:

* ``wanted`` npm packages, which will be installed using npm. Requires you
specify the correct ``npm`` package for your distro, as a dependency
(see the pillar.example)
* ``unwanted`` npm packages, which will be uninstalled using npm.
* ``required system packages`` on which any of the ``wanted`` npm packages
depend for their correct installation. Usually, a ``npm`` package and/or
some other compiler packages are required.
* ``required states`` on which any of the ``wanted`` packages depend for their
correct installation (ie, ``epel`` for RedHat families).

``packages.archives``
-------------------

Expand Down
30 changes: 27 additions & 3 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ platforms:
image: debian:9
run_command: /lib/systemd/systemd
provision_command:
- apt-get update && apt-get install -y udev locales
- apt-get update && apt-get install -y udev locales git
- name: ubuntu-18.04
driver_config:
image: ubuntu:18.04
run_command: /lib/systemd/systemd
provision_command:
- apt-get update && apt-get install -y udev locales
- apt-get update && apt-get install -y udev locales git
- name: ubuntu-16.04
driver_config:
image: ubuntu:16.04
run_command: /lib/systemd/systemd
provision_command:
- apt-get update && apt-get install -y udev locales
- apt-get update && apt-get install -y udev locales git
- locale-gen en_US.UTF-8
- update-locale LANG=en_US.UTF-8
- name: centos-7
Expand Down Expand Up @@ -106,6 +106,30 @@ suites:
- centos-7
- fedora
- opensuse-leap-salt-minion
provisioner:
dependencies:
- name: node
repo: git
source: https://github.com/saltstack-formulas/node-formula.git
state_top:
base:
'*':
- node
- packages
pillars_from_files:
packages.sls: pillar.example
pillars:
top.sls:
base:
'*':
- node
- packages
node.sls:
node:
version: 11.11.0-1nodesource1
install_from_ppa: True
ppa:
repository_url: https://deb.nodesource.com/node_11.x

- name: ubu18
excludes:
Expand Down
6 changes: 6 additions & 0 deletions packages/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ packages:
required:
states: []
pkgs: []
npms:
wanted: []
unwanted: []
required:
states: []
pkgs: []
snaps:
packages: ['snapd', 'fuse',]
collides: []
Expand Down
7 changes: 7 additions & 0 deletions packages/gems.sls
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
{% set wanted_gems = packages.gems.wanted %}
{% set unwanted_gems = packages.gems.unwanted %}
{% if req_states %}
include:
{% for dep in req_states %}
- {{ dep }}
{% endfor %}
{% endif %}
### REQ PKGS (without these, some of the WANTED GEMS will fail to install)
gem_req_pkgs:
pkg.installed:
Expand Down
1 change: 1 addition & 0 deletions packages/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ include:
- packages.remote_pkgs
- packages.pips
- packages.gems
- packages.npms
- packages.archives
- packages.snaps
75 changes: 75 additions & 0 deletions packages/npms.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{% from "packages/map.jinja" import packages with context %}
{% set req_states = packages.npms.required.states %}
{% set req_pkgs = packages.npms.required.pkgs %}
{% set wanted_npms = packages.npms.wanted %}
{% set unwanted_npms = packages.npms.unwanted %}
{% if req_states %}
include:
{% for dep in req_states %}
- {{ dep }}
{% endfor %}
{% endif %}
# As we depend on npm installed, if this state file is invoked every time
# if will fail with 'npm not found'. This condition makes sure it's run
# only when explicitly asking for adding/removing npms
{% if wanted_npms or unwanted_npms %}
### REQ PKGS (without these, some of the WANTED NPMS will fail to install)
npm_req_pkgs:
pkg.installed:
- pkgs: {{ req_pkgs | json }}
### NPM PKGS to install using npm
# (requires the npm binary installed, either by the system or listed in
# the required packages
{% if packages.npms.dir is defined %}
npms_dir:
file.directory:
- name: {{ packages.npms.dir }}
- user: {{ 'root' if 'user' not in packages.npms else packages.npms.user }}
- group: {{ 'root' if 'group' not in packages.npms else packages.npms.group }}
- mode: {{ '0755' if 'mode' not in packages.npms else packages.npms.mode }}
- makedirs: True
{% endif %}
wanted_npms:
npm.installed:
- pkgs: {{ wanted_npms | json }}
{% if packages.npms.dir is defined %}
- dir: {{ packages.npms.dir }}
{% endif %}
{% if packages.npms.user is defined %}
- user: {{ packages.npms.user }}
{% endif %}
{% if packages.npms.registry is defined %}
- registry: {{ packages.npms.registry }}
{% endif %}
{% if packages.npms.env is defined %}
- env: {{ packages.npms.env | json }}
{% endif %}
{% if packages.npms.force_reinstall is defined %}
- force_reinstall: {{ packages.npms.force_reinstall }}
{% endif %}
- require:
{% if packages.npms.dir is defined %}
- file: npms_dir
{% endif %}
- pkg: npm_req_pkgs
{% if req_states %}
{% for dep in req_states %}
- sls: {{ dep }}
{% endfor %}
{% endif %}
{% for upn in unwanted_npms %}
{{ upn }}:
npm.removed
{% endfor %}
{% endif %}
7 changes: 7 additions & 0 deletions packages/pips.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
{% set unwanted_pips = packages.pips.unwanted %}
{% set pip_config = packages.pips.config %}
{% if req_states %}
include:
{% for dep in req_states %}
- {{ dep }}
{% endfor %}
{% endif %}
### REQ PKGS (without these, some of the WANTED PIPS will fail to install)
pip_req_pkgs:
pkg.installed:
Expand Down
7 changes: 7 additions & 0 deletions packages/pkgs.sls
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
{% set wanted_packages = packages.pkgs.wanted %}
{% set unwanted_packages = packages.pkgs.unwanted %}
{% if req_states %}
include:
{% for dep in req_states %}
- {{ dep }}
{% endfor %}
{% endif %}
### PRE-REQ PKGS (without these, some of the WANTED PKGS will fail to install)
pkg_req_pkgs:
pkg.installed:
Expand Down
5 changes: 5 additions & 0 deletions packages/snaps.sls
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
### REQ PKGS (without this, SNAPS can fail to install/uninstall)
include:
- packages.pkgs
{% if req_states %}
{% for dep in req_states %}
- {{ dep }}
{% endfor %}
{% endif %}
extend:
unwanted_pkgs:
Expand Down
29 changes: 29 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ packages:
timeout: 120
default-timeout: 120
# proxy: http://proxy.example.com:3128

gems:
wanted:
- progressbar
Expand All @@ -51,13 +52,41 @@ packages:
- diff-lcs
- kitchen-vagrant
- kwalify

snaps:
wanted:
- hello-world
classic:
- test-snapd-hello-classic
unwanted:
- goodbye-world

npms:
dir: /home/kitchen/npms # The target directory in which to install the package, or None for global installation
user: kitchen # The user to run NPM with (and to assign to `dir`)
group: kitchen # The group to assign to `dir`
mode: 0755 # The permissions to assign to `dir`
# registry: None # The NPM registry from which to install the package
# env: None # A list of environment variables to be set prior to execution
# force_reinstall: False # Install the package even if it is already installed
required:
states:
- node.pkg
wanted:
# Valid formats:
#
# @google-cloud/bigquery@^0.9.6
# @foobar
# buffer-equal-constant-time@1.0.1
# coffee-script
# You need to quote the package if it starts with '@'
- '@davidodio/hello@2.3.0'
- hello-world-npm
- sax
- coffee-script@1.0.1
unwanted:
- gist

archives:
wanted:
terminator:
Expand Down
52 changes: 52 additions & 0 deletions test/integration/default/npms_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## FIXME! inspec's npm resource fails to check correctly (sudo issues, path issues)
## so I added some "poor man's checks" to ensure, at least, that npms are in place

npms_path = '/home/kitchen/npms'

wanted_npms = {
'@davidodio/hello': '2.3.0',
'hello-world-npm': '1.1.1',
'sax': '1.2.4',
'coffee-script': '1.0.1'
}

### WANTED/REQUIRED
control 'Wanted/Required npm packages' do
title 'should be installed'
desc '(only testing in the Debian platform, as the node-formula dependency is too specific)'

only_if do
os.name == 'debian'
end

describe directory(npms_path) do
it { should exist }
its('owner') { should cmp 'kitchen' }
its('group') { should cmp 'kitchen' }
its('mode') { should cmp '0755' }
end

wanted_npms.each do |p,v|
describe directory("#{npms_path}/node_modules/#{p}") do
it { should exist }
end
end
end

### UNWANTED
control 'Unwanted npm packages' do
title 'should be uninstalled'
desc '(only testing in the Debian platform, as the node-formula dependency is too specific)'

only_if do
os.name == 'debian'
end

%w{
gist
}.each do |p|
describe npm(p) do
it { should_not be_installed }
end
end
end

0 comments on commit 40f0541

Please sign in to comment.