From b3032391dd5dc776f999b034d4e5e30fda1d823c Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Tue, 26 Mar 2019 18:31:43 +0100 Subject: [PATCH 1/6] feat(php/ng): support the use of a list of php versions Related to #138 --- php/ng/fpm/config.sls | 34 ++++++++++++++++++++++++++++++++++ php/ng/fpm/init.sls | 20 ++++++++++++++++++++ php/ng/fpm/pools_config.sls | 9 ++++++++- php/ng/ini.jinja | 2 +- php/ng/installed.jinja | 16 +++++++++++++++- php/ng/map.jinja | 6 +++++- 6 files changed, 83 insertions(+), 4 deletions(-) diff --git a/php/ng/fpm/config.sls b/php/ng/fpm/config.sls index a91ff89..0129034 100644 --- a/php/ng/fpm/config.sls +++ b/php/ng/fpm/config.sls @@ -11,6 +11,39 @@ {% endif %} {% endfor %} + +{% if salt['pillar.get']('php:ng:version') is iterable %} + {% for version in salt['pillar.get']('php:ng:version') %} + {% set conf_settings = odict(php.lookup.fpm.defaults) %} + {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} + {% set ini = php.lookup.fpm.ini|replace(first_version, version) %} + {% set conf = php.lookup.fpm.conf|replace(first_version, version) %} + {% set pools = php.lookup.fpm.pools|replace(first_version, version) %} + + {% for key, value in conf_settings.items() %} + {% if value is string %} + {% do conf_settings.update({key: value.replace(first_version, version)}) %} + {% endif %} + {% endfor %} + {% do conf_settings.global.update({'pid': '/var/run/php' + version + '-fpm.pid' }) %} + {% do conf_settings.global.update({'error_log': '/var/log/php' + version + '-fpm.log' }) %} + +php_fpm_ini_config_{{ version }}: + {{ php_ini(ini, php.fpm.config.ini.opts, ini_settings) }} + +php_fpm_conf_config_{{ version }}: + {{ php_ini(conf, php.fpm.config.conf.opts, odict(conf_settings)) }} + +{{ pools }}: + file.directory: + - name: {{ pools }} + - user: {{ php.lookup.fpm.user }} + - group: {{ php.lookup.fpm.group }} + - file_mode: 755 + - make_dirs: True + {% endfor %} +{% else %} + {% set conf_settings = php.lookup.fpm.defaults %} {% do conf_settings.update(php.fpm.config.conf.settings) %} @@ -27,3 +60,4 @@ php_fpm_conf_config: - group: {{ php.lookup.fpm.group }} - file_mode: 755 - make_dirs: True +{% endif %} diff --git a/php/ng/fpm/init.sls b/php/ng/fpm/init.sls index 0087bc3..b7f952b 100644 --- a/php/ng/fpm/init.sls +++ b/php/ng/fpm/init.sls @@ -9,10 +9,29 @@ extend: php_fpm_service: service: - watch: + {% if salt['pillar.get']('php:ng:version') is iterable %} + {% for version in salt['pillar.get']('php:ng:version') %} + - file: php_fpm_ini_config_{{ version }} + - file: php_fpm_conf_config_{{ version }} + {% endfor %} + {% else %} - file: php_fpm_ini_config - file: php_fpm_conf_config + {% endif %} - require: - sls: php.ng.fpm.config + {% if salt['pillar.get']('php:ng:version') is iterable %} + {% for version in salt['pillar.get']('php:ng:version') %} + php_fpm_ini_config_{{ version }}: + file: + - require: + - pkg: php_install_fpm + php_fpm_conf_config_{{ version }}: + file: + - require: + - pkg: php_install_fpm + {% endfor %} + {% else %} php_fpm_ini_config: file: - require: @@ -21,3 +40,4 @@ extend: file: - require: - pkg: php_install_fpm + {% endif %} diff --git a/php/ng/fpm/pools_config.sls b/php/ng/fpm/pools_config.sls index 625f303..a65dfc8 100644 --- a/php/ng/fpm/pools_config.sls +++ b/php/ng/fpm/pools_config.sls @@ -17,7 +17,14 @@ {% do pvalues.update(pool_defaults) %} {% endfor %} {% set state = 'php_fpm_pool_conf_' ~ loop.index0 %} -{% set fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %} + +{% if salt['pillar.get']('php:ng:version') is iterable %} + {% set first_fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %} + {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} + {% set fpath = first_fpath.replace(first_version, config.get('phpversion', '7.0')) %} +{% else %} + {% set fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %} +{% endif %} {{ state }}: {% if config.enabled %} diff --git a/php/ng/ini.jinja b/php/ng/ini.jinja index 8dfc1fe..d63b960 100644 --- a/php/ng/ini.jinja +++ b/php/ng/ini.jinja @@ -10,5 +10,5 @@ - source: salt://php/ng/files/php.ini - template: jinja - context: - config: {{ serialize(settings) }} + config: {{ serialize(odict(settings)) }} {%- endmacro -%} diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index 0033d31..808be89 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -16,10 +16,24 @@ {% do specials.append(pkg) %} {% else %} {% do pkgs.append(pkg) %} + {% if salt['pillar.get']('php:ng:version') is iterable %} + {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} + {% for other_version in salt['pillar.get']('php:ng:version') %} + {% set other_version_str = other_version|string %} + {% do pkgs.append(pkg.replace(first_version, other_version_str)) %} + {% endfor %} + {% endif %} {% endif %} {% endfor %} {% else %} {% do pkgs.append(pkginfo) %} + {% if salt['pillar.get']('php:ng:version') is iterable %} + {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} + {% for other_version in salt['pillar.get']('php:ng:version') %} + {% set other_version_str = other_version|string %} + {% do pkgs.append(pkginfo.replace(first_version, other_version_str)) %} + {% endfor %} + {% endif %} {% endif %} {% if grains['os_family'] == "Debian" and (state == 'cli' or state == 'fpm' or state == 'php') %} @@ -60,7 +74,7 @@ php_ppa_{{ state }}: - __env__: - LC_ALL: C.UTF-8 - onlyif: - - test ! -e /etc/apt/sources.list.d/ondrej-php.list + - test ! -e /etc/apt/sources.list.d/ondrej-php.list - require_in: - pkg: php_install_{{ state }} pkg.latest: diff --git a/php/ng/map.jinja b/php/ng/map.jinja index fb63de3..36678b6 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -1,7 +1,11 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} +{%- if salt['pillar.get']('php:ng:version') is iterable %} + {%- set phpng_version = salt['pillar.get']('php:ng:version')[0]|string %} +{% else %} + {%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} +{% endif %} {%- set freebsd_phpng_version = phpng_version.replace('.', '') %} {%- if salt['grains.get']('os') == "Ubuntu" %} From a98aa7e81addd5e10cae7e84672a255d1d4a7c92 Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Fri, 5 Apr 2019 15:08:06 +0200 Subject: [PATCH 2/6] docs(pillar.example): example of versions --- pillar.example | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pillar.example b/pillar.example index 6023952..c5be4eb 100644 --- a/pillar.example +++ b/pillar.example @@ -15,6 +15,13 @@ php: # when you add the php.mongo formula to your execution list mongo_version: "1.5.5" ng: + # set the version of php to be used + version: "7.3" + # can be a list of versions : + # version: + # - "7.3" + # - "7.2" + # this section contains mostly grain filtered data, while overrides # are possible in the pillar for unique cases, if your OS is not # represented, please consider adding it to the map.jinja for From dbb542c4fb580f93aded2390d637fb5c06891c9c Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Fri, 5 Apr 2019 15:08:30 +0200 Subject: [PATCH 3/6] fix(php/ng): don't iterate on string, make sure list is not string --- php/ng/fpm/config.sls | 8 ++++---- php/ng/fpm/init.sls | 9 +++++---- php/ng/fpm/pools_config.sls | 5 +++-- php/ng/installed.jinja | 13 +++++++------ php/ng/map.jinja | 7 ++++--- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/php/ng/fpm/config.sls b/php/ng/fpm/config.sls index 0129034..a62d364 100644 --- a/php/ng/fpm/config.sls +++ b/php/ng/fpm/config.sls @@ -11,11 +11,11 @@ {% endif %} {% endfor %} - -{% if salt['pillar.get']('php:ng:version') is iterable %} - {% for version in salt['pillar.get']('php:ng:version') %} +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} +{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% for version in pillar_php_ng_version %} {% set conf_settings = odict(php.lookup.fpm.defaults) %} - {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} + {% set first_version = pillar_php_ng_version[0]|string %} {% set ini = php.lookup.fpm.ini|replace(first_version, version) %} {% set conf = php.lookup.fpm.conf|replace(first_version, version) %} {% set pools = php.lookup.fpm.pools|replace(first_version, version) %} diff --git a/php/ng/fpm/init.sls b/php/ng/fpm/init.sls index b7f952b..e6b4e3a 100644 --- a/php/ng/fpm/init.sls +++ b/php/ng/fpm/init.sls @@ -5,12 +5,13 @@ include: - php.ng.fpm.service - php.ng.fpm.pools +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} extend: php_fpm_service: service: - watch: - {% if salt['pillar.get']('php:ng:version') is iterable %} - {% for version in salt['pillar.get']('php:ng:version') %} + {% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% for version in pillar_php_ng_version %} - file: php_fpm_ini_config_{{ version }} - file: php_fpm_conf_config_{{ version }} {% endfor %} @@ -20,8 +21,8 @@ extend: {% endif %} - require: - sls: php.ng.fpm.config - {% if salt['pillar.get']('php:ng:version') is iterable %} - {% for version in salt['pillar.get']('php:ng:version') %} + {% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% for version in pillar_php_ng_version %} php_fpm_ini_config_{{ version }}: file: - require: diff --git a/php/ng/fpm/pools_config.sls b/php/ng/fpm/pools_config.sls index a65dfc8..6850ad6 100644 --- a/php/ng/fpm/pools_config.sls +++ b/php/ng/fpm/pools_config.sls @@ -18,9 +18,10 @@ {% endfor %} {% set state = 'php_fpm_pool_conf_' ~ loop.index0 %} -{% if salt['pillar.get']('php:ng:version') is iterable %} +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} +{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} {% set first_fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %} - {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} + {% set first_version = pillar_php_ng_version[0]|string %} {% set fpath = first_fpath.replace(first_version, config.get('phpversion', '7.0')) %} {% else %} {% set fpath = path_join(config.get('filename', pool), php.lookup.fpm.pools) %} diff --git a/php/ng/installed.jinja b/php/ng/installed.jinja index 808be89..a9f006c 100644 --- a/php/ng/installed.jinja +++ b/php/ng/installed.jinja @@ -10,15 +10,16 @@ {% set pkgs = [] %} {% set specials = [] %} +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} {% if pkginfo is iterable and pkginfo is not string %} {% for pkg in pkginfo %} {% if pkg is mapping %} {% do specials.append(pkg) %} {% else %} {% do pkgs.append(pkg) %} - {% if salt['pillar.get']('php:ng:version') is iterable %} - {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} - {% for other_version in salt['pillar.get']('php:ng:version') %} + {% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% set first_version = pillar_php_ng_version[0]|string %} + {% for other_version in pillar_php_ng_version %} {% set other_version_str = other_version|string %} {% do pkgs.append(pkg.replace(first_version, other_version_str)) %} {% endfor %} @@ -27,9 +28,9 @@ {% endfor %} {% else %} {% do pkgs.append(pkginfo) %} - {% if salt['pillar.get']('php:ng:version') is iterable %} - {% set first_version = salt['pillar.get']('php:ng:version')[0]|string %} - {% for other_version in salt['pillar.get']('php:ng:version') %} + {% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% set first_version = pillar_php_ng_version[0]|string %} + {% for other_version in pillar_php_ng_version %} {% set other_version_str = other_version|string %} {% do pkgs.append(pkginfo.replace(first_version, other_version_str)) %} {% endfor %} diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 36678b6..4d214ab 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{%- if salt['pillar.get']('php:ng:version') is iterable %} - {%- set phpng_version = salt['pillar.get']('php:ng:version')[0]|string %} +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} +{%- if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {%- set phpng_version = pillar_php_ng_version[0]|string %} {% else %} - {%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} + {%- set phpng_version = pillar_php_ng_version|string %} {% endif %} {%- set freebsd_phpng_version = phpng_version.replace('.', '') %} From bb4a077d84208194346875e2784ba59aeb2cb708 Mon Sep 17 00:00:00 2001 From: Simon Schneider Date: Fri, 12 Apr 2019 15:55:28 +0200 Subject: [PATCH 4/6] feat(php/ng): support for php cli multiversion --- php/ng/cli/ini.sls | 11 +++++++++++ php/ng/cli/init.sls | 11 +++++++++++ php/ng/cli/install.sls | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/php/ng/cli/ini.sls b/php/ng/cli/ini.sls index 6844192..15c7727 100644 --- a/php/ng/cli/ini.sls +++ b/php/ng/cli/ini.sls @@ -11,5 +11,16 @@ {% endif %} {% endfor %} +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} +{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% for version in pillar_php_ng_version %} + {% set first_version = pillar_php_ng_version[0]|string %} + {% set ini = php.lookup.cli.ini|replace(first_version, version) %} +php_cli_ini_{{ version }}: + {{ php_ini(ini, php.cli.ini.opts, settings) }} + {% endfor %} +{% else %} + php_cli_ini: {{ php_ini(php.lookup.cli.ini, php.cli.ini.opts, settings) }} +{% endif %} diff --git a/php/ng/cli/init.sls b/php/ng/cli/init.sls index 06bc3e9..621d2c3 100644 --- a/php/ng/cli/init.sls +++ b/php/ng/cli/init.sls @@ -4,8 +4,19 @@ include: - php.ng.cli.install - php.ng.cli.ini +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} +{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} +extend: + {% for version in pillar_php_ng_version %} + php_cli_ini_{{ version }}: + file: + - require: + - sls: php.ng.cli.install + {% endfor %} +{% else %} extend: php_cli_ini: file: - require: - sls: php.ng.cli.install +{% endif %} diff --git a/php/ng/cli/install.sls b/php/ng/cli/install.sls index ee4d463..a281933 100644 --- a/php/ng/cli/install.sls +++ b/php/ng/cli/install.sls @@ -3,8 +3,18 @@ {%- if salt['grains.get']('os_family') == "Debian" %} {% set current_php = salt['alternatives.show_current']('php') %} +{% set pillar_php_ng_version = salt['pillar.get']('php:ng:version', '7.0') %} +{% if pillar_php_ng_version is iterable and pillar_php_ng_version is not string %} + {% if 'alternatives_version' in salt['pillar.get']('php:ng') %} + {% set phpng_version = salt['pillar.get']('php:ng:alternatives_version') %} + {% else %} + {% set phpng_version = false %} + {% endif %} +{% else %} {% set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} +{% endif %} +{% if phpng_version %} php_{{ phpng_version }}_link: alternatives.set: - name: php @@ -15,3 +25,4 @@ php_{{ phpng_version }}_link: - which php - test {{ current_php }} != $(which php{{ phpng_version }}) {% endif %} +{% endif %} From 23a6ec1001cfd0efd64e279cb3123c2f13797f6b Mon Sep 17 00:00:00 2001 From: Simon Schneider Date: Fri, 12 Apr 2019 16:01:44 +0200 Subject: [PATCH 5/6] docs(pillar.example): add example for alternatives with multiversion --- pillar.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pillar.example b/pillar.example index c5be4eb..70e5d10 100644 --- a/pillar.example +++ b/pillar.example @@ -22,6 +22,9 @@ php: # - "7.3" # - "7.2" + # set the version for the Debian alternatives system, when using a list of versions, otherwise php:ng:version is used. + alternatives_version: "7.3" + # this section contains mostly grain filtered data, while overrides # are possible in the pillar for unique cases, if your OS is not # represented, please consider adding it to the map.jinja for From 38fe58f150c2110187d9c18afb805cd4a74bebcf Mon Sep 17 00:00:00 2001 From: Simon Schneider Date: Fri, 12 Apr 2019 16:05:36 +0200 Subject: [PATCH 6/6] style(pillar.example): add line break --- pillar.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pillar.example b/pillar.example index 70e5d10..63b215d 100644 --- a/pillar.example +++ b/pillar.example @@ -22,7 +22,8 @@ php: # - "7.3" # - "7.2" - # set the version for the Debian alternatives system, when using a list of versions, otherwise php:ng:version is used. + # set the version for the Debian alternatives system, when using a list of versions, + # php:ng:version is used otherwise. alternatives_version: "7.3" # this section contains mostly grain filtered data, while overrides