Переглянути джерело

Improve limitations related to `git.latest` in `salt.formulas` (#239)

* Ensure options for formulas `git.latest` are also based on defaults

* Prevent erroneous remote tracking branch modification by `salt.formulas` #238

* Allow multiple envs to use the same gitdir for `salt.formulas`

* Ensure `gitdir` original branch is checked out after formulas `git.latest`

* Fix erroneous comment re: merging in `salt` pillar
tags/v0.57.0
myii 6 роки тому
джерело
коміт
91b666c75f
5 змінених файлів з 61 додано та 8 видалено
  1. +3
    -0
      pillar.example
  2. +3
    -0
      salt/defaults.yaml
  3. +10
    -1
      salt/formulas.jinja
  4. +37
    -6
      salt/formulas.sls
  5. +8
    -1
      salt/map.jinja

+ 3
- 0
pillar.example Переглянути файл

user: root user: root
group: root group: root
mode: 755 mode: 755
# Explicitly checkout the original branch for repos after the
# git.latest states have been processed (False by default)
checkout_orig_branch: False
# List of formulas to enable in each environment # List of formulas to enable in each environment
list: list:
base: base:

+ 3
- 0
salt/defaults.yaml Переглянути файл

providers: salt://salt/files/cloud.providers.d providers: salt://salt/files/cloud.providers.d
profiles: salt://salt/files/cloud.profiles.d profiles: salt://salt/files/cloud.profiles.d
maps: salt://salt/files/cloud.maps.d maps: salt://salt/files/cloud.maps.d

salt_formulas:
checkout_orig_branch: False

+ 10
- 1
salt/formulas.jinja Переглянути файл

'baseurl': 'https://github.com/saltstack-formulas', 'baseurl': 'https://github.com/saltstack-formulas',
'basedir': '/srv/formulas', 'basedir': '/srv/formulas',
'update': False, 'update': False,
'options': {},
'options': {
'branch': 'master',
},
} }
%} %}
{% set formulas = salt['pillar.get']('salt_formulas:list', {}) %} {% set formulas = salt['pillar.get']('salt_formulas:list', {}) %}
{{ value|yaml }} {{ value|yaml }}
{%- endmacro -%} {%- endmacro -%}


{%- macro formulas_opts_for_git_latest(env) -%}
{%- set options = defaults['options'] or {} -%}
{%- do options.update(salt['pillar.get']('salt_formulas:git_opts:default:options') or {}) -%}
{%- do options.update(salt['pillar.get']('salt_formulas:git_opts:{0}:options'.format(env)) or {}) -%}
{{ options|yaml }}
{%- endmacro -%}

{%- macro formulas_roots(env) -%} {%- macro formulas_roots(env) -%}
{%- set value = [] -%} {%- set value = [] -%}
{%- for dir in formulas.get(env, []) -%} {%- for dir in formulas.get(env, []) -%}

+ 37
- 6
salt/formulas.sls Переглянути файл

{% set processed_gitdirs = [] %}
{% set processed_gitdirs = {} %}
{% set processed_gitdir_envs = [] %}
{% set processed_basedirs = [] %} {% set processed_basedirs = [] %}


{% from "salt/map.jinja" import formulas_settings with context %}
{% from "salt/formulas.jinja" import formulas_git_opt with context %} {% from "salt/formulas.jinja" import formulas_git_opt with context %}
{% from "salt/formulas.jinja" import formulas_opts_for_git_latest with context %}


# Loop over all formulas listed in pillar data # Loop over all formulas listed in pillar data
{% for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %} {% for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %}
{% set gitdir = '{0}/{1}'.format(basedir, entry) %} {% set gitdir = '{0}/{1}'.format(basedir, entry) %}
{% set update = formulas_git_opt(env, 'update')|load_yaml %} {% set update = formulas_git_opt(env, 'update')|load_yaml %}


{% if formulas_settings.checkout_orig_branch %}
{% if not salt['file.directory_exists']('{0}/{1}'.format(gitdir, '.git')) %}
{% set gitdir_branch = '' %}
{% else %}
{% set gitdir_branch = salt['git.current_branch'](gitdir) %}
{% endif %}
{% do processed_gitdirs.update({gitdir:gitdir_branch}) %}
{% endif %}

# Setup the directory hosting the Git repository # Setup the directory hosting the Git repository
{% if basedir not in processed_basedirs %} {% if basedir not in processed_basedirs %}
{% do processed_basedirs.append(basedir) %} {% do processed_basedirs.append(basedir) %}
{% endif %} {% endif %}


# Setup the formula Git repository # Setup the formula Git repository
{% if gitdir not in processed_gitdirs %}
{% do processed_gitdirs.append(gitdir) %}
{% set options = formulas_git_opt(env, 'options')|load_yaml %}
{% set gitdir_env = '{0}_{1}'.format(gitdir, env) %}
{% if gitdir_env not in processed_gitdir_envs %}
{% do processed_gitdir_envs.append(gitdir_env) %}
{% set options = formulas_opts_for_git_latest(env)|load_yaml %}
{% set baseurl = formulas_git_opt(env, 'baseurl')|load_yaml %} {% set baseurl = formulas_git_opt(env, 'baseurl')|load_yaml %}
{{ gitdir }}:

{{ gitdir_env }}:
git.latest: git.latest:
- name: {{ baseurl }}/{{ entry }}.git - name: {{ baseurl }}/{{ entry }}.git
- target: {{ gitdir }} - target: {{ gitdir }}
- unless: test -e {{ gitdir }} - unless: test -e {{ gitdir }}
{%- endif %} {%- endif %}
{% endif %} {% endif %}

{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

{% if formulas_settings.checkout_orig_branch %}
# For each directory processed, explicitly checkout the original branch before
# the `git.latest` state ran
{% for gitdir, original_branch in processed_gitdirs.items() %}
{% if original_branch %}
{% set gitdir_user = salt['file.get_user'](gitdir) %}
checkout_original_branch_for_{{ gitdir }}:
module.run:
- name: git.checkout
- order: last
- cwd: {{ gitdir }}
- rev: {{ original_branch }}
- user: {{ gitdir_user }}
- unless: test "$(cd {{ gitdir }}; git rev-parse --abbrev-ref HEAD)" = "{{ original_branch }}"
{% endif %}
{% endfor %}
{% endif %}

+ 8
- 1
salt/map.jinja Переглянути файл

{## Merge the flavor_map to the default settings ##} {## Merge the flavor_map to the default settings ##}
{% do deep_merge(default_settings.salt,os_family_map) %} {% do deep_merge(default_settings.salt,os_family_map) %}


{## Merge in salt:lookup pillar ##}
{## Merge in salt pillar ##}
{% set salt_settings = salt['pillar.get']( {% set salt_settings = salt['pillar.get'](
'salt', 'salt',
default=default_settings.salt, default=default_settings.salt,
merge=True) merge=True)
%} %}

{## Merge in salt_formulas pillar ##}
{% set formulas_settings = salt['pillar.get'](
'salt_formulas',
default=default_settings.salt_formulas,
merge=True)
%}

Завантаження…
Відмінити
Зберегти