From 256e9b9fc6a982ac7b77a05544004b0ce5549705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Doma=C5=84ski?= Date: Fri, 3 Apr 2026 20:51:34 +0200 Subject: [PATCH] first commit --- .dockerignore | 1 + Dockerfile | 24 ++++++++++++++++++++++++ README.md | 7 +++++++ build.sh | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 14 ++++++++++++++ entrypoint.sh | 10 ++++++++++ 6 files changed, 84 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 build.sh create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cffd296 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +!entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44bfaa6 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7d031b --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Cannibal + +eats docker data omnom nom + +## But what it really does? + +Runs docker system prune periodically diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..fdc928a --- /dev/null +++ b/build.sh @@ -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}" \ + . diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0003c7f --- /dev/null +++ b/docker-compose.yml @@ -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}" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..87fe4f5 --- /dev/null +++ b/entrypoint.sh @@ -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}"