Saltstack Official PHP Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9KB

  1. {% from "php/map.jinja" import php with context %}
  2. {% set install_file = php.lookup.pkgs.local_bin + '/' + php.lookup.pkgs.composer_bin %}
  3. {% if not salt['config.get']('sudo_user') %}
  4. {% set salt_user = salt['config.get']('user', 'root') %}
  5. {% else %}
  6. {% set salt_user = salt['config.get']('sudo_user', 'root') %}
  7. {% endif %}
  8. {% set salt_user_home = salt['user.info'](salt_user).get('home', '/root') %}
  9. include:
  10. - php
  11. {%- for module in php.lookup.get('composer', {}).get('required_modules', []) %}
  12. - php.{{ module }}
  13. {%- endfor %}
  14. get-composer:
  15. file.managed:
  16. - name: {{ php.lookup.pkgs.temp_dir }}/installer
  17. - mode: '0755'
  18. - unless: test -f {{ install_file }}
  19. - source: https://getcomposer.org/installer
  20. - source_hash: https://composer.github.io/installer.sig
  21. - require:
  22. - pkg: php
  23. install-composer:
  24. cmd.run:
  25. - name: php {{ php.lookup.pkgs.temp_dir }}/installer --filename={{ php.lookup.pkgs.composer_bin }} --install-dir={{ php.lookup.pkgs.local_bin }}
  26. - unless: test -f {{ install_file }}
  27. - env:
  28. - HOME: {{ salt_user_home }}
  29. - require:
  30. - file: get-composer
  31. # Get composer version date and check if older than 60day (defaultvalue of COMPOSER_DEV_WARNING_TIME)
  32. # then it's time to run `composer selfupdate`
  33. #
  34. # It would be nice if composer had a command line switch to get this, but it doesn't,
  35. # and so we just grep for it.
  36. #
  37. update-composer:
  38. cmd.run:
  39. - name: "{{ install_file }} selfupdate"
  40. {% if grains['os_family'] == 'FreeBSD' %}
  41. - unless: test $(date -v+60d -j -f "%Y-%m-%d %H:%M:%S" "$({{ install_file }} --version --no-interaction | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s")
  42. {% else %}
  43. - unless: test $(date -d "60 days $({{ install_file }} --version --no-interaction | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s")
  44. {% endif %}
  45. - cwd: {{ php.lookup.pkgs.local_bin }}
  46. - env:
  47. - HOME: {{ salt_user_home }}
  48. - require:
  49. - cmd: install-composer