feat: add docker
This commit is contained in:
33
docker/entrypoint.sh
Normal file
33
docker/entrypoint.sh
Normal file
@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e # Exit immediately if a command exits with a non-zero status.
|
||||
|
||||
# Define the command to be executed by cron or manually
|
||||
APP_CMD="/usr/local/bin/ruleset-sync -i /config/template.json -o /rules"
|
||||
|
||||
# === Manual Run ===
|
||||
# If the first argument is "manual", run the sync once and exit.
|
||||
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}
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# === Cron Setup ===
|
||||
# This section runs as root to set up the cron job.
|
||||
|
||||
echo "Setting up cron job with schedule: ${CRON_SCHEDULE}"
|
||||
|
||||
# Remove any existing crontab
|
||||
crontab -d || true
|
||||
|
||||
# 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.
|
||||
echo "Starting cron daemon..."
|
||||
exec crond -f -l 8
|
Reference in New Issue
Block a user