#!/bin/bash # ───────────────────────────────────────────────────────────────────────────── # migrate-to-erpnext.sh — One-time migration: serve Ops from ERPNext container # # Run on the server (96.125.196.67) as root. # This script: # 1. Stops and removes the standalone ops-frontend container # 2. Patches ERPNext docker-compose to add Authentik Traefik labels # 3. Recreates ERPNext frontend with new labels # # After running this, use deploy.sh to push new builds. # ───────────────────────────────────────────────────────────────────────────── set -e # Find ERPNext compose file ERP_COMPOSE="" for p in /opt/erpnext/docker-compose.yml /opt/frappe_docker/docker-compose.yml; do [ -f "$p" ] && ERP_COMPOSE="$p" && break done [ -z "$ERP_COMPOSE" ] && echo "ERROR: ERPNext docker-compose not found" && exit 1 ERP_DIR="$(dirname "$ERP_COMPOSE")" echo "=== Targo Ops Infrastructure Simplification ===" echo "Using: $ERP_COMPOSE" echo "" # ── Step 1: Stop ops-frontend container ── echo "==> Step 1: Stopping ops-frontend container..." if docker ps -a --format '{{.Names}}' | grep -q 'ops-frontend'; then (cd /opt/ops-app/infra 2>/dev/null && docker compose down 2>/dev/null) || \ (docker stop ops-frontend 2>/dev/null; docker rm ops-frontend 2>/dev/null) || true echo " Done." else echo " Already removed." fi # ── Step 2: Patch docker-compose.yml ── echo "" echo "==> Step 2: Adding Authentik labels to ERPNext frontend..." if grep -q 'routers.ops-app' "$ERP_COMPOSE"; then echo " Already present. Skipping." else cp "$ERP_COMPOSE" "${ERP_COMPOSE}.bak" python3 < Step 3: Recreating ERPNext frontend..." cd "$ERP_DIR" docker compose up -d frontend echo " Done." echo "" echo "=== Migration complete ===" echo "" echo "Deploy ops build: ./deploy.sh" echo "Access: https://erp.gigafibre.ca/assets/ops-app/" echo "Cleanup: rm -rf /opt/ops-app" echo ""