feat: refactor Docker setup for built-in cron scheduling and improved entrypoint handling

This commit is contained in:
2025-11-04 21:37:46 +01:00
parent 57e2bc392d
commit 9d5a9b438d
10 changed files with 481 additions and 240 deletions

View File

@@ -1,29 +1,43 @@
services:
microsoft-rewards-bot:
microsoft-rewards-script:
build: .
container_name: microsoft-rewards-bot
container_name: microsoft-rewards-script
restart: unless-stopped
# Volume mounts: Specify a location where you want to save the files on your local machine.
volumes:
- ./src/accounts.jsonc:/app/src/accounts.jsonc:ro
- ./src/config.jsonc:/app/src/config.jsonc:ro
- ./sessions:/app/sessions
- ./src/accounts.jsonc:/usr/src/microsoft-rewards-script/dist/accounts.jsonc:ro
- ./src/config.jsonc:/usr/src/microsoft-rewards-script/dist/config.jsonc:ro
- ./sessions:/usr/src/microsoft-rewards-script/sessions # Optional, saves your login session
- ./reports:/usr/src/microsoft-rewards-script/reports # Optional, saves run reports
environment:
TZ: "America/Toronto" # Set your timezone for logging (and cron if enabled)
TZ: "America/Toronto" # Set your timezone for proper scheduling
NODE_ENV: "production"
# Force headless when running in Docker (uses Chromium Headless Shell only)
FORCE_HEADLESS: "1"
# Optional: enable in-container cron scheduling
#USE_CRON: "true"
#CRON_SCHEDULE: "0 9 * * *" # Daily at 9 AM (see https://crontab.guru)
#RUN_ON_START: "true" # Run once immediately on container start
CRON_SCHEDULE: "0 7,16,20 * * *" # Customize your schedule, use crontab.guru for formatting
RUN_ON_START: "true" # Runs the script immediately on container startup
# Add scheduled start-time randomization (uncomment to customize or disable, default: enabled)
#MIN_SLEEP_MINUTES: "5"
#MAX_SLEEP_MINUTES: "50"
SKIP_RANDOM_SLEEP: "false"
# Optionally set how long to wait before killing a stuck script run (prevents blocking future runs, default: 8 hours)
#STUCK_PROCESS_TIMEOUT_HOURS: "8"
# Optional resource limits for the container
mem_limit: 4g
cpus: 2
# Health check - monitors if cron daemon is running to ensure scheduled jobs can execute
# Container marked unhealthy if cron process dies
healthcheck:
test: ["CMD", "sh", "-c", "pgrep cron > /dev/null || exit 1"]
interval: 60s
timeout: 10s
retries: 3
start_period: 30s
# Security hardening
security_opt:
- no-new-privileges:true
# Default: single run per container start
command: ["node", "--enable-source-maps", "./dist/index.js"]
- no-new-privileges:true