diff --git a/.gitignore b/.gitignore index 182c4aa..f490fe8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,9 @@ regctl # ignore snooze file snooze.list # ignore updates file -updates_available.txt \ No newline at end of file +updates_available.txt +# ignore user compose files +compose.yaml +compose.yml +docker-compose.yaml +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ac1111a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use an official Alpine image as a base +FROM alpine:latest + +WORKDIR /app + +# Install apps +RUN apk update && apk add --no-cache bash curl docker-cli docker-cli-compose supercronic jq regclient msmtp --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ + +# Copy the script files into the container +COPY entrypoint.sh /app/entrypoint.sh +COPY dockcheck.sh /app/dockcheck.sh +COPY urls.list /app/urls.list +COPY notify_templates /app/notify_templates +COPY extras /app/extras +COPY addons /app/addons + +# Create symlink, give execution rights on the script and set proper permissions +RUN chmod +x /app/dockcheck.sh +RUN chmod +x /app/entrypoint.sh + +ENTRYPOINT ["/app/entrypoint.sh"] + +# Run the cron daemon in the foreground and tail the log file to keep the container running +CMD ["supercronic", "-passthrough-logs", "-json", "/app/crontab"] diff --git a/compose-example.yaml b/compose-example.yaml new file mode 100644 index 0000000..fb86825 --- /dev/null +++ b/compose-example.yaml @@ -0,0 +1,14 @@ +services: + dockcheck: + image: dockcheck:latest + restart: unless-stopped + environment: + CRON_SCHEDULE: "0 * * * *" + DOCKCHECK_ARGS: "-mniI -x 10" + CRON_SCHEDULE_1: "30 1 * * *" + DOCKCHECK_ARGS_1: "-milap -x 1" + volumes: + - /etc/localtime:/etc/localtime:ro + - /var/run/docker.sock:/var/run/docker.sock + - ./dockcheck.config:/app/dockcheck.config + - /path/to/projects/docker:/path/to/projects/docker:ro diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..f67e013 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Exit immediately if a command exits with a non-zero status +set -e + +# If the CRON_SCHEDULE and DOCKCHECK_ARGS environment variables are set, create the crontab entry for the dockcheck user +if [ -n "$CRON_SCHEDULE" ] && [ -n "$DOCKCHECK_ARGS" ]; then + # Write the environment variable content to a temporary file, ensuring a newline at the end + echo "$CRON_SCHEDULE" /app/dockcheck.sh $DOCKCHECK_ARGS > /app/crontab + + if [ -n "$DOCKCHECK_ONSTART" ]; then + echo "Executing: dockcheck $DOCKCHECK_ARGS" + /app/dockcheck.sh $DOCKCHECK_ARGS + fi + + # Support additional schedule variables + for schedule_var in "${!CRON_SCHEDULE_@}"; do + suffix="${schedule_var#CRON_SCHEDULE_}" + schedule_value="${!schedule_var}" + args_var="DOCKCHECK_ARGS_${suffix}" + args_value="${!args_var}" + echo "$schedule_value" /app/dockcheck.sh $args_value >> /app/crontab + + onstart_var="DOCKCHECK_ONSTART_${suffix}" + if [ -n "${!onstart_var}" ]; then + echo "Executing: dockcheck $args_value" + /app/dockcheck.sh $args_value + fi + done + + echo "Crontab created." +else + echo "No CRON_SCHEDULE or DOCKCHECK_ARGS environment variable(s) found. No crontab created." +fi + +# Pass control to the CMD command specified in the Dockerfile +exec "$@"