From d54701e60da4f9cac6803eef43f8bdda00abcfa3 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Mon, 20 Sep 2021 20:24:12 +0300
Subject: [PATCH] Periodic garbage collection.

- Add a crond image.
- Add a weekly Cron job to run garbage collection.
---
 crond/.dockerignore |  2 ++
 crond/Dockerfile    |  6 ++++++
 crond/README.md     | 20 ++++++++++++++++++++
 crond/crontab       |  1 +
 docker-compose.yml  |  8 ++++++++
 5 files changed, 37 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..3d39d79
--- /dev/null
+++ b/crond/Dockerfile
@@ -0,0 +1,6 @@
+# hadolint ignore=DL3006
+FROM registry.shore.co.il/cron as supersonic
+# hadolint ignore=DL3002
+USER root
+# hadolint ignore=DL3018
+RUN apk add --update --no-cache docker-cli
diff --git a/crond/README.md b/crond/README.md
new file mode 100644
index 0000000..7a0e895
--- /dev/null
+++ b/crond/README.md
@@ -0,0 +1,20 @@
+# crond
+
+> Cron container image.
+
+## Description
+
+Periodically run the registry's garbage collection. It should be improved to
+first put the registry in a read-only mode or disable the Nginx proxy or
+something.
+
+## 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://git.shore.co.il/explore/>.
diff --git a/crond/crontab b/crond/crontab
new file mode 100644
index 0000000..de221d8
--- /dev/null
+++ b/crond/crontab
@@ -0,0 +1 @@
+@weekly docker exec registry_registry_1 registry garbage-collect /etc/docker/registry/config.yml
diff --git a/docker-compose.yml b/docker-compose.yml
index 60463f0..df05d1a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,6 +16,7 @@ services:
     restart: always
     volumes:
       - "registry:/var/lib/registry"
+
   reg:
     command:
       - "server"
@@ -34,6 +35,13 @@ services:
     image: r.j3ss.co/reg:v0.16.1
     restart: always
 
+  crond:
+    build:
+      context: crond/
+    restart: always
+    volumes:
+      - /run/docker.sock:/run/docker.sock
+
 volumes:
   registry:
 
-- 
GitLab