This commit is contained in:
Ho Ngoc Hai
2025-12-27 01:31:10 +07:00
commit 4da46b5b8e
205 changed files with 21063 additions and 0 deletions

26
scripts/dev/logs.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
SERVICE=$1
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name>"
echo "Example: $0 auth-service"
echo ""
echo "Or use 'docker' to view Docker logs:"
echo " $0 docker <container-name>"
exit 1
fi
if [ "$SERVICE" = "docker" ]; then
CONTAINER=$2
if [ -z "$CONTAINER" ]; then
echo "Usage: $0 docker <container-name>"
echo "Available containers:"
docker ps --format "{{.Names}}"
exit 1
fi
docker logs -f "$CONTAINER"
else
cd "services/$SERVICE"
pnpm dev
fi

102
scripts/dev/setup-env.sh Executable file
View File

@@ -0,0 +1,102 @@
#!/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
# Check if we're in the project root
if [ ! -f "package.json" ]; then
echo -e "${RED}❌ Error: Must run from project root${NC}"
exit 1
fi
# Setup shared environment
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${NC}"
read -p "Overwrite? (y/n): " overwrite
if [ "$overwrite" != "y" ]; then
echo "Skipping shared environment setup"
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
# Setup service-specific environments
echo ""
echo "📦 Step 2: Setup service-specific environments"
# Function to setup service env
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_auth_dev (for auth-service)"
echo " - goodgo_user_dev (for user-service)"
echo " - etc."
echo ""
echo "4. Run migrations:"
echo " ./scripts/db/migrate.sh auth-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 ""

41
scripts/dev/start-all.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
set -e
echo "🚀 Starting all services..."
# Check if Docker is running
if ! docker info &> /dev/null; then
echo "❌ Docker is not running. Please start Docker first."
exit 1
fi
# Check if Neon DATABASE_URL is set
if [ -f "deployments/local/.env.local" ]; then
export $(grep -v '^#' deployments/local/.env.local | xargs)
fi
if [ -z "$DATABASE_URL" ]; then
echo "⚠️ WARNING: DATABASE_URL not set!"
echo " Please setup Neon database: ./scripts/db/setup-neon.sh"
echo " Or set DATABASE_URL in deployments/local/.env.local"
echo ""
read -p "Continue anyway? (y/n): " continue
if [ "$continue" != "y" ]; then
exit 1
fi
fi
# Start infrastructure (Redis, Traefik - no PostgreSQL needed)
echo "📦 Starting infrastructure (Redis, Traefik)..."
cd deployments/local
docker-compose up -d
cd ../..
# Wait for Redis to be ready
echo "⏳ Waiting for Redis to be ready..."
sleep 3
# Start services
echo "🚀 Starting services..."
pnpm dev

22
scripts/dev/start-service.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -e
SERVICE=$1
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name>"
echo "Example: $0 auth-service"
exit 1
fi
echo "🚀 Starting $SERVICE..."
# Check if service exists
if [ ! -d "services/$SERVICE" ]; then
echo "❌ Service $SERVICE not found"
exit 1
fi
cd "services/$SERVICE"
pnpm dev