From ad365339b047e3aa06cd9b3ff0b3bee12321d595 Mon Sep 17 00:00:00 2001 From: Christian Busch Date: Sun, 26 Apr 2026 22:43:51 +0200 Subject: [PATCH] Docker: Support for setting cron schedule, PUID, GUID and time zone via env vars. --- CHANGELOG.md | 9 +++++++ docker/Dockerfile | 19 ++++++--------- docker/docker-compose.yml | 22 +++++++++-------- docker/entrypoint.sh | 51 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc4c423..562138e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## 2026-04-26 + +### Fixed +- Setting cron schedule for docker image via environment variable works now +- Setting time zone for docker image via environment variable works now + +### Added +- Docker image now supports setting PUID and GUID + ## 2025-11-28 ### Fixed diff --git a/docker/Dockerfile b/docker/Dockerfile index 86c1306..cab573f 100755 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,30 +2,27 @@ FROM alpine:latest ENV TZ="UTC" ENV SCHEDULE="* * * * *" +ENV PUID=1000 +ENV PGID=1000 ## Configure runtime variables for nsupdate ENV NSUPDATE_CONFD_DIR="/config" ENV NSUPDATE_LOG_DIR="/log" ## Install requirements -RUN apk update RUN apk add --no-cache git curl libxml2-utils tzdata jq -# Read timezone from server, so in docker-compose you can change TZ -RUN ln -sf "/usr/share/zoneinfo/${TZ}" /etc/localtime && \ - echo "${TZ}" > /etc/timezone && date - # Cache Bust upon new commits ADD https://api.github.com/repos/chrisb86/nsupdate/git/refs/heads/main /.git-hashref -COPY nsupdate.sh /usr/local/bin/nsupdate.sh -RUN chmod +x /usr/local/bin/nsupdate.sh +COPY --chmod=755 nsupdate.sh /usr/local/bin/nsupdate.sh +COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/entrypoint.sh -## Setup cron job -RUN echo "${SCHEDULE} sh /usr/local/bin/nsupdate.sh" >> /etc/crontabs/root +# Create volume directories (ownership will be set at runtime) +RUN mkdir -p /config /log ## Start crond -CMD [ "crond", "-l", "2", "-f" ] +ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ] VOLUME /config -VOLUME /log +VOLUME /log \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 46a63e4..ca62c5b 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,15 +1,17 @@ -version: '3' - services: nsupdate: - image: git.debilux.org/chris/nsupdate + image: git.debilux.org/chris/nsupdate:latest container_name: nsupdate + restart: unless-stopped environment: - - SCHEDULE="*\2 * * * *" - - TZ=Europe/Berlin - - NSUPDATE_INWX_USER=YOUR_INWX_USERNAME - - NSUPDATE_INWX_PASSWORD=YOUR_INWX_PASSWORD + - PUID=1000 # (default: 1000) + - PGID=1000 # (default: 1000) + - VERBOSE=false + - DEBUG=false + - SCHEDULE=*/2 * * * * (default: * * * * *) + - TZ=Europe/Berlin # (default: Etc/UTC) + - NSUPDATE_INWX_USER=${NSUPDATE_INWX_USER} + - NSUPDATE_INWX_PASSWORD=${NSUPDATE_INWX_PASSWORD} volumes: - - ./data:/config - - ./log:/log - restart: unless-stopped \ No newline at end of file + - ./config:/config + - ./log:/log \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index c079839..4c633ae 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,4 +1,49 @@ -#! /bin/sh +#!/bin/sh +set -e -echo "${SCHEDULE} sh nsupdate.sh" >> /etc/crontabs/root -crond -l 2 -f > /dev/stdout 2> /dev/stderr & \ No newline at end of file +COMMAND="/usr/local/bin/nsupdate.sh" + +# Default schedule if not specified +SCHEDULE="${SCHEDULE:-* * * * *}" + +# Default cron log level if not specified +CRON_LOG_LEVEL="${CRON_LOG_LEVEL:-2}" + +# Default user name not specified +USERNAME="${USERNAME:-nsupdate}" + +# Default UID and GID if not specified +PUID=${PUID:-1000} +PGID=${PGID:-1000} + +# Default timezone if not specified +TZ=${TZ:-Etc/UTC} + +# Set the timezone +ln -snf /usr/share/zoneinfo/$TZ /etc/localtime +echo "$TZ" >/etc/timezone +echo "Timezone set to $TZ" + +# Create group if it doesn't exist yet +if ! getent group "$USERNAME" > /dev/null 2>&1; then + addgroup -g "$PGID" "$USERNAME" +fi + +# Create user if it doesn't exist yet +if ! getent passwd "$USERNAME" > /dev/null 2>&1; then + adduser -u "$PUID" -G "$USERNAME" -D -H -s /bin/false "$USERNAME" +fi + +CRON_FILE="/etc/crontabs/$USERNAME" +mkdir -p /etc/crontabs +printf '%s %s\n' "$SCHEDULE" "$COMMAND" > "$CRON_FILE" +chmod 600 "$CRON_FILE" + +# Set correct permissions +chown -R "$USERNAME":"$USERNAME" /config +chown -R "$USERNAME":"$USERNAME" /log +echo "Permissions adjusted" + +# Start nsupdate in the foreground with reduced warnings +echo "Starting cron..." +exec crond -l "${CRON_LOG_LEVEL}" -f \ No newline at end of file