Fix: Remove hardcoded UUIDs and secrets from deploy scripts
- deploy.py: UUIDs from env vars or Coolify API lookup by name - fast-deploy.sh: No hardcoded UUIDs, APP_DOMAIN from env - docker-compose.yml: All secrets from env vars, no hardcoded values - .env.example: All required vars documented - Deleted obsolete fast-frontend-deploy.sh with hardcoded container name
This commit is contained in:
+78
-11
@@ -4,36 +4,103 @@
|
||||
# bash scripts/fast-deploy.sh frontend # Frontend-only: build + copy (~20s)
|
||||
# bash scripts/fast-deploy.sh full # Full: Coolify rebuild (~2min)
|
||||
# Default: frontend
|
||||
#
|
||||
# Environment variables:
|
||||
# COOLIFY_API_TOKEN — Coolify API token (required for full deploy)
|
||||
# COOLIFY_BASE_URL — Coolify base URL (default: https://server.media-on.de)
|
||||
# COOLIFY_APP_UUID — Application UUID (optional, resolved via API if absent)
|
||||
# APP_NAME — Application name for API lookup (default: leocrm-api)
|
||||
# APP_DOMAIN — App domain (required for full deploy, e.g. https://crm.media-on.de)
|
||||
# SSH_KEY — SSH key path (default: /a0/usr/workdir/.ssh/coolify-01-root)
|
||||
# SERVER_IP — Server IP (default: 46.225.91.159)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SERVER="root@46.225.91.159"
|
||||
SSH_KEY="${SSH_KEY:-/a0/usr/workdir/.ssh/coolify-01-root}"
|
||||
SERVER_IP="${SERVER_IP:-46.225.91.159}"
|
||||
SERVER="root@${SERVER_IP}"
|
||||
SSH_OPTS="-o StrictHostKeyChecking=no -i $SSH_KEY"
|
||||
MODE="${1:-frontend}"
|
||||
|
||||
cd /a0/usr/workdir/leocrm-fix
|
||||
# Resolve repo root from script location
|
||||
cd "$(dirname "$0")/.."
|
||||
REPO_ROOT="$(pwd)"
|
||||
|
||||
# ─── Helper: Resolve app UUID via Coolify API ────────────────────────
|
||||
resolve_app_uuid() {
|
||||
local token="${COOLIFY_API_TOKEN:-}"
|
||||
local base_url="${COOLIFY_BASE_URL:-https://server.media-on.de}"
|
||||
local app_name="${APP_NAME:-leocrm-api}"
|
||||
|
||||
if [ -z "$token" ]; then
|
||||
echo "ERROR: COOLIFY_API_TOKEN not set" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
curl -sS -H "Authorization: Bearer $token" \
|
||||
"${base_url}/api/v1/applications" \
|
||||
| python3 -c "
|
||||
import sys, json
|
||||
apps = json.load(sys.stdin)
|
||||
for app in apps:
|
||||
if app.get('name') == '${app_name}':
|
||||
print(app.get('uuid', ''))
|
||||
break
|
||||
" 2>/dev/null
|
||||
}
|
||||
|
||||
# ─── Full Deploy ─────────────────────────────────────────────────────
|
||||
if [ "$MODE" = "full" ]; then
|
||||
echo "[Full Deploy] Triggering Coolify rebuild..."
|
||||
COOLIFY_API_TOKEN="${COOLIFY_API_TOKEN:-}" \
|
||||
COOLIFY_APP_UUID='stvabl4vaqru7jclx4ittzr3' \
|
||||
COOLIFY_BASE_URL='https://server.media-on.de' \
|
||||
|
||||
if [ -z "${COOLIFY_API_TOKEN:-}" ]; then
|
||||
echo "ERROR: COOLIFY_API_TOKEN not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${APP_DOMAIN:-}" ]; then
|
||||
echo "ERROR: APP_DOMAIN not set (e.g. https://crm.media-on.de)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COOLIFY_API_TOKEN="$COOLIFY_API_TOKEN" \
|
||||
COOLIFY_BASE_URL="${COOLIFY_BASE_URL:-https://server.media-on.de}" \
|
||||
COOLIFY_APP_UUID="${COOLIFY_APP_UUID:-}" \
|
||||
COOLIFY_WORKER_UUID="${COOLIFY_WORKER_UUID:-}" \
|
||||
APP_NAME="${APP_NAME:-leocrm-api}" \
|
||||
WORKER_NAME="${WORKER_NAME:-leocrm-worker}" \
|
||||
APP_DOMAIN="$APP_DOMAIN" \
|
||||
SSH_KEY="$SSH_KEY" \
|
||||
SERVER_IP='46.225.91.159' \
|
||||
/opt/venv/bin/python scripts/deploy.py
|
||||
SERVER_IP="$SERVER_IP" \
|
||||
/opt/venv/bin/python "$REPO_ROOT/scripts/deploy.py"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Frontend-only fast deploy
|
||||
# ─── Frontend-only Fast Deploy ──────────────────────────────────────
|
||||
|
||||
# Resolve app UUID
|
||||
APP_UUID="${COOLIFY_APP_UUID:-}"
|
||||
if [ -z "$APP_UUID" ]; then
|
||||
if [ -z "${COOLIFY_API_TOKEN:-}" ]; then
|
||||
echo "ERROR: COOLIFY_APP_UUID or COOLIFY_API_TOKEN must be set" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[1/6] Resolving app UUID via Coolify API..."
|
||||
APP_UUID="$(resolve_app_uuid)"
|
||||
if [ -z "$APP_UUID" ]; then
|
||||
echo "ERROR: Could not resolve app UUID" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " App UUID: $APP_UUID"
|
||||
fi
|
||||
|
||||
echo "[1/5] Building frontend..."
|
||||
cd frontend
|
||||
cd "$REPO_ROOT/frontend"
|
||||
npm run build 2>&1 | tail -3
|
||||
|
||||
echo "[2/5] Finding container..."
|
||||
CONTAINER=$(ssh $SSH_OPTS $SERVER 'docker ps --format "{{.Names}}" | grep "^stvabl4vaqru7jclx4ittzr3-" | head -1')
|
||||
CONTAINER=$(ssh $SSH_OPTS $SERVER "docker ps --format '{{.Names}}' | grep '^${APP_UUID}-' | head -1")
|
||||
if [ -z "$CONTAINER" ]; then
|
||||
echo "ERROR: Could not find app container"
|
||||
echo "ERROR: Could not find app container with prefix ${APP_UUID}-" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " Container: $CONTAINER"
|
||||
|
||||
Reference in New Issue
Block a user