fix(docker): chown /data so the non-root hub can write its DB 🐳🔑

The image runs as uid 10001; the VOLUME /data was root-owned so sqlite/blob
writes failed and the container exited on boot. Create + chown /data to the
devbox user before VOLUME/USER (a named volume inherits the image dir's
ownership). Verified on real arm64 docker (.13): builds, runs non-root, serves
/metrics + dashboard /api/state, 31.9MB. Also made install.sh's service setup
non-fatal (a failing systemctl --user / launchctl over headless SSH warns +
continues instead of aborting the whole install) — fleet-verified: systemd
user service enabled w/ Restart=always, NRestarts proved self-heal.
This commit is contained in:
shoemoney 2026-06-23 13:10:44 -05:00
parent 44e142fdf0
commit 94f7d3e782
2 changed files with 15 additions and 7 deletions

View file

@ -18,6 +18,9 @@ FROM alpine:3.20
# ca-certificates + tzdata for correct TLS/timestamps; wget (busybox) backs the healthcheck. # ca-certificates + tzdata for correct TLS/timestamps; wget (busybox) backs the healthcheck.
RUN apk add --no-cache ca-certificates tzdata && adduser -D -u 10001 devbox RUN apk add --no-cache ca-certificates tzdata && adduser -D -u 10001 devbox
COPY --from=build /out/devbox-hub /usr/local/bin/devbox-hub COPY --from=build /out/devbox-hub /usr/local/bin/devbox-hub
# Own /data BEFORE declaring the volume + dropping root, so the non-root user can
# write the sqlite DB + blobs (a named volume inherits the image dir's ownership).
RUN mkdir -p /data && chown devbox:devbox /data
USER devbox USER devbox
VOLUME /data VOLUME /data
# 8088 = hub API · 8099 = live dashboard (only reachable if you enable --dashboard) # 8088 = hub API · 8099 = live dashboard (only reachable if you enable --dashboard)

View file

@ -144,9 +144,13 @@ install_service_macos() {
</dict></plist> </dict></plist>
PLIST PLIST
launchctl unload "$plist" 2>/dev/null || true launchctl unload "$plist" 2>/dev/null || true
launchctl load "$plist" if launchctl load "$plist" 2>/dev/null; then
say " ✅ launchd agent loaded (KeepAlive). logs: ~/Library/Logs/devbox.log" say " ✅ launchd agent loaded (KeepAlive). logs: ~/Library/Logs/devbox.log"
say " stop: launchctl unload $plist" say " stop: launchctl unload $plist"
else
say " ⚠️ wrote $plist but 'launchctl load' failed (run it from a desktop session, not SSH):"
say " launchctl load $plist"
fi
} }
install_service_linux() { install_service_linux() {
@ -166,14 +170,15 @@ RestartSec=3
[Install] [Install]
WantedBy=default.target WantedBy=default.target
UNIT UNIT
if command -v systemctl >/dev/null 2>&1; then if command -v systemctl >/dev/null 2>&1 &&
systemctl --user daemon-reload systemctl --user daemon-reload 2>/dev/null &&
systemctl --user enable --now devbox.service systemctl --user enable --now devbox.service 2>/dev/null; then
loginctl enable-linger "$USER" 2>/dev/null || say " (run 'sudo loginctl enable-linger $USER' so it starts before login)" loginctl enable-linger "$USER" 2>/dev/null || say " (run 'sudo loginctl enable-linger $USER' so it starts before login)"
say " ✅ systemd user service enabled (Restart=always). logs: journalctl --user -u devbox -f" say " ✅ systemd user service enabled (Restart=always). logs: journalctl --user -u devbox -f"
say " stop: systemctl --user disable --now devbox" say " stop: systemctl --user disable --now devbox"
else else
say " wrote $unit — no systemd here; start manually with: $DEVBOX start" say " ⚠️ wrote $unit, but couldn't enable it via 'systemctl --user' (no user session bus is"
say " common over headless SSH). Enable from a desktop login: systemctl --user enable --now devbox"
fi fi
} }