install.sls 2.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_service_running = tplroot ~ '.service.running' %}
{%- from tplroot | path_join("map.jinja") import discourse with context %}
{%- from tplroot | path_join("libtofs.jinja") import files_switch with context %}

include:
  - {{ sls_service_running }}

{%- set themes = discourse | traverse('themes', {}) %}

{%- for name, params in themes.items() %}
  {%- set theme_filename = name ~ '.yaml' %}
  {%- set theme_contairer_path = '/shared' | path_join('themes',
                                                       theme_filename)
    %}
  {%- set theme_path = discourse.directory | path_join('shared',
                                                       'standalone',
                                                       'themes',
                                                       theme_filename)
    %}
  {%- set install_cmd = 'cd /var/www/discourse/ '
                        ~ '&& rake themes:install '
                        ~ '< ' ~ theme_contairer_path
    %}

  {%- set theme = {'theme_name': params.get('theme_name')} %}
  {%- set install_lookup = 'discourse-setup-themes-install-' ~ name ~ '-install-file-managed' %}

discourse-setup-themes-install-{{ name }}-config-file-managed:
  file.managed:
    - name: {{ theme_path }}
    - source: {{ files_switch(['theme.yaml.jinja'],
                              lookup=install_lookup,
                              use_subpath=True
                 )
              }}
    - mode: 644
    - user: root
    - group: root
    - makedirs: True
    - template: jinja
    - context:
        theme: {{ theme | tojson }}
    - require:
      - sls: {{ sls_service_running }}

discourse-setup-themes-install-{{ name }}-install-cmd-run:
  cmd.run:
    - name: {{ discourse | traverse('launcher:run_cmd')
               ~ " '"
               ~ install_cmd
               ~ "'"
             }}
    - cwd: {{ discourse.directory }}
    - require:
      - sls: {{ sls_service_running }}
    - retry:
        attempts: 5
        until: True
        interval: 5
        splay: 2
{%- endfor %}