Skip to content

[php/ng] support the use of a list of php versions #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions php/ng/cli/ini.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
11 changes: 11 additions & 0 deletions php/ng/cli/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
11 changes: 11 additions & 0 deletions php/ng/cli/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,3 +25,4 @@ php_{{ phpng_version }}_link:
- which php
- test {{ current_php }} != $(which php{{ phpng_version }})
{% endif %}
{% endif %}
34 changes: 34 additions & 0 deletions php/ng/fpm/config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@
{% 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 conf_settings = odict(php.lookup.fpm.defaults) %}
{% 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) %}

{% 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' }) %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very satisfied with this part, I would want the loop above to be more generic but for some reason I couldn't get it to change the subdictionnary


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) %}

Expand All @@ -27,3 +60,4 @@ php_fpm_conf_config:
- group: {{ php.lookup.fpm.group }}
- file_mode: 755
- make_dirs: True
{% endif %}
21 changes: 21 additions & 0 deletions php/ng/fpm/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@ 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 pillar_php_ng_version is iterable and pillar_php_ng_version is not string %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now I'm not sure how this handles when 7.3 as a float is used. Is setting the version without quotes supported by the existing version of the formula ?

{% for version in pillar_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 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:
- pkg: php_install_fpm
php_fpm_conf_config_{{ version }}:
file:
- require:
- pkg: php_install_fpm
{% endfor %}
{% else %}
php_fpm_ini_config:
file:
- require:
Expand All @@ -21,3 +41,4 @@ extend:
file:
- require:
- pkg: php_install_fpm
{% endif %}
10 changes: 9 additions & 1 deletion php/ng/fpm/pools_config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
{% 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) %}

{% 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 = 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) %}
{% endif %}

{{ state }}:
{% if config.enabled %}
Expand Down
2 changes: 1 addition & 1 deletion php/ng/ini.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
- source: salt://php/ng/files/php.ini
- template: jinja
- context:
config: {{ serialize(settings) }}
config: {{ serialize(odict(settings)) }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is needed

{%- endmacro -%}
17 changes: 16 additions & 1 deletion php/ng/installed.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,31 @@
{% 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 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 %}
{% endif %}
{% endif %}
{% endfor %}
{% else %}
{% do pkgs.append(pkginfo) %}
{% 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 %}
{% endif %}
{% endif %}

{% if grains['os_family'] == "Debian" and (state == 'cli' or state == 'fpm' or state == 'php') %}
Expand Down Expand Up @@ -60,7 +75,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:
Expand Down
7 changes: 6 additions & 1 deletion php/ng/map.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{%- set phpng_version = salt['pillar.get']('php:ng:version', '7.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 = pillar_php_ng_version|string %}
{% endif %}
{%- set freebsd_phpng_version = phpng_version.replace('.', '') %}

{%- if salt['grains.get']('os') == "Ubuntu" %}
Expand Down
11 changes: 11 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ 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"

# 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
# are possible in the pillar for unique cases, if your OS is not
# represented, please consider adding it to the map.jinja for
Expand Down