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
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 33s
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -1,15 +1,17 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
nsupdate:
|
||||
image: git.debilux.org/chris/nsupdate
|
||||
image: git.debilux.org/chris/nsupdate:latest
|
||||
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
|
||||
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
|
||||
@@ -1,4 +1,49 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "${SCHEDULE} sh nsupdate.sh" >> /etc/crontabs/root
|
||||
crond -l 2 -f > /dev/stdout 2> /dev/stderr &
|
||||
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
|
||||
Reference in New Issue
Block a user