From c47bf46faa5a382dce7a7fe665121d618e3f3802 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Sat, 28 Mar 2026 19:03:38 +0000 Subject: [PATCH] Make data/ path configurable; preserve on frontend redeploy - docker-compose: DATA_DIR env var controls data volume mount (defaults to ./data for local, /var/www/html/gmal-scope-builder/data on server) - deploy.sh: resolve DATA_DIR from .env, default to persistent web dir - deploy.sh: rm only frontend files from WEB_DIR, preserve data/ subdir - .env.example: document DATA_DIR variable Co-Authored-By: Claude Sonnet 4.6 --- .env.example | 3 +++ deploy.sh | 13 ++++++++++--- docker-compose.yml | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index d0babef..805cfc5 100644 --- a/.env.example +++ b/.env.example @@ -2,3 +2,6 @@ POSTGRES_PASSWORD=your_strong_password_here ANTHROPIC_API_KEY=your-anthropic-api-key AZURE_TENANT_ID=your-azure-tenant-id AZURE_CLIENT_ID=your-azure-client-id +# Absolute path to the directory containing the GMAL Excel file +# Defaults to ./data (relative to repo) if not set +DATA_DIR=/var/www/html/gmal-scope-builder/data diff --git a/deploy.sh b/deploy.sh index 9387708..accf363 100755 --- a/deploy.sh +++ b/deploy.sh @@ -33,9 +33,14 @@ done command -v docker &>/dev/null || die "Docker is not installed" sudo docker compose version &>/dev/null || die "Docker Compose plugin not available" +# Resolve DATA_DIR (from .env or default to persistent web dir) +DATA_DIR=$(grep "^DATA_DIR=" "$REPO_DIR/.env" | cut -d= -f2- | tr -d '"' || true) +DATA_DIR="${DATA_DIR:-/var/www/html/gmal-scope-builder/data}" +sudo mkdir -p "$DATA_DIR" + # Warn if no GMAL Excel file (non-fatal — data may already be in the DB) -if ! ls "$REPO_DIR/data/"*.xlsx &>/dev/null 2>&1; then - warn "No .xlsx file found in $REPO_DIR/data/ — GMAL ingest will need to be triggered manually after deploy" +if ! sudo ls "${DATA_DIR}/"*.xlsx &>/dev/null 2>&1; then + warn "No .xlsx file found in $DATA_DIR — GMAL ingest will need to be triggered manually after deploy" fi log "Pre-flight OK" @@ -82,9 +87,11 @@ sudo docker run --rm \ # ── 7. Deploy frontend static files ────────────────────────────────────────── log "Deploying frontend to $WEB_DIR..." sudo mkdir -p "$WEB_DIR" -sudo rm -rf "${WEB_DIR:?}"/* +# Remove only frontend files — preserve data/ subdirectory +sudo find "${WEB_DIR:?}" -maxdepth 1 -mindepth 1 ! -name 'data' -exec rm -rf {} + sudo cp -r "$REPO_DIR/frontend/dist/." "$WEB_DIR/" sudo chown -R www-data:www-data "$WEB_DIR" +sudo chown -R root:root "$DATA_DIR" # data/ stays root-owned for Docker log "Frontend deployed ($(find "$REPO_DIR/frontend/dist" -type f | wc -l) files)" # ── 8. Apache config (idempotent) ───────────────────────────────────────────── diff --git a/docker-compose.yml b/docker-compose.yml index ee20bf7..f170365 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: ports: - "127.0.0.1:8002:8000" volumes: - - ./data:/app/data + - ${DATA_DIR:-./data}:/app/data volumes: pgdata: