Skip to content

Commit c475a4c

Browse files
authored
Merge pull request #31 from JulioECastro/master
Correct packages and fpm as checkinstall alternative for RedHat and CentOS
2 parents fd627aa + ad7f639 commit c475a4c

File tree

3 files changed

+63
-17
lines changed

3 files changed

+63
-17
lines changed

node/map.jinja

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{% set pillar_get = salt['pillar.get'] -%}
22

33
{% if pillar_get('node:install_from_source') %}
4-
{% set default_npm_prefix = '/usr/local' %}
4+
{% set default_npm_prefix = '/usr/local' %}
55
{% else %}
6-
{% set default_npm_prefix = '/usr' %}
6+
{% set default_npm_prefix = '/usr' %}
77
{% endif %}
88
{% set npm_prefix = pillar_get('npm:prefix', default_npm_prefix) %}
99
{% set npm_bin = '{0}/bin/npm'.format(npm_prefix) %}
1010
{% set npm_src_requirement = 'file: {0}'.format(npm_bin) %}
1111

1212
{% if npm_prefix == '/usr' %}
13-
{% set npmrc_prefix = '' %}
13+
{% set npmrc_prefix = '' %}
1414
{% else %}
15-
{% set npmrc_prefix = npm_prefix %}
15+
{% set npmrc_prefix = npm_prefix %}
1616
{% endif %}
1717
{% set npmrc = '{0}/etc/npmrc'.format(npmrc_prefix) %}
1818

@@ -31,8 +31,17 @@
3131
},
3232
}, grain='os', merge=pillar_get('node:lookup')) %}
3333

34-
{% if pillar_get('node:install_from_source') or (grains['os'] == 'Debian' and grains['osrelease']|float < 8 and not pillar_get('node:install_from_ppa')) %}
35-
{% set npm_requirement = npm_src_requirement %}
34+
{% if pillar_get('node:install_from_source') or (grains['os_family'] == 'Debian' and grains['osrelease']|float < 8 and not pillar_get('node:install_from_ppa')) %}
35+
{% set npm_requirement = npm_src_requirement %}
3636
{% else %}
37-
{% set npm_requirement = 'pkg: {0}'.format(node['npm_pkg']) %}
37+
{% set npm_requirement = 'pkg: {0}'.format(node['npm_pkg']) %}
3838
{% endif %}
39+
40+
{% set from_src_requirements = salt['grains.filter_by']({
41+
'Debian': {
42+
'pkgs': ['git', 'curl', 'gcc', 'pkg-config', 'build-essential', 'checkinstall', 'libssl-dev', 'g++']
43+
},
44+
'RedHat': {
45+
'pkgs': ['git', 'curl', 'gcc','openssl-devel','pkgconfig', 'gcc-c++', 'make', 'automake']
46+
},
47+
}, grain='os_family', merge=pillar_get('from_src_requirements:lookup'), default='Debian') %}

node/pkg.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- from "node/map.jinja" import node, npm_bin with context %}
22
3-
{%- if grains['os'] in ['Ubuntu', 'Debian'] and salt['pillar.get']('node:install_from_ppa') %}
3+
{%- if grains['os_family'] in ['Ubuntu', 'Debian'] and salt['pillar.get']('node:install_from_ppa') %}
44
nodejs.ppa:
55
pkg.installed:
66
- name: apt-transport-https

node/source.sls

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% from "node/map.jinja" import from_src_requirements with context %}
2+
13
{% set node = pillar.get('node', {}) -%}
24
{% set version = node.get('version', '5.1.0') -%}
35
{% set checksum = node.get('checksum', '25b2d3b7dd57fe47a483539fea240a3c6bbbdab4d89a45a812134cf1380ecb94') -%}
@@ -12,15 +14,19 @@
1214
1315
Ensure required packages are present:
1416
pkg.installed:
15-
- names:
16-
- libssl-dev
17-
- git
18-
- pkg-config
19-
- build-essential
20-
- curl
17+
- names: {{ from_src_requirements.pkgs|json }}
18+
19+
{% if grains['os_family'] in ['RedHat', 'CentOS'] %}
20+
Alternative checkinstall requirement:
21+
pkg.installed:
22+
- pkgs:
23+
- ruby-devel
2124
- gcc
22-
- g++
23-
- checkinstall
25+
26+
fpm:
27+
gem.installed:
28+
- user: root
29+
{% endif %}
2430
2531
Download node sources:
2632
file.managed:
@@ -48,11 +54,42 @@ make-node:
4854
- cwd: /usr/src/node-v{{ version }}
4955
- name: make --jobs={{ make_jobs }}
5056
57+
{% if grains['os_family'] in ['RedHat', 'CentOS'] %}
58+
make-install-node:
59+
cmd.run:
60+
- cwd: /usr/src/node-v{{ version }}
61+
- name: make install DESTDIR=/usr/src/node-v{{ version }}/tmp
62+
- onchanges:
63+
- cmd: make-node
64+
65+
fpm-node:
66+
cmd.run:
67+
- cwd: /usr/src/node-v{{ version }}
68+
- name: fpm -s dir -t rpm -C /usr/src/node-v{{ version }}/tmp --name=node --version "{{ version }}" --iteration 1 --description "Node package v{{ version }} (fpm)" --force
69+
- onchanges:
70+
- cmd: make-install-node
71+
72+
install-node:
73+
pkg.installed:
74+
- sources:
75+
- node: /usr/src/node-v{{ version }}/node-{{ version }}-1.x86_64.rpm
76+
- onchanges:
77+
- cmd: fpm-node
78+
{% else %}
79+
5180
install-node:
5281
cmd.run:
5382
- cwd: /usr/src/node-v{{ version }}
5483
- name: checkinstall --install=yes --pkgname=node --pkgversion "{{ version }}" --default
5584
- onchanges:
5685
- cmd: make-node
5786
58-
{% endif %}
87+
{% endif %}
88+
89+
{% else %}
90+
91+
Version Control:
92+
test.succeed_without_changes:
93+
- name: Node version {{ nodeVersion }} already installed
94+
95+
{% endif %}

0 commit comments

Comments
 (0)