From 49725b2fd0e130d5b0de8b8d211070ad248eedc0 Mon Sep 17 00:00:00 2001 From: Kunthawat Greethong Date: Sat, 2 May 2026 10:24:03 +0700 Subject: [PATCH] refactor: move data.db and uploads to storage/ folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed database path to ./storage/data.db - Changed uploads path to ./storage/uploads - Updated Dockerfile to create storage/uploads dir (not uploads) - Updated entrypoint.sh to check /app/storage/data.db - Removed COPY of uploads from builder to runner Now all persistent data is in /app/storage/: - /app/storage/data.db (SQLite database) - /app/storage/uploads/ (uploaded media) Easypanel mount: emdash-storage → /app/storage To update EmDash: change version in package.json → push → redeploy Co-Authored-By: Claude Opus 4.6 --- Dockerfile | 3 +-- astro.config.mjs | 4 ++-- entrypoint.sh | 22 ++++++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index d655b76..acdc314 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN pnpm build && pnpm exec emdash init && mkdir -p uploads +RUN pnpm build && mkdir -p storage/uploads FROM deps AS runner @@ -26,7 +26,6 @@ ENV HOST=0.0.0.0 COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/dist ./dist -COPY --from=builder /app/uploads ./uploads EXPOSE 4321 diff --git a/astro.config.mjs b/astro.config.mjs index 6621681..448765e 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -17,9 +17,9 @@ export default defineConfig({ integrations: [ react(), emdash({ - database: sqlite({ url: "file:./data.db" }), + database: sqlite({ url: "file:./storage/data.db" }), storage: local({ - directory: "./uploads", + directory: "./storage/uploads", baseUrl: "/_emdash/api/media/file", }), plugins: [auditLogPlugin()], diff --git a/entrypoint.sh b/entrypoint.sh index b7e3369..394b802 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,15 +2,21 @@ # Wait for volume mount to settle (Easypanel may mount after container starts) sleep 3 -# Check if data.db exists and has content -# Using file size as backup check (empty DB is ~8KB, seeded DB is much larger) -DB_SIZE=$(stat -c%s /app/data.db 2>/dev/null || stat -f%z /app/data.db 2>/dev/null || echo "0") +# Check if data.db exists in storage folder and has content +DB_PATH="/app/storage/data.db" +UPLOADS_PATH="/app/storage/uploads" -if [ -f /app/data.db ] && [ "$DB_SIZE" -gt 1000 ]; then - # DB exists and has size > 1KB, check if it has content - if sqlite3 /app/data.db "SELECT COUNT(*) FROM content" 2>/dev/null | grep -q "^[1-9]"; then - echo "Database exists with content, starting normally..." - exec node ./dist/server/entry.mjs +# Ensure storage directories exist +mkdir -p "$UPLOADS_PATH" + +# Check if data.db exists and has content +if [ -f "$DB_PATH" ]; then + DB_SIZE=$(stat -c%s "$DB_PATH" 2>/dev/null || stat -f%z "$DB_PATH" 2>/dev/null || echo "0") + if [ "$DB_SIZE" -gt 1000 ]; then + if sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM content" 2>/dev/null | grep -q "^[1-9]"; then + echo "Database exists with content, starting normally..." + exec node ./dist/server/entry.mjs + fi fi fi