chore: adjust docker files

This commit is contained in:
2025-06-29 13:05:09 +03:00
parent 6dccf35a30
commit da4bffad4d
4 changed files with 51 additions and 37 deletions

View File

@ -1,33 +1,46 @@
#!/bin/sh
set -e # Exit immediately if a command exits with a non-zero status.
set -e
# Define the command to be executed by cron or manually
APP_CMD="/usr/local/bin/ruleset-sync -i /config/template.json -o /rules"
# --- Environment Variable Defaults ---
DOMAIN=${DOMAIN:-}
RULE_PATH=${RULE_PATH:-}
# === Manual Run ===
# If the first argument is "manual", run the sync once and exit.
# --- Build the Command ---
# This command is now used for both the initial run and the cron job.
APP_CMD="/usr/local/bin/ruleset-sync \
--input-config /config/template.json \
--rules-dir /rules \
--output-config /config/default.json \
--domain ${DOMAIN} \
--rule-path ${RULE_PATH}"
# --- Manual Run Mode ---
# This allows for on-demand execution without restarting the container.
if [ "$1" = "manual" ]; then
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Running one-time manual sync..."
# Execute the command as the non-root 'app' user
su-exec app:app ${APP_CMD}
su-exec app:app sh -c "${APP_CMD}"
exit 0
fi
# === Cron Setup ===
# This section runs as root to set up the cron job.
# ===================================================================
# Initial Synchronization on Container Start
# ===================================================================
echo "--- Running initial synchronization on container start ---"
# Execute the command once immediately.
# We run it as the non-root 'app' user to ensure correct file permissions.
su-exec app:app sh -c "${APP_CMD}"
echo "--- Initial synchronization finished ---"
# ===================================================================
# --- Cron Setup ---
# This section runs after the initial sync is complete.
echo "Setting up cron job with schedule: ${CRON_SCHEDULE}"
# Remove any existing crontab
crontab -d || true
echo "${CRON_SCHEDULE} su-exec app:app sh -c '${APP_CMD}' > /proc/1/fd/1 2>/proc/1/fd/2" | crontab -
# Add the new cron job. It will run the command as the 'app' user
# and redirect stdout/stderr to the container's log stream.
echo "${CRON_SCHEDULE} su-exec app:app ${APP_CMD} > /proc/1/fd/1 2>/proc/1/fd/2" | crontab -
# Start the cron daemon in the foreground.
# This keeps the container running and handles executing the scheduled jobs.
# Logs from crond itself and the script's output will go to Docker logs.
# --- Start Cron Daemon ---
# This must be the last command. It keeps the container running.
echo "Starting cron daemon..."
exec crond -f -l 8