#!/bin/bash # deploy-test-env.sh — Deploy test-env to dev cluster and verify # # Usage: # bash dev/deploy-test-env.sh [--check-only] [--create-secrets] # # Prerequisites: # - kubectl configured for dev cluster # - Images benadis/pg-1c:18.1-2.1C and benadis/ar-edt:6.2.27.1 accessible # # This script: # 1. Validates kustomize build # 2. Applies manifests via kustomize # 3. Creates secrets if --create-secrets # 4. Waits for pods to be ready # 5. Runs smoke tests (pg_isready, ragent check) set -euo pipefail cd "$(dirname "$0")/.." RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' CHECK_ONLY=false CREATE_SECRETS=false for arg in "$@"; do case $arg in --check-only) CHECK_ONLY=true ;; --create-secrets) CREATE_SECRETS=true ;; esac done echo "=== test-env deployment ===" # --- Step 1: Validate kustomize --- echo -e "\n${YELLOW}[1/5] Validating kustomize build...${NC}" if kubectl kustomize test-env/ > /dev/null 2>&1; then echo -e "${GREEN} ✓ kustomize build OK${NC}" else echo -e "${RED} ✗ kustomize build FAILED${NC}" kubectl kustomize test-env/ 2>&1 | head -20 exit 1 fi if $CHECK_ONLY; then echo -e "\n${GREEN}Validation passed (--check-only)${NC}" kubectl kustomize test-env/ | grep -c 'kind:' | xargs -I{} echo " {} resources" exit 0 fi # --- Step 2: Apply manifests --- echo -e "\n${YELLOW}[2/5] Applying manifests...${NC}" kubectl apply -k test-env/ echo -e "${GREEN} ✓ Manifests applied${NC}" # --- Step 3: Create secrets if needed --- if $CREATE_SECRETS; then echo -e "\n${YELLOW}[3/5] Creating secrets...${NC}" kubectl -n test-env create secret generic test-env-secrets \ --from-literal=pg-password=usr1cv8 \ --dry-run=client -o yaml | kubectl apply -f - echo -e "${GREEN} ✓ Secrets created${NC}" else echo -e "\n${YELLOW}[3/5] Checking secrets...${NC}" if kubectl -n test-env get secret test-env-secrets > /dev/null 2>&1; then echo -e "${GREEN} ✓ test-env-secrets exists${NC}" else echo -e "${RED} ✗ test-env-secrets missing — run with --create-secrets${NC}" fi fi # --- Step 4: Wait for pods --- echo -e "\n${YELLOW}[4/5] Waiting for pods (timeout 120s)...${NC}" wait_for_pod() { local label=$1 local timeout=${2:-120} local start=$(date +%s) while true; do local phase=$(kubectl -n test-env get pods -l "$label" -o jsonpath='{.items[0].status.phase}' 2>/dev/null || echo "Pending") if [ "$phase" = "Running" ]; then echo -e "${GREEN} ✓ $label → Running${NC}" return 0 fi local elapsed=$(( $(date +%s) - start )) if [ $elapsed -gt $timeout ]; then echo -e "${RED} ✗ $label → $phase (timeout ${timeout}s)${NC}" return 1 fi sleep 5 done } wait_for_pod "app=test-pg" 120 wait_for_pod "app=onec-server" 120 # --- Step 5: Smoke tests --- echo -e "\n${YELLOW}[5/5] Smoke tests...${NC}" # PostgreSQL ready PG_POD=$(kubectl -n test-env get pod -l app=test-pg -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "") if [ -n "$PG_POD" ]; then if kubectl -n test-env exec "$PG_POD" -- su - postgres -c "/usr/lib/postgresql/18/bin/pg_isready" > /dev/null 2>&1; then echo -e "${GREEN} ✓ PostgreSQL is ready${NC}" else echo -e "${RED} ✗ PostgreSQL pg_isready failed${NC}" fi fi # 1C server ragent running ONEC_POD=$(kubectl -n test-env get pod -l app=onec-server -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "") if [ -n "$ONEC_POD" ]; then if kubectl -n test-env exec "$ONEC_POD" -- pgrep ragent > /dev/null 2>&1; then echo -e "${GREEN} ✓ ragent is running${NC}" else echo -e "${RED} ✗ ragent not running${NC}" fi if kubectl -n test-env exec "$ONEC_POD" -- pgrep crserver > /dev/null 2>&1; then echo -e "${GREEN} ✓ crserver is running${NC}" else echo -e "${RED} ✗ crserver not running${NC}" fi fi # Summary echo -e "\n=== Status ===" kubectl -n test-env get pods -o wide echo "" kubectl -n test-env get svc echo "" kubectl -n test-env get pvc