166 lines
5.9 KiB
Bash
Executable File
166 lines
5.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# GoodGo Platform - Start Dev Infrastructure
|
|
# =============================================================================
|
|
# EN: Starts lightweight local infra (Redis + RabbitMQ) and verifies remote
|
|
# connections (PostgreSQL + MinIO). No need to run full docker-compose.
|
|
# VI: Khởi động infra local nhẹ (Redis + RabbitMQ) và kiểm tra kết nối
|
|
# remote (PostgreSQL + MinIO). Không cần chạy docker-compose đầy đủ.
|
|
#
|
|
# Usage:
|
|
# ./scripts/dev/start-dev.sh # Start infra + check connections
|
|
# ./scripts/dev/start-dev.sh stop # Stop local containers
|
|
# ./scripts/dev/start-dev.sh status # Check status
|
|
# =============================================================================
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
COMPOSE_FILE="$PROJECT_ROOT/deployments/local/docker-compose.dev.yml"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
print_header() {
|
|
echo ""
|
|
echo -e "${BLUE}═══════════════════════════════════════════════════${NC}"
|
|
echo -e "${BLUE} GoodGo Platform - Dev Infrastructure${NC}"
|
|
echo -e "${BLUE}═══════════════════════════════════════════════════${NC}"
|
|
echo ""
|
|
}
|
|
|
|
check_remote_pg() {
|
|
echo -e "${YELLOW}[PostgreSQL]${NC} Testing remote connection (212.28.186.239:30992)..."
|
|
if nc -z -w3 212.28.186.239 30992 2>/dev/null; then
|
|
echo -e " ${GREEN}✓${NC} PostgreSQL remote is reachable"
|
|
return 0
|
|
else
|
|
echo -e " ${RED}✗${NC} PostgreSQL remote is NOT reachable"
|
|
echo -e " ${RED} Check your network / VPN connection${NC}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
check_remote_minio() {
|
|
echo -e "${YELLOW}[MinIO]${NC} Testing remote connection (minio.techbi.org)..."
|
|
if nc -z -w3 minio.techbi.org 443 2>/dev/null; then
|
|
echo -e " ${GREEN}✓${NC} MinIO remote is reachable"
|
|
return 0
|
|
else
|
|
echo -e " ${RED}✗${NC} MinIO remote is NOT reachable"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
check_local_redis() {
|
|
echo -e "${YELLOW}[Redis]${NC} Testing local connection (localhost:16379)..."
|
|
if nc -z -w3 localhost 16379 2>/dev/null; then
|
|
echo -e " ${GREEN}✓${NC} Redis local is running"
|
|
return 0
|
|
else
|
|
echo -e " ${RED}✗${NC} Redis local is NOT running"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
check_local_rabbitmq() {
|
|
echo -e "${YELLOW}[RabbitMQ]${NC} Testing local connection (localhost:25672)..."
|
|
if nc -z -w3 localhost 25672 2>/dev/null; then
|
|
echo -e " ${GREEN}✓${NC} RabbitMQ local is running"
|
|
return 0
|
|
else
|
|
echo -e " ${RED}✗${NC} RabbitMQ local is NOT running"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
start_infra() {
|
|
print_header
|
|
|
|
echo -e "${BLUE}Starting local containers (Redis + RabbitMQ)...${NC}"
|
|
docker compose -f "$COMPOSE_FILE" up -d
|
|
echo ""
|
|
|
|
# Wait for containers to be healthy
|
|
echo -e "${BLUE}Waiting for containers to be ready...${NC}"
|
|
sleep 3
|
|
|
|
echo ""
|
|
echo -e "${BLUE}Checking all connections:${NC}"
|
|
echo ""
|
|
|
|
local all_ok=true
|
|
check_remote_pg || all_ok=false
|
|
check_remote_minio || all_ok=false
|
|
check_local_redis || all_ok=false
|
|
check_local_rabbitmq || all_ok=false
|
|
|
|
echo ""
|
|
if [ "$all_ok" = true ]; then
|
|
echo -e "${GREEN}═══════════════════════════════════════════════════${NC}"
|
|
echo -e "${GREEN} All infrastructure is ready!${NC}"
|
|
echo -e "${GREEN}═══════════════════════════════════════════════════${NC}"
|
|
else
|
|
echo -e "${YELLOW}═══════════════════════════════════════════════════${NC}"
|
|
echo -e "${YELLOW} Some connections failed. Check above for details.${NC}"
|
|
echo -e "${YELLOW}═══════════════════════════════════════════════════${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}Infrastructure endpoints:${NC}"
|
|
echo -e " PostgreSQL : ${GREEN}212.28.186.239:30992${NC} (remote)"
|
|
echo -e " MinIO : ${GREEN}minio.techbi.org${NC} (remote, HTTPS)"
|
|
echo -e " Redis : ${GREEN}localhost:16379${NC} (local)"
|
|
echo -e " RabbitMQ : ${GREEN}localhost:25672${NC} (local, UI: localhost:35672)"
|
|
echo ""
|
|
echo -e "${BLUE}Run a service:${NC}"
|
|
echo -e " cd services/iam-service-net/src/IamService.API"
|
|
echo -e " dotnet run"
|
|
echo ""
|
|
echo -e "${BLUE}Service ports:${NC}"
|
|
echo -e " IAM Service : http://localhost:5001"
|
|
echo -e " Storage Service : http://localhost:5002"
|
|
echo -e " Wallet Service : http://localhost:5003"
|
|
echo -e " Merchant Service: http://localhost:5005"
|
|
echo ""
|
|
}
|
|
|
|
stop_infra() {
|
|
echo -e "${BLUE}Stopping local containers...${NC}"
|
|
docker compose -f "$COMPOSE_FILE" down
|
|
echo -e "${GREEN}Done.${NC}"
|
|
}
|
|
|
|
show_status() {
|
|
print_header
|
|
echo -e "${BLUE}Container status:${NC}"
|
|
docker compose -f "$COMPOSE_FILE" ps 2>/dev/null || echo " No containers running"
|
|
echo ""
|
|
echo -e "${BLUE}Connection checks:${NC}"
|
|
check_remote_pg
|
|
check_remote_minio
|
|
check_local_redis
|
|
check_local_rabbitmq
|
|
}
|
|
|
|
case "${1:-start}" in
|
|
start)
|
|
start_infra
|
|
;;
|
|
stop)
|
|
stop_infra
|
|
;;
|
|
status)
|
|
show_status
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|status}"
|
|
exit 1
|
|
;;
|
|
esac
|