mirror of
https://github.com/saltstack-formulas/packages-formula.git
synced 2025-04-16 09:40:23 +00:00
Merge pull request #51 from netmanagers/master
Add npm management support
This commit is contained in:
commit
40f05416d8
12 changed files with 269 additions and 30 deletions
|
@ -1,39 +1,43 @@
|
||||||
packages formula
|
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)
|
|
||||||
|
|
||||||
- Allow to hold/unhold system packages (#8)
|
|
||||||
- Add more tests
|
|
||||||
|
|
||||||
0.0.4 (2018-03-06)
|
|
||||||
|
|
||||||
- Allow to specify held system packages also as a list (#10)
|
|
||||||
|
|
||||||
0.0.5 (2018-03-14)
|
|
||||||
|
|
||||||
- Add snap support
|
|
||||||
|
|
||||||
0.0.6 (2018-04-09)
|
|
||||||
|
|
||||||
- Add snap with classic confinement support
|
|
||||||
|
|
||||||
0.0.7 (2018-07-11)
|
|
||||||
|
|
||||||
- Fix pip/gems for FreeBSD
|
|
||||||
|
|
||||||
0.0.8 (2018-08-23)
|
0.0.8 (2018-08-23)
|
||||||
|
|
||||||
- Add archive support
|
- Add archive support
|
||||||
|
|
||||||
0.0.9 (2018-10-03)
|
0.0.7 (2018-07-11)
|
||||||
|
|
||||||
- Add support for plain files using arcihve
|
- 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.4 (2018-03-06)
|
||||||
|
|
||||||
|
- Allow to specify held system packages also as a list (#10)
|
||||||
|
|
||||||
|
0.0.3 (2018-03-02)
|
||||||
|
|
||||||
|
- Allow to hold/unhold system packages (#8)
|
||||||
|
|
||||||
|
0.0.2 (2018-02-23)
|
||||||
|
|
||||||
|
- Add Fedora support
|
||||||
|
- Add more tests
|
||||||
|
|
||||||
|
0.0.1 (2018-02-12)
|
||||||
|
|
||||||
|
- Initial version
|
||||||
|
|
22
README.rst
22
README.rst
|
@ -127,6 +127,28 @@ You can specify:
|
||||||
* ``required states`` on which any of the ``wanted`` packages depend for their
|
* ``required states`` on which any of the ``wanted`` packages depend for their
|
||||||
correct installation (ie, ``epel`` for RedHat families).
|
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``
|
``packages.archives``
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|
30
kitchen.yml
30
kitchen.yml
|
@ -20,19 +20,19 @@ platforms:
|
||||||
image: debian:9
|
image: debian:9
|
||||||
run_command: /lib/systemd/systemd
|
run_command: /lib/systemd/systemd
|
||||||
provision_command:
|
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
|
- name: ubuntu-18.04
|
||||||
driver_config:
|
driver_config:
|
||||||
image: ubuntu:18.04
|
image: ubuntu:18.04
|
||||||
run_command: /lib/systemd/systemd
|
run_command: /lib/systemd/systemd
|
||||||
provision_command:
|
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
|
- name: ubuntu-16.04
|
||||||
driver_config:
|
driver_config:
|
||||||
image: ubuntu:16.04
|
image: ubuntu:16.04
|
||||||
run_command: /lib/systemd/systemd
|
run_command: /lib/systemd/systemd
|
||||||
provision_command:
|
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
|
- locale-gen en_US.UTF-8
|
||||||
- update-locale LANG=en_US.UTF-8
|
- update-locale LANG=en_US.UTF-8
|
||||||
- name: centos-7
|
- name: centos-7
|
||||||
|
@ -106,6 +106,30 @@ suites:
|
||||||
- centos-7
|
- centos-7
|
||||||
- fedora
|
- fedora
|
||||||
- opensuse-leap-salt-minion
|
- 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
|
- name: ubu18
|
||||||
excludes:
|
excludes:
|
||||||
|
|
|
@ -23,6 +23,12 @@ packages:
|
||||||
required:
|
required:
|
||||||
states: []
|
states: []
|
||||||
pkgs: []
|
pkgs: []
|
||||||
|
npms:
|
||||||
|
wanted: []
|
||||||
|
unwanted: []
|
||||||
|
required:
|
||||||
|
states: []
|
||||||
|
pkgs: []
|
||||||
snaps:
|
snaps:
|
||||||
packages: ['snapd', 'fuse',]
|
packages: ['snapd', 'fuse',]
|
||||||
collides: []
|
collides: []
|
||||||
|
|
|
@ -7,6 +7,13 @@
|
||||||
{% set wanted_gems = packages.gems.wanted %}
|
{% set wanted_gems = packages.gems.wanted %}
|
||||||
{% set unwanted_gems = packages.gems.unwanted %}
|
{% 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)
|
### REQ PKGS (without these, some of the WANTED GEMS will fail to install)
|
||||||
gem_req_pkgs:
|
gem_req_pkgs:
|
||||||
pkg.installed:
|
pkg.installed:
|
||||||
|
|
|
@ -6,5 +6,6 @@ include:
|
||||||
- packages.remote_pkgs
|
- packages.remote_pkgs
|
||||||
- packages.pips
|
- packages.pips
|
||||||
- packages.gems
|
- packages.gems
|
||||||
|
- packages.npms
|
||||||
- packages.archives
|
- packages.archives
|
||||||
- packages.snaps
|
- packages.snaps
|
||||||
|
|
75
packages/npms.sls
Normal file
75
packages/npms.sls
Normal file
|
@ -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 %}
|
|
@ -8,6 +8,13 @@
|
||||||
{% set unwanted_pips = packages.pips.unwanted %}
|
{% set unwanted_pips = packages.pips.unwanted %}
|
||||||
{% set pip_config = packages.pips.config %}
|
{% 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)
|
### REQ PKGS (without these, some of the WANTED PIPS will fail to install)
|
||||||
pip_req_pkgs:
|
pip_req_pkgs:
|
||||||
pkg.installed:
|
pkg.installed:
|
||||||
|
|
|
@ -9,6 +9,13 @@
|
||||||
{% set wanted_packages = packages.pkgs.wanted %}
|
{% set wanted_packages = packages.pkgs.wanted %}
|
||||||
{% set unwanted_packages = packages.pkgs.unwanted %}
|
{% 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)
|
### PRE-REQ PKGS (without these, some of the WANTED PKGS will fail to install)
|
||||||
pkg_req_pkgs:
|
pkg_req_pkgs:
|
||||||
pkg.installed:
|
pkg.installed:
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
### REQ PKGS (without this, SNAPS can fail to install/uninstall)
|
### REQ PKGS (without this, SNAPS can fail to install/uninstall)
|
||||||
include:
|
include:
|
||||||
- packages.pkgs
|
- packages.pkgs
|
||||||
|
{% if req_states %}
|
||||||
|
{% for dep in req_states %}
|
||||||
|
- {{ dep }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
extend:
|
extend:
|
||||||
unwanted_pkgs:
|
unwanted_pkgs:
|
||||||
|
|
|
@ -43,6 +43,7 @@ packages:
|
||||||
timeout: 120
|
timeout: 120
|
||||||
default-timeout: 120
|
default-timeout: 120
|
||||||
# proxy: http://proxy.example.com:3128
|
# proxy: http://proxy.example.com:3128
|
||||||
|
|
||||||
gems:
|
gems:
|
||||||
wanted:
|
wanted:
|
||||||
- progressbar
|
- progressbar
|
||||||
|
@ -51,6 +52,7 @@ packages:
|
||||||
- diff-lcs
|
- diff-lcs
|
||||||
- kitchen-vagrant
|
- kitchen-vagrant
|
||||||
- kwalify
|
- kwalify
|
||||||
|
|
||||||
snaps:
|
snaps:
|
||||||
wanted:
|
wanted:
|
||||||
- hello-world
|
- hello-world
|
||||||
|
@ -58,6 +60,33 @@ packages:
|
||||||
- test-snapd-hello-classic
|
- test-snapd-hello-classic
|
||||||
unwanted:
|
unwanted:
|
||||||
- goodbye-world
|
- 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:
|
archives:
|
||||||
wanted:
|
wanted:
|
||||||
terminator:
|
terminator:
|
||||||
|
|
52
test/integration/default/npms_spec.rb
Normal file
52
test/integration/default/npms_spec.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue