Skip to content

Commit

Permalink
fix(compose-ng): fix ports, volumes, restart policy, add privileged mode
Browse files Browse the repository at this point in the history
  • Loading branch information
japtain-cack committed Apr 7, 2020
1 parent c3c4eb8 commit f62a45c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions docker/compose-ng.sls
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include:
docker_container.running:
- skip_translate: {{ docker.containers.skip_translate }}
- force: {{ docker.containers.force_running }}
- privileged: {{ container.privileged|default(False) }}
{%- else %}
{%- if 'dvc' in container and container.dvc %}
docker.installed:
Expand All @@ -49,26 +50,31 @@ include:
{%- endfor %}
{%- endif %}
{%- if 'ports' in container and container.ports is iterable %}
- ports:
- port_bindings:
{%- for port_mapping in container.ports %}
{%- if port_mapping is string %}
{%- set mapping = port_mapping.split(':',2) %}
{%- if mapping|length < 2 %}
- "{{ mapping[0] }}"
{%- elif mapping|length > 2 %}
- "{{ mapping[0] }}:{{ mapping[1] }}:{{ mapping[-1] }}
{%- else %}
- "{{ mapping[-1] }}/tcp":
HostPort: "{{ mapping[-2] }}"
HostIp: "{{ mapping[-3]|d('') }}"
- "{{ mapping[0] }}:{{ mapping[-1] }}"
{%- endif %}
{%- elif port_mapping is mapping %}
- {{ port_mapping }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'volumes' in container %}
- volumes:
{%- for volume in container.volumes %}
- {{ volume }}
- binds:
{%- for bind in container.volumes %}
{%- set mapping = bind.rsplit(':', 1) %}
{%- if mapping|length > 1 %}
- "{{ mapping[0] }}:{{ mapping[-1] }}"
{%- else %}
- "{{ mapping[0] }}"
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'volumes_from' in container %}
Expand All @@ -87,11 +93,11 @@ include:
{%- endfor %}
{%- endif %}
{%- if 'restart' in container %}
- restart_policy:
{%- set policy = container.restart.split(':',1) %}
Name: {{ policy[0] }}
{%- if policy|length > 1 %}
MaximumRetryCount: {{ policy[1] }}
{%- if policy|length < 2 %}
- restart_policy: {{ policy[0] }}
{%- else %}
- restart_policy: {{ policy[0] }}:{{ policy[-1] }}
{%- endif %}
{%- endif %}
- require:
Expand Down

0 comments on commit f62a45c

Please sign in to comment.