From 2f63c9d2f760a0133226c1a15f960fb78c6ea5dc Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sat, 21 Sep 2019 19:54:29 +0300
Subject: [PATCH] Add Cron container for backing up the slapd data.

---
 crond/.dockerignore |  2 ++
 crond/Dockerfile    |  8 ++++++++
 crond/README.md     | 21 +++++++++++++++++++++
 crond/crontab       |  1 +
 docker-compose.yml  |  6 ++++++
 5 files changed, 38 insertions(+)
 create mode 100644 crond/.dockerignore
 create mode 100644 crond/Dockerfile
 create mode 100644 crond/README.md
 create mode 100644 crond/crontab

diff --git a/crond/.dockerignore b/crond/.dockerignore
new file mode 100644
index 0000000..780ece0
--- /dev/null
+++ b/crond/.dockerignore
@@ -0,0 +1,2 @@
+*
+!crontab
diff --git a/crond/Dockerfile b/crond/Dockerfile
new file mode 100644
index 0000000..994fbce
--- /dev/null
+++ b/crond/Dockerfile
@@ -0,0 +1,8 @@
+FROM docker:19.03 as docker
+
+# hadolint ignore=DL3006
+FROM adarnimrod/cron as supersonic
+COPY --from=docker /usr/local/bin/docker /usr/local/bin/
+COPY --chown=root:root crontab /crontab
+# hadolint ignore=DL3002
+USER root
diff --git a/crond/README.md b/crond/README.md
new file mode 100644
index 0000000..4076d73
--- /dev/null
+++ b/crond/README.md
@@ -0,0 +1,21 @@
+# crond
+
+> Cron container image.
+
+## Description
+
+This container periodically runs the slapd backup script. The script runs in the
+slapd container so the `dockerd` socket is bind mounted to this container and
+the commands are executed via `docker exec` in the other containers. Thus,
+outside of the context of this setup this container doesn't make much sense.
+
+## License
+
+This software is licensed under the MIT license (see `LICENSE.txt`).
+
+## Author Information
+
+Nimrod Adar, [contact me](mailto:nimrod@shore.co.il) or visit my [website](
+https://www.shore.co.il/). Patches are welcome via [`git send-email`](
+http://git-scm.com/book/en/v2/Git-Commands-Email). The repository is located
+at: <https://www.shore.co.il/git/>.
diff --git a/crond/crontab b/crond/crontab
new file mode 100644
index 0000000..0534b16
--- /dev/null
+++ b/crond/crontab
@@ -0,0 +1 @@
+@daily docker exec ldap_ldap_1 backup
diff --git a/docker-compose.yml b/docker-compose.yml
index c7b4351..5aab814 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,6 +2,12 @@
 ---
 version: '3.5'
 services:
+  crond:
+    build:
+      context: crond/
+    volumes:
+      - /run/docker.sock:/run/docker.sock
+
   ldap:
     build:
       cache_from:
-- 
GitLab