Fix deploy-preview: handle missing prod DB gracefully
All checks were successful
All checks were successful
Production still uses JSON, so /data/planner.db doesn't exist yet. Detect cp failure and use empty DB (init_db creates tables on startup). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -78,14 +78,20 @@ def deploy(pr_id: str):
|
|||||||
).stdout.strip()
|
).stdout.strip()
|
||||||
|
|
||||||
if prod_pod:
|
if prod_pod:
|
||||||
kubectl("cp", f"{PROD_NS}/{prod_pod}:/data/planner.db", "data/planner.db")
|
r = kubectl("cp", f"{PROD_NS}/{prod_pod}:/data/planner.db", "data/planner.db", check=False)
|
||||||
|
if r.returncode != 0 or not Path("data/planner.db").exists() or Path("data/planner.db").stat().st_size == 0:
|
||||||
|
print(" WARNING: Could not copy prod DB, using empty DB")
|
||||||
|
Path("data/planner.db").touch()
|
||||||
else:
|
else:
|
||||||
print(" WARNING: No running prod pod, using empty DB")
|
print(" WARNING: No running prod pod, using empty DB")
|
||||||
Path("data/planner.db").touch()
|
Path("data/planner.db").touch()
|
||||||
|
|
||||||
# 2. Build and push image
|
# 2. Build and push image
|
||||||
print("[2/5] Building Docker image...")
|
print("[2/5] Building Docker image...")
|
||||||
dockerfile = textwrap.dedent("""\
|
# Only COPY DB if it has content, otherwise let init_db create fresh
|
||||||
|
has_db = Path("data/planner.db").exists() and Path("data/planner.db").stat().st_size > 0
|
||||||
|
copy_db_line = "COPY data/planner.db /data/planner.db" if has_db else "RUN mkdir -p /data"
|
||||||
|
dockerfile = textwrap.dedent(f"""\
|
||||||
FROM node:20-slim AS frontend-build
|
FROM node:20-slim AS frontend-build
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY frontend/package.json frontend/package-lock.json ./
|
COPY frontend/package.json frontend/package-lock.json ./
|
||||||
@@ -99,7 +105,7 @@ def deploy(pr_id: str):
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
COPY backend/ ./backend/
|
COPY backend/ ./backend/
|
||||||
COPY --from=frontend-build /build/dist ./frontend/
|
COPY --from=frontend-build /build/dist ./frontend/
|
||||||
COPY data/planner.db /data/planner.db
|
{copy_db_line}
|
||||||
ENV DB_PATH=/data/planner.db
|
ENV DB_PATH=/data/planner.db
|
||||||
ENV FRONTEND_DIR=/app/frontend
|
ENV FRONTEND_DIR=/app/frontend
|
||||||
ENV DATA_DIR=/data
|
ENV DATA_DIR=/data
|
||||||
|
|||||||
Reference in New Issue
Block a user