expose additional container and compose functionality, allow setting the mine function (#14)
* extend container and compose functionality, make compose file idiomatic, allow setting mine function
* "network" backward compatibility
* conformed to naming convention and changed file mode
* fixed Jinja so that docker.swarm can render even if swarm master ip is not available from the mine
* renamed grain_function to mine_function for more accurate description
diff --git a/docker/client/compose.sls b/docker/client/compose.sls
index 5347586..11c0fdd 100644
--- a/docker/client/compose.sls
+++ b/docker/client/compose.sls
@@ -58,6 +58,7 @@
- template: jinja
- defaults:
compose: {{ compose }}
+ volume: {{ compose.volume|default({}) }}
service: {{ compose.service }}
network: {{ compose.network|default({}) }}
- require:
diff --git a/docker/client/container.sls b/docker/client/container.sls
index e46b218..322f616 100644
--- a/docker/client/container.sls
+++ b/docker/client/container.sls
@@ -1,4 +1,5 @@
{% from "docker/map.jinja" import client with context %}
+{% from "docker/map.jinja" import blacklist with context %}
include:
- docker.client
@@ -30,7 +31,7 @@
{%- do volumes.update({volume:volume}) %}
{%- endif %}
-{%- if path.startswith('/') %}
+{%- if path.startswith('/') and container.makedirs|default(True) %}
{{ id }}_volume_{{ path }}:
file.directory:
- name: {{ path }}
@@ -100,5 +101,10 @@
- dockerng: {{containerid}}
{%- endfor %}
{%- endif %}
+ {%- for key, value in container.iteritems() %}
+ {%- if key not in blacklist.dockerng_running %}
+ - {{ key }}: {{ value }}
+ {%- endif %}
+ {%- endfor %}
{% endfor %}
diff --git a/docker/client/stack.sls b/docker/client/stack.sls
index 626b310..8533f9a 100644
--- a/docker/client/stack.sls
+++ b/docker/client/stack.sls
@@ -18,6 +18,7 @@
- template: jinja
- defaults:
compose: {{ compose }}
+ volume: {{ compose.volume|default({}) }}
service: {{ compose.service }}
network: {{ compose.network|default({}) }}
- require:
diff --git a/docker/files/docker-compose.yml b/docker/files/docker-compose.yml
index 6e03b18..fbe8b74 100644
--- a/docker/files/docker-compose.yml
+++ b/docker/files/docker-compose.yml
@@ -1,24 +1,38 @@
version: '3'
+
services:
{%- for name, srv in service.iteritems() %}
{%- set env_file_set = False %}
{{ name }}:
- {%- for key, value in srv.iteritems() %}
- {%- if key == 'env_file' %}{%- set env_file_set = True %}{%- endif %}
- {{ key }}: {{ value }}
- {%- endfor %}
+ {%- if 'env_file' in srv.keys() %}{%- set env_file_set = True %}{%- endif %}
+ {{ srv|yaml(False)|indent(4) }}
{%- if not env_file_set and compose.environment is defined %}
env_file: .env
{%- endif %}
{%- endfor %}
+{%- if volume|default({}) %}
+volumes:
+{%- for key, value in volume.iteritems() %}
+ {%- if value is mapping %}
+ {{ key }}:
+ {{ value|yaml(False)|indent(4) }}
+ {%- else %}
+ {{ key }}:
+ {%- endif %}
+{%- endfor %}
+{%- endif %}
+
+
{%- if network|default({}) %}
networks:
-{%- for name, net in network.iteritems() %}
- {{ name }}:
- {%- for key, value in net.iteritems() %}
- {{ key }}: {{ value }}
- {%- endfor %}
+{%- for key, value in network.iteritems() %}
+ {%- if value is mapping %}
+ {{ key }}:
+ {{ value|yaml(False)|indent(4) }}
+ {%- else %}
+ {{ key }}:
+ {%- endif %}
{%- endfor %}
{%- endif %}
diff --git a/docker/map.jinja b/docker/map.jinja
index 8644de5..d70b4b0 100644
--- a/docker/map.jinja
+++ b/docker/map.jinja
@@ -22,7 +22,8 @@
'default': {
'master': {
'port': 2377
- }
+ },
+ 'mine_function': 'grains.items'
}
}, grain='os', merge=salt['pillar.get']('docker:swarm')) %}
@@ -56,3 +57,21 @@
},
},
}, grain='os', merge=salt['pillar.get']('docker:registry')) %}
+
+{%- load_yaml as blacklist %}
+dockerng_running:
+ - name
+ - start
+ - user
+ - image
+ - onlyif
+ - makedirs
+ - command
+ - environment
+ - ports
+ - volumes
+ - binds
+ - volumes_from
+ - links
+ - restart
+{%- endload %}
diff --git a/docker/swarm.sls b/docker/swarm.sls
index aa191ed..7992697 100644
--- a/docker/swarm.sls
+++ b/docker/swarm.sls
@@ -52,8 +52,8 @@
{%- else %}
-{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
-{%- if node_grains.get("docker_swarm_AdvertiseAddr", None) == swarm.master.host+":"+swarm.master.port|string %}
+{%- for node_name, node_grains in salt['mine.get']('*', swarm.mine_function).iteritems() %}
+{%- if node_grains.get("docker_swarm_AdvertiseAddr", None) == swarm.master.host|string+":"+swarm.master.port|string %}
{%- set join_token = node_grains.get('docker_swarm_tokens').get(swarm.role, "unknown") %}
docker_swarm_join: