Skip to content

Commit d090f04

Browse files
committed
style: final polish of comments and headers across all files
1 parent 8343b5a commit d090f04

5 files changed

Lines changed: 47 additions & 18 deletions

File tree

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ ENV WORKDIR=/app \
1414
TZ="Asia/Shanghai" \
1515
OVERMIND_PROCFILE=/Procfile \
1616
OVERMIND_CAN_DIE=crontab \
17+
# Gotify settings
1718
GOTIFY_SERVER_PORT=8080 \
19+
# Trust Caddy proxy (localhost) to correctly parse X-Forwarded-For
1820
GOTIFY_SERVER_TRUSTEDPROXIES='["127.0.0.1"]'
1921

2022
WORKDIR $WORKDIR
@@ -51,17 +53,17 @@ RUN apt update && apt install -y --no-install-recommends \
5153
tmux \
5254
msmtp \
5355
bsd-mailx \
54-
# Binary tools
56+
# Download binary tools
5557
&& curl -fsSL "$SUPERCRONIC_URL" -o /usr/local/bin/supercronic \
5658
&& curl -fsSL "$OVERMIND_URL" | gunzip -c - > /usr/local/bin/overmind \
5759
&& chmod +x /usr/local/bin/supercronic /usr/local/bin/overmind /restic.sh \
58-
# Mail symlinks
60+
# Symlink msmtp for mail commands
5961
&& ln -sf /usr/bin/msmtp /usr/bin/sendmail \
6062
&& ln -sf /usr/bin/msmtp /usr/sbin/sendmail \
6163
# Cleanup
6264
&& apt -y autoremove \
6365
&& rm -rf /var/lib/apt/lists/*
6466

65-
# Clear base image entrypoint
67+
# Clear base image entrypoint to allow Overmind to manage processes
6668
ENTRYPOINT []
6769
CMD ["overmind", "start"]

config/Caddyfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
admin off
99
persist_config off
1010

11+
# Trust Fly.io private networking for accurate IP parsing
1112
servers {
1213
trusted_proxies static private_ranges
1314
}
@@ -21,13 +22,13 @@
2122

2223
# ── Site Block ────────────────────────────────────────────────────────────────
2324
:80 {
24-
# Explicitly handle health checks
25+
# Always allow health checks bypass for Fly.io monitoring
2526
handle /health {
2627
respond "OK" 200
2728
}
2829

29-
# Domain Whitelist Enforcement
30-
# If CADDY_DOMAINS is set, block everything else
30+
# Domain Access Control
31+
# Block requests if CADDY_DOMAINS is set and host doesn't match
3132
@outside_domain {
3233
expression `{env.CADDY_DOMAINS} != ""`
3334
not host {$CADDY_DOMAINS}
@@ -36,23 +37,30 @@
3637
respond "Access Denied: Domain not allowed" 403
3738
}
3839

39-
# Main application handling
40+
# Main Reverse Proxy Logic
4041
handle {
4142
encode zstd gzip
4243

44+
# Harden security posture
4345
header {
46+
# Infrastructure protection
4447
Strict-Transport-Security "max-age=31536000;"
4548
X-Content-Type-Options "nosniff"
4649
X-Frame-Options "DENY"
4750
X-XSS-Protection "1; mode=block"
51+
52+
# Privacy & Anti-tracking
4853
Referrer-Policy "strict-origin-when-cross-origin"
4954
Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()"
5055
X-Robots-Tag "noindex, nofollow"
56+
57+
# Hide sensitive headers
5158
-Server
5259
-X-Powered-By
5360
-Last-Modified
5461
}
5562

63+
# Proxy to the application backend
5664
reverse_proxy localhost:8080 {
5765
header_up X-Real-IP {http.request.header.Fly-Client-IP}
5866
header_up X-Forwarded-For {http.request.header.Fly-Client-IP}

config/Procfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# ╔═══════════════════════════════════════════════════════════════════════════╗
2+
# ║ Overmind Process Configuration ║
3+
# ╚═══════════════════════════════════════════════════════════════════════════╝
4+
5+
# Application services
16
gotify: cd /app && ./gotify-app
27
caddy: caddy run --config /Caddyfile
38
crontab: supercronic /crontab

config/crontab

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# Restic backup
1+
# ╔═══════════════════════════════════════════════════════════════════════════╗
2+
# ║ Supercronic Crontab ║
3+
# ╚═══════════════════════════════════════════════════════════════════════════╝
4+
5+
# Restic backup schedule
26
@hourly /restic.sh backup

scripts/restic.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ LOG_DIR="/var/log/restic"
1515
LOG="$LOG_DIR/$(date +%Y%m%d_%H%M%S).log"
1616
mkdir -p "$LOG_DIR"
1717

18-
# ANSI colors
18+
# ANSI colors for terminal output
1919
R="\x1b[31;01m" G="\x1b[32;01m" Y="\x1b[33;01m" B="\x1b[34;01m" X="\x1b[0m"
2020

2121
# ┌───────────────────────────────────────────────────────────────────────────┐
2222
# │ Utilities │
2323
# └───────────────────────────────────────────────────────────────────────────┘
2424

25+
# Log output to both stdout and a log file
2526
log() { "$@" 2>&1 | tee -a "$LOG"; }
2627

28+
# Send email notification on failure or test
2729
mail() {
2830
[ -z "${SMTP_TO:-}" ] && return
29-
# Strip ANSI codes, add UTF-8 header
31+
# Strip ANSI colors and add UTF-8 content-type
3032
sed 's/\x1b\[[0-9;]*m//g' "$LOG" | command mail \
3133
-a "Content-Type: text/plain; charset=UTF-8" \
3234
-s "[$APP_NAME] $1" "$SMTP_TO"
3335
}
3436

37+
# Run a command and log its status
3538
run() {
3639
log echo -en "${B}$2${X} "
3740
local out
@@ -42,10 +45,11 @@ run() {
4245
fi
4346
log echo -e "${R}${X}"
4447
log echo "$out"
45-
mail "$2"
48+
mail "Task Failed: $2"
4649
exit 2
4750
}
4851

52+
# Initialize msmtp configuration for email sending
4953
initMail() {
5054
[ -z "${SMTP_TO:-}" ] && return
5155
[ -z "${SMTP_HOST:-}" ] && return
@@ -69,43 +73,49 @@ EOF
6973
# │ Commands │
7074
# └───────────────────────────────────────────────────────────────────────────┘
7175

76+
# Perform full backup, check, and prune
7277
cmdBackup() {
73-
# Sync time to avoid R2/S3 signature mismatch
78+
# Sync time to ensure S3/R2 requests are valid
7479
ntpdate -u pool.ntp.org 2>/dev/null || log echo -e "${Y}NTP sync skipped${X}"
7580

81+
# Unlock repository in case of previous interrupted runs
7682
restic unlock 2>/dev/null || true
7783

84+
# Initialize repository if it doesn't exist
7885
if ! restic cat config >/dev/null 2>&1; then
79-
log echo -e "${Y}Repo not initialized${X}"
86+
log echo -e "${Y}Repository not initialized, initializing now...${X}"
8087
run "restic init" "Repo init"
8188
fi
8289

90+
# Execute restic operations
8391
run "restic backup --verbose '$DATA'" "Restic backup"
8492
run "restic check" "Restic check"
8593
run "restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --keep-yearly 3 --prune" "Snapshot prune"
8694

95+
# Cleanup old logs (older than 10 hours)
8796
find "$LOG_DIR" -name "*.log" -type f -mmin +600 -delete
8897

89-
log echo -e "${G}Backup complete ✨${X}"
98+
log echo -e "${G}Backup process complete ✨${X}"
9099
}
91100

101+
# Restore data from a specific snapshot ID
92102
cmdRestore() {
93-
[ -z "${1:-}" ] && { echo "Usage: $0 restore <id>"; exit 1; }
103+
[ -z "${1:-}" ] && { echo "Usage: $0 restore <snapshot-id>"; exit 1; }
94104
run "restic restore '$1' --target /" "Restore $1"
95105
}
96106

97107
# ┌───────────────────────────────────────────────────────────────────────────┐
98-
#Main
108+
#Execution Entry Point
99109
# └───────────────────────────────────────────────────────────────────────────┘
100110

101-
[ -z "${RESTIC_PASSWORD:-}" ] && { echo "Missing RESTIC_PASSWORD"; exit 1; }
111+
[ -z "${RESTIC_PASSWORD:-}" ] && { echo "Error: RESTIC_PASSWORD not set"; exit 1; }
102112

103113
initMail
104114

105115
case "${1:-}" in
106116
backup) cmdBackup ;;
107117
restore) cmdRestore "${2:-}" ;;
108118
snapshots) restic snapshots ;;
109-
mail-test) echo "Test email from $APP_NAME" | command mail -s "[$APP_NAME] Mail Test" "$SMTP_TO" && echo "Mail sent to $SMTP_TO" ;;
119+
mail-test) echo "This is a test email from the $APP_NAME backup system." | command mail -s "[$APP_NAME] Mail Test" "$SMTP_TO" && echo "Test email sent to $SMTP_TO" ;;
110120
*) echo "Usage: $0 {backup|restore <id>|snapshots|mail-test}"; exit 1 ;;
111121
esac

0 commit comments

Comments
 (0)