Files
esh-pfi-infrastructure/stacks/news-digest/entrypoint.sh
T
vh d552e289cb news-digest: per-instance cron schedule via env
Hardcoded crontab → render at container start from
DIGEST_CRON_AM + DIGEST_CRON_PM. Defaults match the original
0800 / 2000 so existing deploys are no-ops.

scripts/add-digest-user.sh learns --am and --pm flags so each
teammate's stack can fire on their hours:

  scripts/add-digest-user.sh bob --am "0 6 * * *" --pm "0 17 * * *"
  scripts/add-digest-user.sh carol --pm "30 18 * * 1-5"   # weekdays only

Standard 5-field cron syntax; busybox crond honors the container's
\$TZ. Removed the now-unused stacks/news-digest/crontab file and
the matching COPY in the Dockerfile.
2026-04-28 14:29:55 -07:00

50 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# entrypoint.sh — news-digest worker startup.
#
# Strategy:
# 1. If /output is empty, run digest.py once at start so the page
# isn't blank while waiting for the next cron tick.
# 2. Start busybox crond in foreground so the container stays up.
#
# All env vars are inherited from compose, including TZ which busybox
# crond honors when computing fire times.
set -e
mkdir -p /output
# Sync static frontend assets from /app/templates → /output. The web
# container serves /output as static; the assets are baked into the
# image but the bind-mounted /output otherwise wouldn't pick up
# CSS/JS updates on rebuild without a manual copy.
for asset in style.css app.js favicon.svg; do
if [ -f "/app/templates/$asset" ]; then
cp -f "/app/templates/$asset" "/output/$asset"
fi
done
if [ ! -f /output/index.html ]; then
echo "[entrypoint] no /output/index.html yet — running first digest"
/usr/local/bin/run-digest.sh || \
echo "[entrypoint] first run failed; cron will retry on schedule"
fi
# Render the crontab from env so each per-user instance can fire on
# its own schedule. Defaults match the original singleton (0800 / 2000
# local). Two separate vars (AM / PM) instead of one combined string
# so users can tweak one fire without re-deriving the other.
CRON_AM="${DIGEST_CRON_AM:-0 8 * * *}"
CRON_PM="${DIGEST_CRON_PM:-0 20 * * *}"
mkdir -p /etc/crontabs
{
echo "# news-digest cron — generated at container start from env."
echo "$CRON_AM /usr/local/bin/run-digest.sh"
echo "$CRON_PM /usr/local/bin/run-digest.sh"
} > /etc/crontabs/root
echo "[entrypoint] crontab:"
sed 's/^/ /' /etc/crontabs/root
# Foreground crond. -L /dev/stdout sends cron stdout/stderr to docker logs.
echo "[entrypoint] starting crond"
exec crond -f -L /dev/stdout -l 8