From e1c092c29787c5eac14a69dac9302ccb46e3618d Mon Sep 17 00:00:00 2001 From: Anurag Saxena Date: Sun, 3 May 2026 04:18:06 -0400 Subject: [PATCH] fix: redirect ~/.9router to DATA_DIR in Docker to persist usage data across updates (closes #585) (#658) --- Dockerfile | 7 +++++-- README.md | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5d72cb5..83496e4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ ENV NODE_ENV=production ENV PORT=20128 ENV HOSTNAME=0.0.0.0 ENV NEXT_TELEMETRY_DISABLED=1 +ENV DATA_DIR=/app/data COPY --from=builder /app/public ./public COPY --from=builder /app/.next/static ./.next/static @@ -34,11 +35,13 @@ COPY --from=builder /app/src/mitm ./src/mitm # Standalone node_modules may omit deps only required by the MITM child process. COPY --from=builder /app/node_modules/node-forge ./node_modules/node-forge -RUN mkdir -p /app/data && chown -R bun:bun /app +RUN mkdir -p /app/data && chown -R bun:bun /app && \ + mkdir -p /app/data-home && chown bun:bun /app/data-home && \ + ln -sf /app/data-home /root/.9router 2>/dev/null || true # Fix permissions at runtime (handles mounted volumes) RUN apk --no-cache upgrade && apk --no-cache add su-exec && \ - printf '#!/bin/sh\nchown -R bun:bun /app/data 2>/dev/null\nexec su-exec bun "$@"\n' > /entrypoint.sh && \ + printf '#!/bin/sh\nchown -R bun:bun /app/data /app/data-home 2>/dev/null\nexec su-exec bun "$@"\n' > /entrypoint.sh && \ chmod +x /entrypoint.sh EXPOSE 20128 diff --git a/README.md b/README.md index 8fd575ea..7c6992d5 100644 --- a/README.md +++ b/README.md @@ -1078,9 +1078,9 @@ Notes: ### Runtime Files and Storage - Main app state: `${DATA_DIR}/db.json` (providers, combos, aliases, keys, settings), managed by `src/lib/localDb.js`. -- Usage history and logs: `~/.9router/usage.json` and `~/.9router/log.txt`, managed by `src/lib/usageDb.js`. +- Usage history and logs: `${DATA_DIR}/usage.json` and `${DATA_DIR}/log.txt`, managed by `src/lib/usageDb.js`. - Optional request/translator logs: `/logs/...` when `ENABLE_REQUEST_LOGS=true`. -- Usage storage currently follows `~/.9router` path logic and is independent from `DATA_DIR`. +- Both `${DATA_DIR}` and `~/.9router` resolve to the same location in a Docker container — the symlink `/root/.9router -> /app/data` is created at build time.