Expand compose env vars; add ntfy token + priority + TZ support
docker-compose.yml: - Every env var documented inline with type/default/purpose - env_file: .env (required: false) — container starts without it - NTFY_TOPIC uses :? operator so compose errors clearly if unset - New vars: NTFY_TOKEN (private topics), NTFY_PRIORITY, TZ, APP_PORT, DEV_PORT - Removed duplicate NTFY_URL entry notifier/index.mjs: - Reads TZ from env (was hardcoded "America/Chicago") - Reads NTFY_PRIORITY from env (was hardcoded "default") - Adds Authorization: Bearer header when NTFY_TOKEN is set - Startup log shows auth status and full schedule config .env.example: mirrors every compose variable with descriptions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f38c038fb
commit
0eb625c188
3 files changed
+85
-26
No files matched your search
+32
-11
@@ -1,17 +1,38 @@
|
|||||||
# Copy to .env and fill in your values
|
# Copy this file to .env and fill in your values.
|
||||||
|
# docker-compose reads .env automatically for variable substitution.
|
||||||
|
|
||||||
# ntfy topic — make it unguessable (anyone who knows it can receive/send)
|
# ── App ────────────────────────────────────────────────────────────────────────
|
||||||
# Subscribe at https://ntfy.sh/YOUR_TOPIC or in the ntfy app
|
# Port the web app is exposed on (default: 8080)
|
||||||
|
APP_PORT=8080
|
||||||
|
|
||||||
|
# ── ntfy ──────────────────────────────────────────────────────────────────────
|
||||||
|
# Required — your ntfy topic. Keep it unguessable (anyone with the name can sub).
|
||||||
|
# Subscribe at https://ntfy.sh/YOUR_TOPIC or in the ntfy iOS/Android app.
|
||||||
NTFY_TOPIC=your-unguessable-topic-here
|
NTFY_TOPIC=your-unguessable-topic-here
|
||||||
|
|
||||||
# Optional: self-hosted ntfy server
|
# ntfy server — leave as-is for ntfy.sh, or point to your self-hosted instance
|
||||||
# NTFY_URL=https://ntfy.sh
|
NTFY_URL=https://ntfy.sh
|
||||||
|
|
||||||
# Optional: URL the notification links back to (your deployed app)
|
# Bearer token for private/access-controlled topics (leave blank for public)
|
||||||
# APP_URL=http://localhost:8080
|
NTFY_TOKEN=
|
||||||
|
|
||||||
# Optional: cron schedule (default: 9 AM on the 1st of every month)
|
# Notification priority: min | low | default | high | urgent
|
||||||
# CRON_SCHEDULE=0 9 1 * *
|
NTFY_PRIORITY=default
|
||||||
|
|
||||||
# Set to "true" to get a test ping the moment the notifier starts
|
# ── Schedule ──────────────────────────────────────────────────────────────────
|
||||||
# NTFY_TEST_ON_START=false
|
# Cron schedule for the monthly reminder (default: 9 AM on the 1st of each month)
|
||||||
|
# Format: minute hour day-of-month month day-of-week
|
||||||
|
CRON_SCHEDULE=0 9 1 * *
|
||||||
|
|
||||||
|
# IANA timezone for the cron schedule
|
||||||
|
TZ=America/Chicago
|
||||||
|
|
||||||
|
# URL the notification deep-links back to
|
||||||
|
APP_URL=http://localhost:8080
|
||||||
|
|
||||||
|
# Set to "true" to fire a test notification the moment the notifier container starts
|
||||||
|
NTFY_TEST_ON_START=false
|
||||||
|
|
||||||
|
# ── Dev ───────────────────────────────────────────────────────────────────────
|
||||||
|
# Port for the Vite dev server (docker compose --profile dev up dev)
|
||||||
|
DEV_PORT=5173
|
||||||
+37
-7
@@ -1,26 +1,54 @@
|
|||||||
services:
|
services:
|
||||||
|
|
||||||
|
# ── Web app (nginx, port 8080) ──────────────────────────────────────────────
|
||||||
app:
|
app:
|
||||||
build: .
|
build: .
|
||||||
image: ghcr.io/nmemmert/letter:main
|
image: ghcr.io/nmemmert/letter:main
|
||||||
ports:
|
ports:
|
||||||
- "8080:80"
|
- "${APP_PORT:-8080}:80"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
|
# ── Monthly ntfy reminder ───────────────────────────────────────────────────
|
||||||
notifier:
|
notifier:
|
||||||
build: ./notifier
|
build: ./notifier
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
env_file:
|
||||||
|
- path: .env
|
||||||
|
required: false # container still starts without a .env file
|
||||||
environment:
|
environment:
|
||||||
# Required: set your ntfy topic (keep it unguessable, e.g. "nate-letter-k7x2")
|
# ── ntfy connection ───────────────────────────────────────────────────
|
||||||
NTFY_TOPIC: ${NTFY_TOPIC}
|
# Required: your ntfy topic — keep it unguessable, e.g. "nate-letter-k7x2"
|
||||||
# Optional overrides
|
# Subscribe at https://ntfy.sh/<NTFY_TOPIC> or in the ntfy mobile app
|
||||||
|
NTFY_TOPIC: ${NTFY_TOPIC:?NTFY_TOPIC is required — set it in .env}
|
||||||
|
|
||||||
|
# ntfy server (default: ntfy.sh; set to your self-hosted URL if applicable)
|
||||||
NTFY_URL: ${NTFY_URL:-https://ntfy.sh}
|
NTFY_URL: ${NTFY_URL:-https://ntfy.sh}
|
||||||
|
|
||||||
|
# Bearer token for access-controlled / private topics (leave blank for public)
|
||||||
|
NTFY_TOKEN: ${NTFY_TOKEN:-}
|
||||||
|
|
||||||
|
# Notification priority: min | low | default | high | urgent
|
||||||
|
NTFY_PRIORITY: ${NTFY_PRIORITY:-default}
|
||||||
|
|
||||||
|
# ── Schedule ──────────────────────────────────────────────────────────
|
||||||
|
# Cron expression — default fires at 9 AM on the 1st of every month
|
||||||
|
# Format: minute hour day-of-month month day-of-week
|
||||||
|
CRON_SCHEDULE: ${CRON_SCHEDULE:-0 9 1 * *}
|
||||||
|
|
||||||
|
# IANA timezone for the cron schedule
|
||||||
|
TZ: ${TZ:-America/Chicago}
|
||||||
|
|
||||||
|
# ── App ───────────────────────────────────────────────────────────────
|
||||||
|
# URL the notification deep-links back to (shown as "Open" in ntfy)
|
||||||
APP_URL: ${APP_URL:-http://localhost:8080}
|
APP_URL: ${APP_URL:-http://localhost:8080}
|
||||||
CRON_SCHEDULE: ${CRON_SCHEDULE:-0 9 1 * *} # 9 AM on the 1st of every month
|
|
||||||
# Set to "true" to get a test ping immediately on container start
|
# Set to "true" to fire a test notification immediately on container start
|
||||||
NTFY_TEST_ON_START: ${NTFY_TEST_ON_START:-false}
|
NTFY_TEST_ON_START: ${NTFY_TEST_ON_START:-false}
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- app
|
- app
|
||||||
|
|
||||||
|
# ── Local dev (Vite HMR, port 5173) — run with: docker compose --profile dev up dev
|
||||||
dev:
|
dev:
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
@@ -28,7 +56,9 @@ services:
|
|||||||
- .:/app
|
- .:/app
|
||||||
- node_modules:/app/node_modules
|
- node_modules:/app/node_modules
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "${DEV_PORT:-5173}:5173"
|
||||||
|
environment:
|
||||||
|
NODE_ENV: development
|
||||||
command: sh -c "npm install && npm run dev -- --host 0.0.0.0"
|
command: sh -c "npm install && npm run dev -- --host 0.0.0.0"
|
||||||
profiles: [dev]
|
profiles: [dev]
|
||||||
|
|
||||||
|
|||||||
+16
-8
@@ -2,7 +2,10 @@ import cron from "node-cron";
|
|||||||
|
|
||||||
const NTFY_URL = process.env.NTFY_URL || "https://ntfy.sh";
|
const NTFY_URL = process.env.NTFY_URL || "https://ntfy.sh";
|
||||||
const NTFY_TOPIC = process.env.NTFY_TOPIC;
|
const NTFY_TOPIC = process.env.NTFY_TOPIC;
|
||||||
const CRON_SCHEDULE = process.env.CRON_SCHEDULE || "0 9 1 * *"; // 9 AM on the 1st of each month
|
const NTFY_PRIORITY = process.env.NTFY_PRIORITY || "default";
|
||||||
|
const NTFY_TOKEN = process.env.NTFY_TOKEN; // Bearer token for private topics
|
||||||
|
const CRON_SCHEDULE = process.env.CRON_SCHEDULE || "0 9 1 * *";
|
||||||
|
const TZ = process.env.TZ || "America/Chicago";
|
||||||
const APP_URL = process.env.APP_URL || "http://localhost:8080";
|
const APP_URL = process.env.APP_URL || "http://localhost:8080";
|
||||||
|
|
||||||
if (!NTFY_TOPIC) {
|
if (!NTFY_TOPIC) {
|
||||||
@@ -26,15 +29,18 @@ async function sendReminder() {
|
|||||||
const message = `${monthName} ${year} is done. Take 10 minutes to capture the month before it fades. Open your letter app to answer this month's 6 prompts.`;
|
const message = `${monthName} ${year} is done. Take 10 minutes to capture the month before it fades. Open your letter app to answer this month's 6 prompts.`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${NTFY_URL}/${NTFY_TOPIC}`, {
|
const headers = {
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
Title: title,
|
Title: title,
|
||||||
Priority: "default",
|
Priority: NTFY_PRIORITY,
|
||||||
Tags: "pencil,calendar",
|
Tags: "pencil,calendar",
|
||||||
Click: APP_URL,
|
Click: APP_URL,
|
||||||
"Content-Type": "text/plain",
|
"Content-Type": "text/plain",
|
||||||
},
|
};
|
||||||
|
if (NTFY_TOKEN) headers["Authorization"] = `Bearer ${NTFY_TOKEN}`;
|
||||||
|
|
||||||
|
const res = await fetch(`${NTFY_URL}/${NTFY_TOPIC}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
body: message,
|
body: message,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -50,11 +56,13 @@ async function sendReminder() {
|
|||||||
|
|
||||||
console.log(`[${new Date().toISOString()}] Notifier started`);
|
console.log(`[${new Date().toISOString()}] Notifier started`);
|
||||||
console.log(` Topic: ${NTFY_URL}/${NTFY_TOPIC}`);
|
console.log(` Topic: ${NTFY_URL}/${NTFY_TOPIC}`);
|
||||||
console.log(` Schedule: ${CRON_SCHEDULE}`);
|
console.log(` Priority: ${NTFY_PRIORITY}`);
|
||||||
|
console.log(` Auth: ${NTFY_TOKEN ? "Bearer token set" : "none (public topic)"}`);
|
||||||
|
console.log(` Schedule: ${CRON_SCHEDULE} (${TZ})`);
|
||||||
console.log(` App URL: ${APP_URL}`);
|
console.log(` App URL: ${APP_URL}`);
|
||||||
|
|
||||||
// Run on schedule
|
// Run on schedule
|
||||||
cron.schedule(CRON_SCHEDULE, sendReminder, { timezone: "America/Chicago" });
|
cron.schedule(CRON_SCHEDULE, sendReminder, { timezone: TZ });
|
||||||
|
|
||||||
// Send a startup test ping in dev mode
|
// Send a startup test ping in dev mode
|
||||||
if (process.env.NTFY_TEST_ON_START === "true") {
|
if (process.env.NTFY_TEST_ON_START === "true") {
|
||||||
|
|||||||
Reference in new issue
Block a user