Skip to content

Commit

Permalink
refactor(jinja2): remove excessive jinja, not useful pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Aug 24, 2021
1 parent 4a9579f commit b1c07a7
Show file tree
Hide file tree
Showing 54 changed files with 126 additions and 180 deletions.
3 changes: 1 addition & 2 deletions docker/compose/build.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-build:
docker-compose-{{ service }}-build:
module.run:
- name: dockercompose.build
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/get.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-get:
docker-compose-{{ service }}-get:
module.run:
- name: dockercompose.get
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/kill.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-kill:
docker-compose-{{ service }}-kill:
module.run:
- name: dockercompose.kill
- path: {{ d.compose[service]['path'] }}
Expand Down
15 changes: 7 additions & 8 deletions docker/compose/ng.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
include:
- {{ formula }}.compose.software
- {{ formula }}.networks
- docker.compose.software
- docker.networks
{%- for name, container in d.compose.ng.items() %}
{%- set id = container.container_name|d(name) %}
{%- set required_containers = [] %}
{%- set required_networks = [] %}
{{ formula }}-compose-ng-{{ id }}-present:
docker-compose-ng-{{ id }}-present:
docker_image.present:
- force: {{ d.misc.force_present }}
{%- if ':' in container.image %}
Expand All @@ -26,7 +25,7 @@ include:
- name: {{ container.image }}
{%- endif %}
{{ formula }}-compose-ng-{{ id }}-running:
docker-compose-ng-{{ id }}-running:
docker_container.running:
- name: {{ id }}
- image: {{ container.image }}
Expand Down Expand Up @@ -126,15 +125,15 @@ include:
{%- endfor %}
{%- endif %}
- require:
- docker_image: {{ formula }}-compose-ng-{{ id }}-present
- docker_image: docker-compose-ng-{{ id }}-present
{%- if required_containers is defined %}
{%- for containerid in required_containers %}
- docker_image: {{ formula }}-compose-ng-{{ id }}-present
- docker_image: docker-compose-ng-{{ id }}-present
{%- endfor %}
{%- endif %}
{%- if required_networks is defined %}
{%- for networkid in required_networks %}
- docker_network: {{ formula }}-network-{{ networkid }}-present
- docker_network: docker-network-{{ networkid }}-present
{%- endfor %}
{%- endif %}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/pause.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-pause:
docker-compose-{{ service }}-pause:
module.run:
- name: dockercompose.pause
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/ps.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-ps:
docker-compose-{{ service }}-ps:
module.run:
- name: dockercompose.ps
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/pull.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-pull:
docker-compose-{{ service }}-pull:
module.run:
- name: dockercompose.pull
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/restart.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-restart:
docker-compose-{{ service }}-restart:
module.run:
- name: dockercompose.restart
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/rm.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{{ formula }}-compose-{{ service }}-rm:
docker-compose-{{ service }}-rm:
module.run:
- name: dockercompose.rm
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/service_create.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{%- if 'service_name' in d.compose[service] and d.compose[service]['service_name'] %}
{%- if 'definition' in d.compose[service] and d.compose[service]['definition'] %}
{{ formula }}-compose-{{ service }}-service_create:
docker-compose-{{ service }}-service_create:
module.run:
- name: dockercompose.service_create
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/service_remove.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{%- if 'service_name' in d.compose[service] and d.compose[service]['service_name'] %}
{{ formula }}-compose-{{ service }}-service_remove:
docker-compose-{{ service }}-service_remove:
module.run:
- name: dockercompose.service_remove
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/service_set_tag.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{%- if 'service_name' in d.compose[service] and d.compose[service]['service_name'] %}
{%- if 'tag' in d.compose[service] and d.compose[service]['tag'] %}
{{ formula }}-compose-{{ service }}-service_set_tag-{{ d.compose[service]['tag'] }}:
docker-compose-{{ service }}-service_set_tag-{{ d.compose[service]['tag'] }}:
module.run:
- name: dockercompose.service_set_tag
- path: {{ d.compose[service]['path'] }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/service_upsert.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'applications' in d.compose and d.compose.applications %}
{%- for service in d.compose.applications|unique %}
{%- if 'path' in d.compose[service] and d.compose[service]['path'] %}
{%- if 'service_name' in d.compose[service] and d.compose[service]['service_name'] %}
{%- if 'definition' in d.compose[service] and d.compose[service]['definition'] %}
{{ formula }}-compose-{{ service }}-service_upsert:
docker-compose-{{ service }}-service_upsert:
module.run:
- name: dockercompose.service_upsert
- path: {{ d.compose[service]['path'] }}
Expand Down
7 changes: 3 additions & 4 deletions docker/compose/software/alternatives/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if d.linux.altpriority|int > 0 and grains.kernel == 'Linux' and grains.os_family not in ('Arch',) %}
{%- for cmd in d.pkg.compose.commands|unique %}
{{ formula }}-docker-compose-alternatives-clean-{{ cmd }}:
docker-compose-alternatives-clean-{{ cmd }}:
alternatives.remove:
- name: link-docker-docker-compose-{{ cmd }}
- name: link-docker-compose-{{ cmd }}
- path: {{ d.pkg.compose.path }}/bin/{{ cmd }}
- onlyif: update-alternatives --list |grep ^link-docker-docker-compose-{{ cmd }}
- onlyif: update-alternatives --list |grep ^link-docker-compose-{{ cmd }}
{%- endfor %}
{%- endif %}
7 changes: 3 additions & 4 deletions docker/compose/software/alternatives/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if d.linux.altpriority|int > 0 and grains.kernel == 'Linux' and grains.os_family not in ('Arch',) %}
{%- set sls_binary_install = tplroot ~ '.compose.software.binary.install' %}
Expand All @@ -12,7 +11,7 @@ include:
- {{ sls_binary_install }}
{%- for cmd in d.pkg.compose.commands|unique %}
{{ formula }}-docker-compose-alternatives-install-bin-{{ cmd }}:
docker-compose-alternatives-install-bin-{{ cmd }}:
{%- if grains.os_family not in ('Suse', 'Arch') %}
alternatives.install:
- name: link-docker-compose-{{ cmd }}
Expand All @@ -31,9 +30,9 @@ include:
- require:
- sls: {{ sls_binary_install }}
- require_in:
- alternatives: {{ formula }}-docker-compose-alternatives-set-bin-{{ cmd }}
- alternatives: docker-compose-alternatives-set-bin-{{ cmd }}
{{ formula }}-docker-compose-alternatives-set-bin-{{ cmd }}:
docker-compose-alternatives-set-bin-{{ cmd }}:
alternatives.set:
- unless: {{ grains.os_family in ('Suse', 'Arch') }} || false
- name: link-docker-compose-{{ cmd }}
Expand Down
3 changes: 1 addition & 2 deletions docker/compose/software/binary/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if grains.kernel|lower in ('linux',) %}
{%- set sls_alternatives_clean = tplroot ~ '.software.alternatives.clean' %}
include:
- {{ sls_alternatives_clean }}
{{ formula }}-docker-compose-archive-absent:
docker-compose-archive-absent:
file.absent:
- names:
- {{ d.dir.tmp }}/docker-compose
Expand Down
15 changes: 7 additions & 8 deletions docker/compose/software/binary/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if grains.kernel|lower in ('linux',) %}
{%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %}
{%- if d.pkg.compose.use_upstream == 'binary' and 'binary' in d.pkg.compose %}
{{ formula }}-compose-software-binary-install:
docker-compose-software-binary-install:
{%- if 'deps' in d.pkg and d.pkg.deps %}
{%- if grains.os|lower in ('centos', 'redhat') %}
# python-docker package is not available or too old on CentOS, RedHat
Expand All @@ -18,13 +17,13 @@
- name: docker
- reload_modules: {{ d.misc.reload or true }}
- require:
- pkg: {{ formula }}-compose-software-binary-install
- pkg: docker-compose-software-binary-install
{%- endif %}
pkg.installed:
- names: {{ d.pkg.deps|json }}
- reload_modules: {{ d.misc.reload or true }}
- require_in:
- file: {{ formula }}-compose-software-binary-install
- file: docker-compose-software-binary-install
{%- endif %}
file.managed:
- unless: test -x {{ d.pkg.compose.path }}/docker-compose
Expand All @@ -49,22 +48,22 @@
{%- if d.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS') %}
{%- for cmd in d.pkg.compose.commands|unique %}
{{ formula }}-compose-software-binary-install-symlink-{{ cmd }}:
docker-compose-software-binary-install-symlink-{{ cmd }}:
file.symlink:
- name: /usr/local/bin/{{ cmd }}
- target: {{ d.pkg.compose.path }}/{{ cmd }}
- force: True
- onchanges:
- file: {{ formula }}-compose-software-binary-install
- file: docker-compose-software-binary-install
- require:
- file: {{ formula }}-compose-software-binary-install
- file: docker-compose-software-binary-install
{%- endfor %}
{%- endif %}
{%- endif %}
{%- else %}
{{ formula }}-compose-software-binary-install-other:
docker-compose-software-binary-install-other:
test.show_notification:
- text: |
The docker-compose binary is unavailable/unselected for {{ salt['grains.get']('finger', grains.os_family) }}
Expand Down
5 changes: 2 additions & 3 deletions docker/compose/software/package/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if d.pkg.compose.use_upstream in ('package', 'repo') %}
{%- if grains.os_family|lower in ('redhat', 'debian') %}
Expand All @@ -12,13 +11,13 @@ include:
- {{ sls_repo_clean }}
{%- endif %}
{{ formula }}-docker-compose-package-clean-pkgs:
docker-compose-package-clean-pkgs:
pkg.removed:
- name: {{ d.pkg.compose.name }}
- reload_modules: true
{%- if grains.os_family|lower in ('redhat', 'debian') %}
- require:
- pkgrepo: {{ formula }}-software-package-repo-absent
- pkgrepo: docker-software-package-repo-absent
{%- endif %}
{%- endif %}
Loading

0 comments on commit b1c07a7

Please sign in to comment.