Fixed docker
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 36s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 36s
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:3.21
|
||||||
|
|
||||||
ENV TZ="UTC"
|
ENV TZ="UTC"
|
||||||
ENV SCHEDULE="* * * * *"
|
ENV SCHEDULE="* * * * *"
|
||||||
@@ -10,28 +10,19 @@ 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
|
||||||
|
|
||||||
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
||||||
|
|
||||||
# Create volume directories (ownership will be set at runtime)
|
# Create volume directories (ownership will be set at runtime)
|
||||||
RUN mkdir -p /config /log
|
RUN mkdir -p /config /log
|
||||||
|
|
||||||
## Start crond
|
## Start crond
|
||||||
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
|
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
|
||||||
CMD [ "crond", "-f" ]
|
|
||||||
|
|
||||||
VOLUME /config
|
VOLUME /config
|
||||||
VOLUME /log
|
VOLUME /log
|
||||||
@@ -5,8 +5,10 @@ services:
|
|||||||
image: git.debilux.org/chris/nsupdate
|
image: git.debilux.org/chris/nsupdate
|
||||||
container_name: nsupdate
|
container_name: nsupdate
|
||||||
environment:
|
environment:
|
||||||
- SCHEDULE=*\2 * * * *
|
- SCHEDULE=*/5 * * * *
|
||||||
- TZ=Europe/Berlin
|
- TZ=Europe/Berlin
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
- NSUPDATE_INWX_USER=YOUR_INWX_USERNAME
|
- NSUPDATE_INWX_USER=YOUR_INWX_USERNAME
|
||||||
- NSUPDATE_INWX_PASSWORD=YOUR_INWX_PASSWORD
|
- NSUPDATE_INWX_PASSWORD=YOUR_INWX_PASSWORD
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -1,42 +1,45 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
set -eu
|
COMMAND="/usr/local/bin/nsupdate.sh"
|
||||||
|
|
||||||
|
# Default schedule if not specified
|
||||||
SCHEDULE="${SCHEDULE:-* * * * *}"
|
SCHEDULE="${SCHEDULE:-* * * * *}"
|
||||||
|
|
||||||
|
# Default cron log level if not specified
|
||||||
CRON_LOG_LEVEL="${CRON_LOG_LEVEL:-2}"
|
CRON_LOG_LEVEL="${CRON_LOG_LEVEL:-2}"
|
||||||
PUID="${PUID:-1000}"
|
|
||||||
PGID="${PGID:-1000}"
|
|
||||||
CRON_FILE="/etc/crontabs/root"
|
|
||||||
|
|
||||||
# Create or update group with specified PGID
|
# Default user name not specified
|
||||||
if grep -q "^nsupdate:" /etc/group 2>/dev/null; then
|
USERNAME="${USERNAME:-nsupdate}"
|
||||||
delgroup nsupdate 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
addgroup -g "${PGID}" nsupdate 2>/dev/null || true
|
|
||||||
|
|
||||||
# Create or update user with specified PUID
|
# Default UID and GID if not specified
|
||||||
if grep -q "^nsupdate:" /etc/passwd 2>/dev/null; then
|
PUID=${PUID:-1000}
|
||||||
deluser nsupdate 2>/dev/null || true
|
PGID=${PGID:-1000}
|
||||||
fi
|
|
||||||
adduser -u "${PUID}" -G nsupdate -s /sbin/nologin -D nsupdate 2>/dev/null || true
|
|
||||||
|
|
||||||
# Set ownership of volumes
|
# Default timezone if not specified
|
||||||
chown -R "${PUID}:${PGID}" /config /log
|
TZ=${TZ:-Etc/UTC}
|
||||||
|
|
||||||
# Ensure crontabs directory exists
|
# Set the timezone
|
||||||
mkdir -p "$(dirname "${CRON_FILE}")"
|
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
|
||||||
|
echo "$TZ" >/etc/timezone
|
||||||
|
echo "Timezone set to $TZ"
|
||||||
|
|
||||||
# Write cron job to run as the specified user (by UID:GID)
|
# Create nsupdate group
|
||||||
printf '%s su -s /bin/sh %s:%s -c /usr/local/bin/nsupdate.sh\n' "${SCHEDULE}" "${PUID}" "${PGID}" > "${CRON_FILE}"
|
addgroup -S --gid $PGID "$USERNAME"
|
||||||
chmod 600 "${CRON_FILE}"
|
|
||||||
|
|
||||||
if [ "$#" -gt 0 ]; then
|
# Create nsupdate user
|
||||||
if [ "$1" = "crond" ]; then
|
adduser -S -u $PUID -G "$USERNAME" -D -H -s /bin/false "$USERNAME"
|
||||||
shift
|
|
||||||
exec crond -l "${CRON_LOG_LEVEL}" "$@"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec "$@"
|
CRON_FILE="/etc/crontabs/$USERNAME"
|
||||||
fi
|
mkdir -p /etc/crontabs
|
||||||
|
printf '%s %s %s\n' "$SCHEDULE" "$USERNAME" "$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
|
exec crond -l "${CRON_LOG_LEVEL}" -f
|
||||||
Reference in New Issue
Block a user