From 61ec487e24dde02e1a1c6a93bf7e230e7638fba3 Mon Sep 17 00:00:00 2001
From: Einar Forselv <eforselv@gmail.com>
Date: Sat, 7 Mar 2020 02:55:22 +0100
Subject: [PATCH] Support SWARM_MODE

---
 docs/guide/configuration.rst        | 5 +++++
 restic_compose_backup.env           | 2 ++
 src/restic_compose_backup/config.py | 4 ++++
 3 files changed, 11 insertions(+)

diff --git a/docs/guide/configuration.rst b/docs/guide/configuration.rst
index cde5cbe..bdc3695 100644
--- a/docs/guide/configuration.rst
+++ b/docs/guide/configuration.rst
@@ -188,6 +188,11 @@ connecting to the Docker host. Combined with ``DOCKER_TLS_VERIFY``
 this can be used to talk to docker through TLS in cases
 were we cannot map in the docker socket.
 
+SWARM_MODE
+~~~~~~~~~~
+
+If defined containers in swarm stacks are also evaluated.
+
 Compose Labels
 --------------
 
diff --git a/restic_compose_backup.env b/restic_compose_backup.env
index 080761a..bd474f9 100644
--- a/restic_compose_backup.env
+++ b/restic_compose_backup.env
@@ -4,6 +4,8 @@
 # DOCKER_TLS_VERIFY=1
 # DOCKER_CERT_PATH=''
 
+SWARM_MODE=true
+
 RESTIC_REPOSITORY=/restic_data
 RESTIC_PASSWORD=password
 
diff --git a/src/restic_compose_backup/config.py b/src/restic_compose_backup/config.py
index 1795f5c..e5c5693 100644
--- a/src/restic_compose_backup/config.py
+++ b/src/restic_compose_backup/config.py
@@ -12,6 +12,7 @@ class Config:
         self.password = os.environ.get('RESTIC_REPOSITORY')
         self.cron_schedule = os.environ.get('CRON_SCHEDULE') or self.default_crontab_schedule
         self.cron_command = os.environ.get('CRON_COMMAND') or self.default_backup_command
+        self.swarm_mode = os.environ.get('SWARM_MODE') or False
 
         # Log
         self.log_level = os.environ.get('LOG_LEVEL')
@@ -31,3 +32,6 @@ class Config:
 
         if not self.password:
             raise ValueError("RESTIC_REPOSITORY env var not set")
+
+
+config = Config()