Docker: Support for setting cron schedule, PUID, GUID and time zone via env vars.
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 33s

This commit is contained in:
2026-04-26 22:43:51 +02:00
parent c70334e65e
commit ad365339b0
4 changed files with 77 additions and 24 deletions

View File

@@ -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/). 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 ## 2025-11-28
### Fixed ### Fixed

View File

@@ -2,30 +2,27 @@ FROM alpine:latest
ENV TZ="UTC" ENV TZ="UTC"
ENV SCHEDULE="* * * * *" ENV SCHEDULE="* * * * *"
ENV PUID=1000
ENV PGID=1000
## Configure runtime variables for nsupdate ## Configure runtime variables for nsupdate
ENV NSUPDATE_CONFD_DIR="/config" ENV NSUPDATE_CONFD_DIR="/config"
ENV NSUPDATE_LOG_DIR="/log" ENV NSUPDATE_LOG_DIR="/log"
## Install requirements ## Install requirements
RUN apk update
RUN apk add --no-cache git curl libxml2-utils tzdata jq 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 # Cache Bust upon new commits
ADD https://api.github.com/repos/chrisb86/nsupdate/git/refs/heads/main /.git-hashref ADD https://api.github.com/repos/chrisb86/nsupdate/git/refs/heads/main /.git-hashref
COPY nsupdate.sh /usr/local/bin/nsupdate.sh COPY --chmod=755 nsupdate.sh /usr/local/bin/nsupdate.sh
RUN chmod +x /usr/local/bin/nsupdate.sh COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/entrypoint.sh
## Setup cron job # Create volume directories (ownership will be set at runtime)
RUN echo "${SCHEDULE} sh /usr/local/bin/nsupdate.sh" >> /etc/crontabs/root RUN mkdir -p /config /log
## Start crond ## Start crond
CMD [ "crond", "-l", "2", "-f" ] ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
VOLUME /config VOLUME /config
VOLUME /log VOLUME /log

View File

@@ -1,15 +1,17 @@
version: '3'
services: services:
nsupdate: nsupdate:
image: git.debilux.org/chris/nsupdate image: git.debilux.org/chris/nsupdate:latest
container_name: nsupdate container_name: nsupdate
environment:
- SCHEDULE="*\2 * * * *"
- TZ=Europe/Berlin
- NSUPDATE_INWX_USER=YOUR_INWX_USERNAME
- NSUPDATE_INWX_PASSWORD=YOUR_INWX_PASSWORD
volumes:
- ./data:/config
- ./log:/log
restart: unless-stopped restart: unless-stopped
environment:
- 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:
- ./config:/config
- ./log:/log

View File

@@ -1,4 +1,49 @@
#!/bin/sh #!/bin/sh
set -e
echo "${SCHEDULE} sh nsupdate.sh" >> /etc/crontabs/root COMMAND="/usr/local/bin/nsupdate.sh"
crond -l 2 -f > /dev/stdout 2> /dev/stderr &
# 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