From 1dd68dad17af34a5fb165b97873697dbe77f3620 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 7 Jan 2025 21:14:32 +0000 Subject: [PATCH] Add support to run in docker container for systems without php --- Dockerfile | 12 ++++++++++++ README.md | 5 +++++ docker-compose.yaml | 11 +++++++++++ entrypoint.sh | 13 +++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b514e2a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM php:8.2-cli-alpine +COPY . / +WORKDIR / + +ENV SCHEDULE="*/5 * * * *" \ + CRON_CMD="php /update.php" + +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["/usr/sbin/crond", "-f"] + +SHELL ["/bin/ash"] diff --git a/README.md b/README.md index 6c3ee6e..405378e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ Configuration is very simple: You should probably run this script every few minutes, so that your IP is updated as quickly as possible. Add it to your cronjobs and run it regularly, for example every five minutes. +### How to use - alternative with Docker +`docker compose up` + +The docker container includes the cronjob and runs by default every 5 minutes. + ### CLI options Just add these Options after the command like `./update.php --quiet` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..1f1b181 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3' + +services: + netcup-dyndns: + restart: unless-stopped + network_mode: host + environment: + - SCHEDULE="*/5 * * * *" + build: + context: . + dockerfile: Dockerfile diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..bd1863c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/ash -e + +echo "startup $0" + +if [ ! -z "${SCHEDULE}" ] && [ ! -z "${CRON_CMD}" ]; then + echo "configure cron: ${SCHEDULE} ${CRON_CMD}" + echo "@reboot ${CRON_CMD}" > /etc/crontabs/root + echo "${SCHEDULE} ${CRON_CMD}" >> /etc/crontabs/root +fi + +echo "run: $@" +exec "$@" +