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 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-03-28 19:03:38 +00:00
parent 53a18d0d62
commit c47bf46faa
3 changed files with 14 additions and 4 deletions

View file

@ -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

View file

@ -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) ─────────────────────────────────────────────

View file

@ -29,7 +29,7 @@ services:
ports:
- "127.0.0.1:8002:8000"
volumes:
- ./data:/app/data
- ${DATA_DIR:-./data}:/app/data
volumes:
pgdata: