Skip to content

Commit

Permalink
feat(swarm): fix containers; basic swarm module support
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Nov 12, 2020
1 parent 9a867fe commit b388931
Show file tree
Hide file tree
Showing 43 changed files with 491 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docker/compose/build.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/get.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/kill.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
22 changes: 22 additions & 0 deletions docker/compose/networks/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'networks' in d and d.networks %}
{%- set sls_archive = tplroot ~ '.software.archive.install' %}
{%- set sls_desktop = tplroot ~ '.software.desktop.install' %}
{%- set sls_package = tplroot ~ '.software.package.install' %}
include:
- {{ sls_archive if d.pkg.docker.use_upstream == 'archive' else sls_desktop if d.pkg.docker.use_upstream == 'desktop' else sls_package }}
{%- for name in docker.networks %}
{{ formula }}-network-{{ name }}-absent:
docker_network.absent:
- name: {{ name }}
{%- endfor %}
5 changes: 5 additions & 0 deletions docker/compose/networks/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
22 changes: 22 additions & 0 deletions docker/compose/networks/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'networks' in d and d.networks %}
{%- set sls_archive = tplroot ~ '.software.archive.install' %}
{%- set sls_desktop = tplroot ~ '.software.desktop.install' %}
{%- set sls_package = tplroot ~ '.software.package.install' %}
include:
- {{ sls_archive if d.pkg.docker.use_upstream == 'archive' else sls_desktop if d.pkg.docker.use_upstream == 'desktop' else sls_package }}
{%- for name in docker.networks %}
{{ formula }}-network-{{ name }}-present:
docker_network.present:
- name: {{ name }}
{%- endfor %}
16 changes: 16 additions & 0 deletions docker/compose/ng.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
include:
- {{ formula }}.compose.software
- {{ formula }}.compose.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:
{%- if 'deps' in d.pkg and d.pkg.deps %}
Expand All @@ -38,6 +40,8 @@ include:
- skip_translate: {{ d.misc.skip_translate }}
- force: {{ d.misc.force_running }}
- privileged: {{ container.privileged|default(False) }}
- interactive: {{ container.stdin_open|default(False) }}
- tty: {{ container.tty|default(False) }}
{%- if 'command' in container %}
- command: {{ container.command }}
{%- endif %}
Expand Down Expand Up @@ -102,6 +106,13 @@ include:
{{ name }}: {{ alias }}
{%- endfor %}
{%- endif %}
{%- if 'networks' in container %}
- networks:
{%- for network in container.networks %}
{%- do required_networks.append(network) %}
- {{ network }}
{%- endfor %}
{%- endif %}
{%- if 'restart' in container %}
{%- set policy = container.restart.split(':',1) %}
{%- if policy|length < 2 %}
Expand All @@ -117,5 +128,10 @@ include:
- docker_image: {{ formula }}-compose-ng-{{ id }}-present
{%- endfor %}
{%- endif %}
{%- if required_networks is defined %}
{%- for networkid in required_networks %}
- docker_network: {{ networkid }}
{%- endfor %}
{%- endif %}
{% endfor %}
4 changes: 2 additions & 2 deletions docker/compose/pause.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/ps.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/pull.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/restart.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/rm.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/service_create.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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'] %}
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/service_remove.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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'] %}
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/service_set_tag.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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'] %}
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/service_upsert.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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'] %}
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/start.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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 }}-start:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/stop.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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 }}-stop:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/unpause.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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 }}-unpause:
Expand Down
4 changes: 2 additions & 2 deletions docker/compose/up.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.compose and d.compose.wanted %}
{%- for service in d.compose.wanted|unique %}
{%- 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 }}-up:
Expand Down
11 changes: 9 additions & 2 deletions docker/containers/absent.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
{%- set formula = d.formula %}
{%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %}
{%- if 'wanted' in d.containers and d.containers.wanted %}
{%- if 'running' in d.containers and d.containers.running %}
{%- set sls_stopped = tplroot ~ '.containers.stopped' %}
include:
- {{ sls_stopped }}
{{ formula }}-containers-absent:
docker_container.absent:
- names: {{ d.containers.wanted|unique|json }}
- names: {{ d.containers.running|unique|json }}
- require:
- sls: {{ sls_stopped }}
{%- endif %}
4 changes: 2 additions & 2 deletions docker/containers/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{%- set formula = d.formula %}
{%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %}
{%- if 'wanted' in d.containers and d.containers.wanted %}
{%- for c in d.containers.wanted|unique %}
{%- if 'running' in d.containers and d.containers.running %}
{%- for c in d.containers.running|unique %}
{%- if c in d.containers and d.containers[c] %}
{{ formula }}-containers-{{ c }}-running:
Expand Down
9 changes: 6 additions & 3 deletions docker/containers/stopped.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.containers and d.containers.wanted %}
{%- if 'running' in d.containers and d.containers.running %}
{%- for c in d.containers.running|unique %}
{{ formula }}-containers-stopped:
{{ formula }}-containers-{{ c }}-stopped:
docker_container.stopped:
- containers: {{ d.containers.wanted|unique|json }}
- name: {{ c }}
- onlyif: docker container inspect {{ c }}
{%- endfor %}
{%- endif %}
27 changes: 20 additions & 7 deletions docker/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ docker:
supported:
- docker
- compose
- swarm
wanted:
comp:
- docker
- compose
firewall: false
- docker
- compose

pkg:
version: 'latest' # linux native package version
Expand Down Expand Up @@ -77,11 +76,23 @@ docker:
source: 'https://dl.bintray.com/docker-compose/master/docker-compose-Linux-x86_64'
source_hash: '3c96b57ea8e0027aee7e1a3023f7599bcecae54e77bcfd5f4e65a59672637e54'

networks: {}
containers:
wanted: {}
running: []
compose:
wanted: {}
applications: []
ng: {}
swarm:
joinswarm: {}
leave_swarm: false
node_ls: {}
remove_node: {}
remove_service: {}
service_create: {}
swarm_init: {}
service_info: {}
swarm_tokens: true
update_node: {}

dir:
base: /usr/local
Expand All @@ -97,12 +108,14 @@ docker:
arch: ''

misc:
skip_translate: None
force_absent: false
force_present: false
force_running: false
skip_translate: None
clean: false
reload: true
refresh: true
firewall: false
hold: false

retry_option:
Expand Down
2 changes: 2 additions & 0 deletions docker/files/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# Collection of common macros

{%- macro format_kwargs(kwarg) -%}
{%- if kwarg and kwarg is mapping %}

{%- filter indent(4) %}
{%- for k, v in kwarg|dictsort() %}
- {{ k }}: {{ v }}
{%- endfor %}
{%- endfilter %}

{%- endif %}
{%- endmacro %}
Loading

0 comments on commit b388931

Please sign in to comment.