first commit

This commit is contained in:
Piotr Domański 2026-04-03 20:51:34 +02:00
commit 256e9b9fc6
6 changed files with 84 additions and 0 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
!entrypoint.sh

24
Dockerfile Normal file
View file

@ -0,0 +1,24 @@
ARG ALPINE_VERSION=3.21
FROM alpine:${ALPINE_VERSION}
ARG SUPERCRONIC_VERSION=0.2.33
# TARGETARCH is auto-set by buildx per platform: "amd64", "arm64", etc.
ARG TARGETARCH
RUN apk add --no-cache docker-cli
ADD https://github.com/aptible/supercronic/releases/download/v${SUPERCRONIC_VERSION}/supercronic-linux-${TARGETARCH} \
/usr/local/bin/supercronic
RUN chmod +x /usr/local/bin/supercronic
# Match GID to your host's docker group. Check with: stat -c '%g' /var/run/docker.sock
ARG DOCKER_GID=999
RUN getent group ${DOCKER_GID} || addgroup -g ${DOCKER_GID} dockersock && \
adduser -D -G $(getent group ${DOCKER_GID} | cut -d: -f1) cannibal
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
USER cannibal
ENTRYPOINT ["/entrypoint.sh"]

7
README.md Normal file
View file

@ -0,0 +1,7 @@
# Cannibal
eats docker data omnom nom
## But what it really does?
Runs docker system prune periodically

28
build.sh Executable file
View file

@ -0,0 +1,28 @@
#!/bin/sh
set -e
IMAGE="${IMAGE:-docker-pruner}"
TAG="${TAG:-latest}"
DOCKER_GID="${DOCKER_GID:-$(stat -c '%g' /var/run/docker.sock)}"
SUPERCRONIC_VERSION="${SUPERCRONIC_VERSION:-0.2.33}"
ALPINE_VERSION="${ALPINE_VERSION:-3.21}"
if ! docker buildx inspect multibuilder > /dev/null 2>&1; then
echo "Creating multibuilder..."
docker buildx create --name multibuilder --use
else
docker buildx use multibuilder
fi
echo "Building ${IMAGE}:${TAG} for linux/amd64 and linux/arm64"
echo " Alpine: ${ALPINE_VERSION}"
echo " Supercronic: ${SUPERCRONIC_VERSION}"
echo " DOCKER_GID: ${DOCKER_GID}"
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg ALPINE_VERSION="${ALPINE_VERSION}" \
--build-arg SUPERCRONIC_VERSION="${SUPERCRONIC_VERSION}" \
--build-arg DOCKER_GID="${DOCKER_GID}" \
--tag "${IMAGE}:${TAG}" \
.

14
docker-compose.yml Normal file
View file

@ -0,0 +1,14 @@
services:
cannibal:
image: cannibal:latest
build:
context: .
args:
DOCKER_GID: "${DOCKER_GID:-999}"
restart: unless-stopped
environment:
PRUNE_SCHEDULE: "0 3 * * *" # every day at 3am
volumes:
- /var/run/docker.sock:/var/run/docker.sock
group_add:
- "${DOCKER_GID:-999}"

10
entrypoint.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
echo "Docker pruner starting as $(whoami). Schedule: ${PRUNE_SCHEDULE}"
# Write crontab from env var at runtime
CRONTAB_FILE=/tmp/crontab
echo "${PRUNE_SCHEDULE} docker system prune -af >> /tmp/prune.log 2>&1" > "${CRONTAB_FILE}"
exec supercronic "${CRONTAB_FILE}"