fix: fix quote syntax error in curl health check (line 129)
This commit is contained in:
parent
e91072a45c
commit
f4af4731ed
169
scripts/opax.sh
169
scripts/opax.sh
|
|
@ -9,10 +9,6 @@
|
||||||
# Alias: opax
|
# Alias: opax
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
# --- General Setup ---
|
|
||||||
# Exit on error, unset variable, or pipe failure.
|
|
||||||
# set -euo pipefail # REMOVED: kills shell when sourced
|
|
||||||
|
|
||||||
# --- Pre-computation and Environment ---
|
# --- Pre-computation and Environment ---
|
||||||
OSVAUCO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
OSVAUCO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
export GOOGLE_CLOUD_PROJECT="propane-will-491900-m5"
|
export GOOGLE_CLOUD_PROJECT="propane-will-491900-m5"
|
||||||
|
|
@ -20,23 +16,19 @@ export GOOGLE_CLOUD_LOCATION="us-central1"
|
||||||
export GEMINI_MODEL="gemini-2.5-pro"
|
export GEMINI_MODEL="gemini-2.5-pro"
|
||||||
|
|
||||||
# --- UI Colors and Icons ---
|
# --- UI Colors and Icons ---
|
||||||
# Use tput for wider compatibility, with fallbacks.
|
GREEN="$(tput setaf 2 2>/dev/null || printf '\033[0;32m')"
|
||||||
GREEN="$(tput setaf 2 || echo -e '\033[0;32m')"
|
RED="$(tput setaf 1 2>/dev/null || printf '\033[0;31m')"
|
||||||
RED="$(tput setaf 1 || echo -e '\033[0;31m')"
|
YELLOW="$(tput setaf 3 2>/dev/null || printf '\033[1;33m')"
|
||||||
YELLOW="$(tput setaf 3 || echo -e '\033[1;33m')"
|
CYAN="$(tput setaf 6 2>/dev/null || printf '\033[0;36m')"
|
||||||
CYAN="$(tput setaf 6 || echo -e '\033[0;36m')"
|
WHITE="$(tput setaf 7 2>/dev/null || printf '\033[1;37m')"
|
||||||
WHITE="$(tput setaf 7 || echo -e '\033[1;37m')"
|
DIM="$(tput dim 2>/dev/null || printf '\033[2m')"
|
||||||
DIM="$(tput dim || echo -e '\033[2m')"
|
BOLD="$(tput bold 2>/dev/null || printf '\033[1m')"
|
||||||
BOLD="$(tput bold || echo -e '\033[1m')"
|
NC="$(tput sgr0 2>/dev/null || printf '\033[0m')"
|
||||||
NC="$(tput sgr0 || echo -e '\033[0m')" # No Color
|
|
||||||
|
|
||||||
# Checkmarks
|
|
||||||
OK="✅"
|
OK="✅"
|
||||||
FAIL="❌"
|
FAIL="❌"
|
||||||
|
|
||||||
# Internal state to prevent re-printing banner on multiple sources
|
|
||||||
if [[ -z "${OPAX_LOADED-}" ]]; then
|
if [[ -z "${OPAX_LOADED-}" ]]; then
|
||||||
# --- Banner Display ---
|
|
||||||
clear
|
clear
|
||||||
printf "${CYAN}"
|
printf "${CYAN}"
|
||||||
echo " ___ _____ _ _ ___ _ _ ___ _____ "
|
echo " ___ _____ _ _ ___ _ _ ___ _____ "
|
||||||
|
|
@ -46,128 +38,95 @@ if [[ -z "${OPAX_LOADED-}" ]]; then
|
||||||
echo " | |_| |___| | \ \_/ / | | | |_| | |__ \ \_/ / "
|
echo " | |_| |___| | \ \_/ / | | | |_| | |__ \ \_/ / "
|
||||||
echo " \___/\____/ \___/\_| |_/\___/ \___| \___/ "
|
echo " \___/\____/ \___/\_| |_/\___/ \___| \___/ "
|
||||||
printf "${NC}"
|
printf "${NC}"
|
||||||
printf "${DIM} -------------------------------------------------${NC}
|
printf "${DIM} -------------------------------------------------${NC}\n"
|
||||||
"
|
printf " ${CYAN}OPAX${NC} ${DIM}Operator Platform // ${GOOGLE_CLOUD_PROJECT}${NC}\n"
|
||||||
printf " ${CYAN}OPAX${NC} ${DIM}Operator Platform // ${GOOGLE_CLOUD_PROJECT}${NC}
|
printf "${DIM} -------------------------------------------------${NC}\n\n"
|
||||||
"
|
|
||||||
printf "${DIM} -------------------------------------------------${NC}
|
|
||||||
|
|
||||||
"
|
printf "${BOLD}${WHITE} Preflight Checks...${NC}\n"
|
||||||
|
|
||||||
# --- Health & Auth Checks ---
|
|
||||||
printf "${BOLD}${WHITE} Preflight Checks...${NC}
|
|
||||||
"
|
|
||||||
|
|
||||||
# Helper function for checks
|
|
||||||
run_check() {
|
run_check() {
|
||||||
local description="$1"
|
local description="$1"
|
||||||
local command_to_run="$2"
|
local command_to_run="$2"
|
||||||
local error_message="$3"
|
local error_message="$3"
|
||||||
local is_critical="${4:-false}" # Default to not critical
|
local is_critical="${4:-false}"
|
||||||
|
|
||||||
printf " %-35s" "$description"
|
printf " %-40s" "$description"
|
||||||
if eval "$command_to_run" &>/dev/null; then
|
if eval "$command_to_run" &>/dev/null; then
|
||||||
printf "${GREEN}${OK}${NC}
|
printf "${GREEN}${OK}${NC}\n"
|
||||||
"
|
|
||||||
else
|
else
|
||||||
printf "${RED}${FAIL}${NC}
|
printf "${RED}${FAIL}${NC}\n"
|
||||||
"
|
|
||||||
if [[ "$is_critical" == "true" ]]; then
|
if [[ "$is_critical" == "true" ]]; then
|
||||||
printf "
|
printf "\n ${RED}${BOLD}CRITICAL:${NC} ${error_message}\n"
|
||||||
${RED}${BOLD}CRITICAL FAILURE:${NC} ${error_message}
|
printf " ${YELLOW}Aborting OPAX startup.${NC}\n\n"
|
||||||
"
|
|
||||||
printf " ${YELLOW}Aborting OPAX startup.${NC}
|
|
||||||
|
|
||||||
"
|
|
||||||
# Clean up and exit the subshell this script is running in
|
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
printf " ${YELLOW}Warning:${NC} ${error_message}
|
printf " ${YELLOW}⚠${NC} ${error_message}\n"
|
||||||
"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 1. Critical: gcloud authentication
|
run_check "gcloud user authenticated" \
|
||||||
run_check "gcloud user authenticated"
|
"gcloud auth list --filter=status:ACTIVE --format='value(account)' | grep -q @" \
|
||||||
"gcloud auth list --filter=status:ACTIVE --format='value(account)' | grep -q .@"
|
"Run: gcloud auth login" \
|
||||||
"Not logged into gcloud. Run 'gcloud auth login'."
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# 2. Critical: Application Default Credentials (ADC)
|
run_check "Application Default Credentials (ADC)" \
|
||||||
run_check "Application Default Credentials (ADC)"
|
"gcloud auth application-default print-access-token --quiet" \
|
||||||
"gcloud auth application-default print-access-token --quiet"
|
"Run: gcloud auth application-default login" \
|
||||||
"ADC not configured. Run 'gcloud auth application-default login'."
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# 3. Critical: gcloud project configuration
|
run_check "gcloud project = $GOOGLE_CLOUD_PROJECT" \
|
||||||
run_check "gcloud project set to '$GOOGLE_CLOUD_PROJECT'"
|
"[[ \$(gcloud config get-value project 2>/dev/null) == '$GOOGLE_CLOUD_PROJECT' ]]" \
|
||||||
"[[ \$(gcloud config get-value project) == '$GOOGLE_CLOUD_PROJECT' ]]"
|
"Run: gcloud config set project $GOOGLE_CLOUD_PROJECT" \
|
||||||
"Wrong project. Run 'gcloud config set project $GOOGLE_CLOUD_PROJECT'."
|
|
||||||
true
|
|
||||||
|
|
||||||
# 4. Critical: GitHub remote connectivity
|
|
||||||
run_check "GitHub remote reachable"
|
|
||||||
"git ls-remote --exit-code origin >/dev/null 2>&1"
|
|
||||||
"Cannot connect to git remote 'origin'."
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# 5. Non-critical: Secret Manager access
|
run_check "GitHub remote reachable" \
|
||||||
run_check "Secret Manager access (test read)"
|
"git -C '$OSVAUCO_DIR' ls-remote --exit-code origin" \
|
||||||
"gcloud secrets versions access latest --secret=github-token --project=$GOOGLE_CLOUD_PROJECT >/dev/null"
|
"Cannot reach git remote origin" \
|
||||||
"Could not access secrets. Check IAM permissions for Secret Manager."
|
true
|
||||||
|
|
||||||
|
run_check "Secret Manager readable" \
|
||||||
|
"gcloud secrets versions access latest --secret=github-token --project=$GOOGLE_CLOUD_PROJECT" \
|
||||||
|
"Check IAM permissions for Secret Manager"
|
||||||
|
|
||||||
|
run_check "Git working tree clean" \
|
||||||
|
"git -C '$OSVAUCO_DIR' diff --quiet && git -C '$OSVAUCO_DIR' diff --cached --quiet" \
|
||||||
|
"Uncommitted changes present"
|
||||||
|
|
||||||
|
# Cloud Run health — bruk osvauco-agent (ikke opax-mcp-core)
|
||||||
|
SERVICE_URL=$(gcloud run services describe osvauco-agent \
|
||||||
|
--region "$GOOGLE_CLOUD_LOCATION" \
|
||||||
|
--project "$GOOGLE_CLOUD_PROJECT" \
|
||||||
|
--format="value(status.url)" 2>/dev/null || echo "")
|
||||||
|
|
||||||
# 6. Non-critical: Git repository is clean
|
|
||||||
run_check "Git status is clean"
|
|
||||||
"git diff --quiet && git diff --cached --quiet"
|
|
||||||
"You have uncommitted changes in your repository."
|
|
||||||
|
|
||||||
# 7. Non-critical: Cloud Run service health
|
|
||||||
SERVICE_URL=$(gcloud run services describe opax-mcp-core --region "$GOOGLE_CLOUD_LOCATION" --project "$GOOGLE_CLOUD_PROJECT" --format="value(status.url)" 2>/dev/null || echo "")
|
|
||||||
if [[ -n "$SERVICE_URL" ]]; then
|
if [[ -n "$SERVICE_URL" ]]; then
|
||||||
run_check "Cloud Run service 'opax-mcp-core' healthy"
|
TOKEN=$(gcloud auth print-identity-token 2>/dev/null || echo "")
|
||||||
"curl -s -f -H "Authorization: Bearer \$(gcloud auth print-identity-token)" "${SERVICE_URL}/health""
|
run_check "Cloud Run osvauco-agent healthy" \
|
||||||
"The 'opax-mcp-core' service is not responding correctly."
|
"curl -sf -H 'Authorization: Bearer ${TOKEN}' '${SERVICE_URL}/health'" \
|
||||||
|
"Service ikke tilgjengelig — sjekk Cloud Run"
|
||||||
else
|
else
|
||||||
printf " %-35s" "Cloud Run service 'opax-mcp-core' healthy"
|
printf " %-40s${YELLOW}SKIP${NC}\n" "Cloud Run osvauco-agent healthy"
|
||||||
printf "${YELLOW}SKIP${NC}
|
printf " ${DIM}Service ikke funnet i $GOOGLE_CLOUD_LOCATION${NC}\n"
|
||||||
"
|
|
||||||
printf " ${DIM}Warning: Service 'opax-mcp-core' not found or URL could not be retrieved.${NC}
|
|
||||||
"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "
|
printf "\n${GREEN}${BOLD}✅ OPAX klar.${NC}\n\n"
|
||||||
${GREEN}All critical checks passed. OPAX environment is ready.${NC}
|
|
||||||
|
|
||||||
"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# --- Miljø og prompt ---
|
||||||
|
cd "$OSVAUCO_DIR" 2>/dev/null || true
|
||||||
|
|
||||||
# --- Set Environment ---
|
export PS1="\[${GREEN}\]┌──(\[${CYAN}\]OPAX:\[${BOLD}\]\w\[${NC}\])\[${NC}\]\n\[${GREEN}\]└─▪\[${NC}\] "
|
||||||
# Ensure we are in the project directory
|
|
||||||
cd "$OSVAUCO_DIR" || return
|
|
||||||
|
|
||||||
# Set a custom, identifiable prompt
|
|
||||||
export PS1="\[${GREEN}\]┌──(${CYAN}OPAX:${BOLD}\w${NC})\[${NC}\]
|
|
||||||
\[${GREEN}\]└─▪\[${NC}\] "
|
|
||||||
|
|
||||||
# --- Finalization ---
|
|
||||||
# Mark as loaded to prevent re-running the banner and checks
|
|
||||||
export OPAX_LOADED=true
|
export OPAX_LOADED=true
|
||||||
|
|
||||||
# Display quick commands only on the first load in a session
|
|
||||||
if [[ -z "${OPAX_COMMANDS_SHOWN-}" ]]; then
|
if [[ -z "${OPAX_COMMANDS_SHOWN-}" ]]; then
|
||||||
printf "${BOLD}${WHITE}QUICK COMMANDS${NC}
|
printf "${BOLD}${WHITE}QUICK COMMANDS${NC}\n"
|
||||||
"
|
printf " ${GREEN}%-8s${NC} %s\n" "ca" "cost-audit"
|
||||||
printf " ${GREEN}%-15s${NC} %s
|
printf " ${GREEN}%-8s${NC} %s\n" "cl" "cost-lens"
|
||||||
" "opax" "Reload this environment script"
|
printf " ${GREEN}%-8s${NC} %s\n" "st" "smoke-test"
|
||||||
printf " ${GREEN}%-15s${NC} %s
|
printf " ${GREEN}%-8s${NC} %s\n" "hc" "health-check"
|
||||||
" "cost-audit" "Run cost analysis"
|
printf " ${GREEN}%-8s${NC} %s\n" "g" "gemini"
|
||||||
printf " ${GREEN}%-15s${NC} %s
|
printf " ${GREEN}%-8s${NC} %s\n" "sol" "avslutt"
|
||||||
" "smoke-test" "Run API smoke tests"
|
printf "\n"
|
||||||
printf " ${GREEN}%-15s${NC} %s
|
|
||||||
" "g" "Start the Gemini CLI"
|
|
||||||
printf "
|
|
||||||
"
|
|
||||||
export OPAX_COMMANDS_SHOWN=true
|
export OPAX_COMMANDS_SHOWN=true
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user