Skip to content

Commit

Permalink
feat(compose-ng): added networks keyword support
Browse files Browse the repository at this point in the history
  • Loading branch information
olipinski committed Aug 27, 2020
1 parent 9b8b16e commit e7a92c4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
22 changes: 21 additions & 1 deletion docker/compose-ng.sls
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import docker with context %}
{%- from tplroot ~ "/map.jinja" import compose with context %}
{%- from tplroot ~ "/map.jinja" import networks with context %}
include:
- docker.compose
{%- for networkname in networks %}
{{ networkname }} network:
docker_network.present:
- name: {{ networkname }}
{%- endfor %}
{%- for name, container in compose.items() %}
{%- set id = container.container_name|d(name) %}
{%- set required_containers = [] %}
{%- set required_networks = [] %}
{%- if grains['saltversioninfo'] >= [2017, 7, 0] %}
{{ id }}:
docker_image.present:
Expand Down Expand Up @@ -104,6 +112,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 @@ -127,4 +142,9 @@ include:
{%- endif %}
{%- endfor %}
{%- endif %}
{% endfor %}
{%- if required_networks is defined %}
{%- for networkid in required_networks %}
- docker_network: {{ networkid }}
{%- endfor %}
{%- endif %}
{%- endfor %}
2 changes: 2 additions & 0 deletions docker/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@
{% set docker = salt['pillar.get']('docker', default=defaults['docker'], merge=True) %}

{% set compose = salt['pillar.get']('docker:compose', default={}, merge=True) %}

{% set networks = salt['pillar.get']('docker:networks', default={}, merge=True) %}
12 changes: 10 additions & 2 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ docker:
# insecure-registries:
# - harbor.local

networks:
- nginxnet

pkg:
# Package handling
# version: 1.13.1
Expand Down Expand Up @@ -110,6 +113,8 @@ docker:
registry-service:
image: *registry_image
container_name: 'registry-service'
networks:
- nginxnet
volumes_from:
- *dvc
environment:
Expand All @@ -131,8 +136,11 @@ docker:
# image: 'docker.io/nginx:latest' ##Fedora
image: 'nginx:latest'
container_name: 'nginx-latest'
links:
- 'registry-service:registry'
#links:
# - 'registry-service:registry'
# Legacy feature
networks:
- nginxnet
ports:
- '80:80'
- '443:443'
Expand Down

0 comments on commit e7a92c4

Please sign in to comment.