Skip to content

Commit 748a852

Browse files
fix: root-owned bind-mount data dir breaks log writes
entrypoint now chowns the LOG_FILE directory at startup (handles host volumes created by root/other UIDs) then drops privileges via su-exec.
1 parent 88ef6d3 commit 748a852

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /TinyUptimeRobot .
77

88
# ---- runtime stage ----
99
FROM alpine:3.20
10-
RUN apk add --no-cache ca-certificates && adduser -D monitor \
11-
&& mkdir -p /app/data && chown -R monitor:monitor /app
12-
10+
RUN apk add --no-cache ca-certificates su-exec \
11+
&& adduser -D monitor \
12+
&& mkdir -p /app/data \
13+
&& chown -R monitor:monitor /app
1314
WORKDIR /app
1415
COPY --from=build /TinyUptimeRobot /app/TinyUptimeRobot
15-
USER monitor
16+
COPY entrypoint.sh /app/entrypoint.sh
17+
RUN chmod +x /app/entrypoint.sh
18+
# runs as root only to fix /app/data ownership on bind mounts, then drops to monitor
19+
ENTRYPOINT ["/app/entrypoint.sh"]
20+
1621
ENV TARGETS_FILE=/app/targets.txt \
1722
LOG_FILE=/app/data/status.txt \
1823
CHECK_INTERVAL=60s \
1924
HTTP_TIMEOUT=10s
20-
VOLUME ["/app/data"]
21-
ENTRYPOINT ["/app/TinyUptimeRobot"]

entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# Fix ownership of the data dir (bind mounts are often owned by root),
3+
# then drop privileges and run as the unprivileged monitor user.
4+
set -e
5+
6+
DATA_DIR="$(dirname "${LOG_FILE:-/app/data/status.txt}")"
7+
mkdir -p "$DATA_DIR" 2>/dev/null || true
8+
chown -R monitor:monitor "$DATA_DIR" 2>/dev/null || true
9+
10+
# if the targets file is read-only and unreadable, that's fine — the app will error clearly
11+
exec su-exec monitor:monitor /app/TinyUptimeRobot "$@"

0 commit comments

Comments
 (0)