This commit is contained in:
Ho Ngoc Hai
2026-05-23 18:37:02 +07:00
parent f15d91ee29
commit 76d75c753b
3993 changed files with 403 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#!/bin/bash
SERVICE=$1
MODE=$2
# EN: Check usage
# VI: Kiểm tra cách sử dụng
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name>"
echo "Example: $0 iam-service"
echo "Example: $0 mission-service-net"
exit 1
fi
if [ "$SERVICE" = "docker" ]; then
# Legacy support: ./logs.sh docker <name>
CONTAINER=$2
if [ -z "$CONTAINER" ]; then
docker ps --format "{{.Names}}"
exit 1
fi
docker logs -f "$CONTAINER"
exit 0
fi
# Smart Detection
# Try to find a docker container that Matches or Contains the service name
# Common prefixes/suffixes: -local, goodgo-, etc.
# 1. Exact match
if docker ps --format "{{.Names}}" | grep -q "^${SERVICE}$"; then
echo "📦 Found exact container match. Tailing logs..."
docker logs -f "$SERVICE"
exit 0
fi
# 2. Local suffix match (e.g. service-name-local, -net-local)
SUFFIX_MATCH="${SERVICE}-local"
if docker ps --format "{{.Names}}" | grep -q "${SUFFIX_MATCH}"; then
echo "📦 Found container: $SUFFIX_MATCH"
docker logs -f "$SUFFIX_MATCH"
exit 0
fi
# 3. Fuzzy match (head -n 1)
FUZZY=$(docker ps --format "{{.Names}}" | grep "$SERVICE" | head -n 1)
if [ -n "$FUZZY" ]; then
echo "📦 Found fuzzy match: $FUZZY"
docker logs -f "$FUZZY"
exit 0
fi
# 4. If no docker container found, and it's a Node app, maybe user wants pnpm log?
# But typically we don't use this script for local pnpm unless wrapped.
echo "❌ No running container found for $SERVICE."
echo " If you are running it locally (non-Docker), check the terminal window where you started it."

View File

@@ -0,0 +1,106 @@
#!/bin/bash
# Setup Environment Variables for Development
# Thiết lập Environment Variables cho Development
set -e
echo "🔧 Setting up environment variables..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# EN: Check if we're in the project root
# VI: Kiểm tra xem có đang ở root project không
if [ ! -f "package.json" ]; then
echo -e "${RED}❌ Error: Must run from project root / Lỗi: Phải chạy từ root project${NC}"
exit 1
fi
# EN: Setup shared environment
# VI: Thiết lập môi trường chia sẻ
echo ""
echo "📦 Step 1: Setup shared environment (deployments/local/.env.local)"
if [ -f "deployments/local/.env.local" ]; then
echo -e "${YELLOW}⚠️ deployments/local/.env.local already exists / đã tồn tại${NC}"
read -p "Overwrite? (y/n): / Ghi đè? (y/n): " overwrite
if [ "$overwrite" != "y" ]; then
echo "Skipping shared environment setup / Bỏ qua thiết lập môi trường chia sẻ"
else
cp deployments/local/env.local.example deployments/local/.env.local
echo -e "${GREEN}✅ Created deployments/local/.env.local${NC}"
fi
else
cp deployments/local/env.local.example deployments/local/.env.local
echo -e "${GREEN}✅ Created deployments/local/.env.local${NC}"
fi
# EN: Setup service-specific environments
# VI: Thiết lập môi trường cụ thể cho từng service
echo ""
echo "📦 Step 2: Setup service-specific environments"
# EN: Function to setup service env
# VI: Hàm để setup env cho service
setup_service_env() {
local service=$1
local service_path="services/$service"
if [ ! -d "$service_path" ]; then
echo -e "${YELLOW}⚠️ Service $service not found, skipping${NC}"
return
fi
if [ -f "$service_path/.env.local" ]; then
echo -e "${YELLOW}⚠️ $service_path/.env.local already exists, skipping${NC}"
else
if [ -f "$service_path/env.local.example" ]; then
cp "$service_path/env.local.example" "$service_path/.env.local"
echo -e "${GREEN}✅ Created $service_path/.env.local${NC}"
else
echo -e "${YELLOW}⚠️ $service_path/env.local.example not found, skipping${NC}"
fi
fi
}
# Setup for all services
for service_dir in services/*/; do
if [ -d "$service_dir" ]; then
service_name=$(basename "$service_dir")
if [ "$service_name" != "_template" ]; then
setup_service_env "$service_name"
fi
fi
done
# Summary
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${GREEN}✅ Environment setup complete!${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📝 Next steps:"
echo ""
echo "1. Edit deployments/local/.env.local:"
echo " - Set JWT_SECRET and JWT_REFRESH_SECRET"
echo ""
echo "2. Edit services/<service>/.env.local for each service:"
echo " - Set DATABASE_URL from Neon Console"
echo " - Each service needs its own database"
echo ""
echo "3. Create databases in Neon:"
echo " - goodgo_iam_dev (for iam-service)"
echo " - goodgo_user_dev (for user-service)"
echo " - etc."
echo ""
echo "4. Run migrations:"
echo " ./scripts/db/migrate.sh iam-service dev"
echo ""
echo "5. Start development:"
echo " ./scripts/dev/start-all.sh"
echo ""
echo "📚 See docs/vi/guides/local-development.md for details"
echo ""

View File

@@ -0,0 +1,59 @@
#!/bin/bash
# EN: Script to start all services in development environment
# VI: Script để khởi động tất cả services trong môi trường development
set -e
# Source OS helper for cross-platform commands
source "$(dirname "$0")/../utils/os-helper.sh"
echo "🚀 Starting all services... / Khởi động tất cả services..."
# EN: Verify Docker daemon is running
# VI: Xác minh Docker daemon đang chạy
if ! docker info &> /dev/null; then
echo "❌ Docker is not running. Please start Docker first. / Docker không chạy. Vui lòng khởi động Docker trước."
exit 1
fi
# EN: Load environment variables from shared config
# VI: Load biến môi trường từ shared config
if [ -f "deployments/local/.env.local" ]; then
export $(grep -v '^#' deployments/local/.env.local | xargs)
fi
# EN: Check if DATABASE_URL is configured (required for services)
# VI: Kiểm tra DATABASE_URL có được cấu hình không (bắt buộc cho services)
if [ -z "$DATABASE_URL" ]; then
echo "⚠️ WARNING: DATABASE_URL not set! / CẢNH BÁO: DATABASE_URL chưa được thiết lập!"
echo " Please setup Neon database: ./scripts/db/setup-neon.sh"
echo " Or set DATABASE_URL in deployments/local/.env.local"
echo " / Vui lòng thiết lập Neon database: ./scripts/db/setup-neon.sh"
echo " Hoặc đặt DATABASE_URL trong deployments/local/.env.local"
echo ""
read -p "Continue anyway? (y/n): / Tiếp tục? (y/n): " continue
if [ "$continue" != "y" ]; then
exit 1
fi
fi
# EN: Start infrastructure services and .NET backends
# VI: Khởi động infrastructure services và .NET backends
echo "📦 Starting Docker containers (Infra + .NET Services)..."
cd deployments/local
run_compose up -d
cd ../..
# EN: Give Redis time to fully start
# VI: Cho Redis thời gian để khởi động đầy đủ
echo "⏳ Waiting for services to stabilize..."
sleep 5
# EN: Start Node.js apps/services using pnpm dev
# VI: Khởi động Node.js apps/services sử dụng pnpm dev
echo "🚀 Starting Node.js apps (Frontend/BFF)..."
if command -v pnpm &> /dev/null; then
pnpm dev
else
echo "⚠️ pnpm not found. Only Docker services are running."
fi

View File

@@ -0,0 +1,165 @@
#!/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

View File

@@ -0,0 +1,87 @@
#!/bin/bash
# =============================================================================
# Start Single Service (Polyglot)
# =============================================================================
set -e
SERVICE=$1
# EN: Validate arguments
# VI: Xác thực tham số
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name>"
echo "Example: $0 iam-service"
exit 1
fi
echo "🚀 Starting $SERVICE..."
# EN: Check if service exists
# VI: Kiểm tra xem service có tồn tại không
SERVICE_PATH="services/$SERVICE"
if [ ! -d "$SERVICE_PATH" ]; then
echo "❌ Service $SERVICE not found in services/"
exit 1
fi
cd "$SERVICE_PATH"
STARTED=false
# 1. Check for Node.js (package.json)
if [ -f "package.json" ]; then
echo " 📦 Starting Node.js service..."
pnpm dev
STARTED=true
fi
# 2. Check for .NET
# If it's a .NET service, we prefer `dotnet watch run` for hot reload
if [ -f *.sln ] || compgen -G "*.sln" > /dev/null || \
[ -f *.csproj ] || compgen -G "src/*.sln" > /dev/null; then
echo " 📦 Starting .NET service with Hot Reload..."
# Needs env vars? Often yes.
# Load env vars from deployments/local/.env.local if not already set?
# Usually .NET appsettings.Development.json handles this, or we export from .env.local
# Attempt to load .env.local from root
if [ -f "../../deployments/local/.env.local" ]; then
echo " Loading environment variables from deployments/local/.env.local"
export $(grep -v '^#' ../../deployments/local/.env.local | xargs)
fi
TARGET_RUN="."
if [ -d "src" ] && compgen -G "src/*.sln" > /dev/null; then
# Usually we want to run the API project specifically, not the solution (dotnet run works on project, or solution if single run project)
# Finding the API project is tricky without hardcoding.
# Assume pattern: ServiceName.API or just src/
# Try to find a csproj in src that ends with API.csproj or Service.csproj
API_PROJECT=$(find src -name "*.API.csproj" | head -n 1)
if [ -z "$API_PROJECT" ]; then
API_PROJECT=$(find src -name "*.csproj" | grep -v "Domain" | grep -v "Infrastructure" | head -n 1)
fi
if [ -n "$API_PROJECT" ]; then
# We need to run from the project directory or pass --project
TARGET_RUN="$API_PROJECT"
else
TARGET_RUN="src"
fi
elif [ -d "src" ]; then
TARGET_RUN="src"
fi
echo " 👉 Running project: $TARGET_RUN"
dotnet watch run --project "$TARGET_RUN"
STARTED=true
fi
if [ "$STARTED" = false ]; then
echo "❌ Could not determine how to start $SERVICE (no package.json or .sln found)"
exit 1
fi