Skip to content

Commit

Permalink
Periodic image garbage collection (#129)
Browse files Browse the repository at this point in the history
* Add periodic image garbage collection
  • Loading branch information
sgalsaleh authored Feb 5, 2024
1 parent 7624fbf commit 3b6e259
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
37 changes: 35 additions & 2 deletions kustomize/overlays/dev/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ spec:
containers:
- name: ttl-registry
image: registry:2
command: ["/entrypoint.sh"]
ports:
- containerPort: 5000
volumeMounts:
- name: registry-data
mountPath: /var/lib/registry
- name: registry-scripts
mountPath: /entrypoint.sh
subPath: entrypoint.sh
- name: registry-scripts
mountPath: /garbage-collect.sh
subPath: garbage-collect.sh
- name: registry-config
mountPath: /etc/docker/registry/config.yml
subPath: config.yml
Expand All @@ -40,12 +47,38 @@ spec:
emptyDir: {}
- name: registry-config
configMap:
name: registry-config
name: ttl-registry-config
- name: registry-scripts
configMap:
name: ttl-registry-scripts
defaultMode: 0755
---
apiVersion: v1
kind: ConfigMap
metadata:
name: ttl-registry-scripts
labels:
app: ttl-registry
data:
entrypoint.sh: |
#!/bin/sh
set -e
echo "0 * * * * /garbage-collect.sh >> /proc/1/fd/1 2>&1" > /etc/crontabs/root
crond
registry serve /etc/docker/registry/config.yml
garbage-collect.sh: |
#!/bin/sh
set -e
if [ ! -d "/var/lib/registry/docker" ]; then
echo "No registry data found, skipping garbage collection"
exit 0
fi
registry garbage-collect /etc/docker/registry/config.yml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: registry-config
name: ttl-registry-config
labels:
app: ttl-registry
data:
Expand Down
5 changes: 3 additions & 2 deletions registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM registry:2.7.1

ADD ./entrypoint.sh /heroku-entrypoint.sh
ADD ./entrypoint.sh /entrypoint.sh
ADD ./config.yml /etc/docker/registry/config.yml
ADD ./garbage-collect.sh /garbage-collect.sh

ENTRYPOINT ["/heroku-entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/etc/docker/registry/config.yml"]
4 changes: 4 additions & 0 deletions registry/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ else
chmod 0400 /etc/gcs.json
fi

# Run garbage collection job in background
echo "0 * * * * /garbage-collect.sh >> /proc/1/fd/1 2>&1" > /etc/crontabs/root
crond

case "$1" in
*.yaml|*.yml) set -- registry serve "$@" ;;
serve|garbage-collect|help|-*) set -- registry "$@" ;;
Expand Down
5 changes: 5 additions & 0 deletions registry/garbage-collect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

echo "Starting garbage collection..."

registry garbage-collect /etc/docker/registry/config.yml

0 comments on commit 3b6e259

Please sign in to comment.