refactor: reorganize project structure for better maintainability

- Move Docker files to build/docker/
- Move CI/CD configs to build/ci/
- Move deployment configs to deploy/ (helm, k8s, argocd)
- Move config files to config/
- Move scripts to tools/
- Consolidate assets to assets/ (Reflex compatible)
- Add data/ directory for local data (gitignored)
- Update all path references in Makefile, Dockerfile, CI configs
- Add comprehensive README files for build/ and deploy/
- Update project documentation

Benefits:
- Clear separation of concerns
- Cleaner root directory
- Better developer experience
- Enterprise-grade structure
- Improved maintainability
This commit is contained in:
Ehsan.Asadi
2025-12-30 21:20:32 +03:30
parent 954387a8cf
commit 6820f0ee4f
45 changed files with 1737 additions and 361 deletions

126
tools/scripts/diagnose-502.sh Executable file
View File

@@ -0,0 +1,126 @@
#!/bin/bash
# Diagnostic script for 502 Bad Gateway error
set -e
NAMESPACE=${1:-production}
APP_NAME="peikarband"
echo "🔍 Diagnosing 502 Bad Gateway for $APP_NAME in namespace $NAMESPACE"
echo "=========================================="
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# 1. Check Pods
echo "1⃣ Checking Pods..."
echo "-------------------"
PODS=$(kubectl get pods -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME --no-headers 2>/dev/null || echo "")
if [ -z "$PODS" ]; then
echo -e "${RED}❌ No pods found!${NC}"
exit 1
fi
kubectl get pods -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME
echo ""
# Check pod status
POD_STATUS=$(kubectl get pods -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME -o jsonpath='{.items[0].status.phase}' 2>/dev/null || echo "Unknown")
POD_NAME=$(kubectl get pods -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
if [ "$POD_STATUS" != "Running" ]; then
echo -e "${RED}❌ Pod is not Running! Status: $POD_STATUS${NC}"
echo ""
echo "Pod events:"
kubectl describe pod -n $NAMESPACE $POD_NAME | tail -20
echo ""
fi
# 2. Check Service
echo "2⃣ Checking Service..."
echo "----------------------"
kubectl get svc -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME
echo ""
# 3. Check Ingress
echo "3⃣ Checking Ingress..."
echo "-----------------------"
kubectl get ingress -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME
echo ""
# 4. Check Pod Logs
if [ -n "$POD_NAME" ]; then
echo "4⃣ Recent Pod Logs (last 30 lines)..."
echo "--------------------------------------"
kubectl logs -n $NAMESPACE $POD_NAME --tail=30 || echo "Could not fetch logs"
echo ""
fi
# 5. Check Readiness/Liveness
if [ -n "$POD_NAME" ]; then
echo "5⃣ Checking Probe Status..."
echo "----------------------------"
READY=$(kubectl get pod -n $NAMESPACE $POD_NAME -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null || echo "Unknown")
echo "Ready: $READY"
# Check container status
CONTAINER_STATUS=$(kubectl get pod -n $NAMESPACE $POD_NAME -o jsonpath='{.status.containerStatuses[0].ready}' 2>/dev/null || echo "Unknown")
echo "Container Ready: $CONTAINER_STATUS"
echo ""
fi
# 6. Test from inside pod
if [ -n "$POD_NAME" ] && [ "$POD_STATUS" == "Running" ]; then
echo "6⃣ Testing /ping endpoint from inside pod..."
echo "---------------------------------------------"
kubectl exec -n $NAMESPACE $POD_NAME -- curl -s http://localhost:8000/ping || echo -e "${RED}❌ /ping failed!${NC}"
echo ""
fi
# 7. Check Service Endpoints
echo "7⃣ Checking Service Endpoints..."
echo "---------------------------------"
SVC_NAME=$(kubectl get svc -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
if [ -n "$SVC_NAME" ]; then
kubectl get endpoints -n $NAMESPACE $SVC_NAME
ENDPOINTS=$(kubectl get endpoints -n $NAMESPACE $SVC_NAME -o jsonpath='{.subsets[0].addresses[*].ip}' 2>/dev/null || echo "")
if [ -z "$ENDPOINTS" ]; then
echo -e "${RED}❌ No endpoints! Service cannot route traffic.${NC}"
echo "This is likely because readiness probe is failing."
fi
echo ""
fi
# 8. Check Resources
if [ -n "$POD_NAME" ]; then
echo "8⃣ Checking Resource Usage..."
echo "------------------------------"
kubectl top pod -n $NAMESPACE $POD_NAME 2>/dev/null || echo "Metrics not available"
echo ""
fi
# 9. Check Events
echo "9⃣ Recent Events..."
echo "-------------------"
kubectl get events -n $NAMESPACE --sort-by='.lastTimestamp' | grep $APP_NAME | tail -10 || echo "No recent events"
echo ""
# 10. NetworkPolicy check
echo "🔟 Checking NetworkPolicy..."
echo "---------------------------"
kubectl get networkpolicy -n $NAMESPACE -l app.kubernetes.io/name=$APP_NAME || echo "No NetworkPolicy found"
echo ""
echo "=========================================="
echo "✅ Diagnosis complete!"
echo ""
echo "Common fixes:"
echo "1. If pod is CrashLoopBackOff: Check logs and resource limits"
echo "2. If no endpoints: Readiness probe is failing - check /ping endpoint"
echo "3. If NetworkPolicy exists: Check if it allows ingress traffic"
echo "4. If resources exhausted: Increase limits in values-production.yaml"