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 cb8f2ac
Show file tree
Hide file tree
Showing 38 changed files with 413 additions and 125 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
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 inspect {{ c }}
{%- endfor %}
{%- endif %}
26 changes: 19 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 @@ -78,10 +77,21 @@ docker:
source_hash: '3c96b57ea8e0027aee7e1a3023f7599bcecae54e77bcfd5f4e65a59672637e54'

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 +107,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
20 changes: 0 additions & 20 deletions docker/files/service_file.jinja

This file was deleted.

4 changes: 2 additions & 2 deletions docker/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
%}
{%- set d = salt['grains.filter_by']( {'defaults': defaults}, default='defaults', merge=_config) %}

{%- if 'wanted' in d and d.wanted and 'comp' in d.wanted and d.wanted.comp and 'supported' in d and d.supported %}
{%- for c in d.wanted.comp %}
{%- if 'wanted' in d and d.wanted and 'supported' in d and d.supported %}
{%- for c in d.wanted %}

{%- if c in d.supported %}
{%- set path = d.dir.base %}
Expand Down
4 changes: 2 additions & 2 deletions docker/software/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include:
- require:
- sls: {{ sls_config_file }}
{%- endif %}
{%- if d.wanted.firewall %}
{%- if d.misc.firewall %}
pkg.installed:
- name: firewalld
- reload_modules: true
Expand Down Expand Up @@ -62,7 +62,7 @@ include:
- onfail:
- service: {{ formula }}-software-service-running-docker
{%- if d.wanted.firewall and d.pkg.docker.firewall.ports %}
{%- if d.misc.firewall and d.pkg.docker.firewall.ports %}
{{ formula }}-software-service-running-docker:
service.running:
Expand Down
5 changes: 5 additions & 0 deletions docker/swarm/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .leaveswarm
16 changes: 16 additions & 0 deletions docker/swarm/create_service.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- 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 'service_create' in d.swarm and d.swarm.service_create is mapping %}
{%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %}
{{ formula }}-swarm-service_create:
module.run:
- name: swarm.service_create
{{- format_kwargs(d.swarm.service_create|unique) }}
{%- endif %}
5 changes: 5 additions & 0 deletions docker/swarm/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .joinswarm
16 changes: 16 additions & 0 deletions docker/swarm/joinswarm.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- 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 'joinswarm' in d.swarm and d.swarm.joinswarm is mapping %}
{%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %}
{{ formula }}-swarm-joinswarm:
module.run:
- name: swarm.joinswarm
{{- format_kwargs(d.swarm.joinswarm|unique) }}
{%- endif %}
15 changes: 15 additions & 0 deletions docker/swarm/leaveswarm.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- 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 'leave_swarm' in d.swarm and d.swarm.leave_swarm %}
{{ formula }}-swarm-leave_swarm:
module.run:
- name: swarm.leave_swarm
- force: true
{%- endif %}
Loading

0 comments on commit cb8f2ac

Please sign in to comment.