cleanup
This commit is contained in:
parent
c353ddbe01
commit
ce9e2df67c
310 changed files with 2550 additions and 36861 deletions
|
|
@ -1,51 +1,50 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Trading Bot Docker Management Script
|
||||
# Trading Bot Docker Management Script (dev / qa / prod)
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
GRAY='\033[0;37m'
|
||||
NC='\033[0m' # No Color
|
||||
NC='\033[0m'
|
||||
|
||||
# Default options
|
||||
ACTION=""
|
||||
SERVICE=""
|
||||
DEV=false
|
||||
TARGET_ENV="dev"
|
||||
|
||||
show_help() {
|
||||
echo ""
|
||||
echo -e "${GREEN}🤖 Trading Bot Docker Management${NC}"
|
||||
echo -e "${GREEN}🤖 Stock Bot Docker Management${NC}"
|
||||
echo ""
|
||||
echo -e "${CYAN}Usage: $0 <action> [options]${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Actions:${NC}"
|
||||
echo " start Start infrastructure services"
|
||||
echo " stop Stop infrastructure services"
|
||||
echo " stop Stop infrastructure services"
|
||||
echo " restart Restart infrastructure services"
|
||||
echo " status Show service status"
|
||||
echo " logs Show service logs"
|
||||
echo " reset Reset all data (destructive)"
|
||||
echo " admin Start admin interfaces"
|
||||
echo " monitoring Start monitoring stack"
|
||||
echo " reset Reset dev data only (blocked on qa/prod)"
|
||||
echo " admin Start QA admin interfaces (pgadmin, redis-insight)"
|
||||
echo " monitoring Start QA monitoring stack (prometheus, grafana, loki)"
|
||||
echo " help Show this help"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Options:${NC}"
|
||||
echo " --service <name> Specify a specific service"
|
||||
echo " --dev Use development configuration"
|
||||
echo -e "${YELLOW}Environments (default: dev):${NC}"
|
||||
echo " --dev, -d Isolated local dev stack (docker-compose.dev.yml; ports 5433/27018/6380/9100)"
|
||||
echo " --qa Existing QA stack (docker-compose.yml; ports 5432/27017/6379/9000)"
|
||||
echo " --prod Production template (docker-compose.prod.yml; requires .env.prod)"
|
||||
echo " --env <dev|qa|prod> Explicit environment selector"
|
||||
echo " --service, -s <name> Target a single service"
|
||||
echo ""
|
||||
echo -e "${CYAN}Examples:${NC}"
|
||||
echo " $0 start"
|
||||
echo " $0 start --dev"
|
||||
echo " $0 logs --service dragonfly"
|
||||
echo " $0 admin"
|
||||
echo " $0 status --qa"
|
||||
echo " $0 logs --dev --service postgres"
|
||||
echo " $0 reset --dev"
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
start|stop|restart|status|logs|reset|admin|monitoring|help)
|
||||
|
|
@ -57,9 +56,21 @@ while [[ $# -gt 0 ]]; do
|
|||
shift 2
|
||||
;;
|
||||
--dev|-d)
|
||||
DEV=true
|
||||
TARGET_ENV="dev"
|
||||
shift
|
||||
;;
|
||||
--qa)
|
||||
TARGET_ENV="qa"
|
||||
shift
|
||||
;;
|
||||
--prod)
|
||||
TARGET_ENV="prod"
|
||||
shift
|
||||
;;
|
||||
--env|-e)
|
||||
TARGET_ENV="$2"
|
||||
shift 2
|
||||
;;
|
||||
--help|-h)
|
||||
show_help
|
||||
exit 0
|
||||
|
|
@ -78,111 +89,137 @@ if [ -z "$ACTION" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Set up compose files
|
||||
if [ "$DEV" = true ]; then
|
||||
COMPOSE_FILES=(-f docker-compose.yml -f docker-compose.dev.yml)
|
||||
else
|
||||
COMPOSE_FILES=(-f docker-compose.yml)
|
||||
fi
|
||||
case "$TARGET_ENV" in
|
||||
dev)
|
||||
COMPOSE_FILES=(-f docker-compose.dev.yml)
|
||||
CONTAINER_FILTER="stock-bot-dev"
|
||||
;;
|
||||
qa)
|
||||
COMPOSE_FILES=(-f docker-compose.yml)
|
||||
CONTAINER_FILTER="trading-bot"
|
||||
;;
|
||||
prod)
|
||||
if [ -f .env.prod ]; then
|
||||
COMPOSE_FILES=(--env-file .env.prod -f docker-compose.prod.yml)
|
||||
else
|
||||
COMPOSE_FILES=(-f docker-compose.prod.yml)
|
||||
fi
|
||||
CONTAINER_FILTER="stock-bot-prod"
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Invalid environment: $TARGET_ENV (expected dev, qa, or prod)${NC}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$ACTION" in
|
||||
"start")
|
||||
echo -e "${GREEN}🚀 Starting Trading Bot infrastructure...${NC}"
|
||||
echo -e "${GREEN}🚀 Starting Stock Bot [${TARGET_ENV}] infrastructure...${NC}"
|
||||
if [ -n "$SERVICE" ]; then
|
||||
docker compose "${COMPOSE_FILES[@]}" up -d "$SERVICE"
|
||||
else
|
||||
docker compose "${COMPOSE_FILES[@]}" up -d dragonfly postgres questdb mongodb
|
||||
fi
|
||||
echo -e "${GREEN}✅ Infrastructure started!${NC}"
|
||||
echo ""
|
||||
echo -e "${CYAN}🔗 Access Points:${NC}"
|
||||
echo " Dragonfly: localhost:6379"
|
||||
echo " PostgreSQL: localhost:5432"
|
||||
echo " QuestDB Console: http://localhost:9000"
|
||||
echo ""
|
||||
echo -e "${BLUE}💡 Use '$0 admin' to start admin interfaces${NC}"
|
||||
echo -e "${GREEN}✅ [${TARGET_ENV}] Infrastructure started!${NC}"
|
||||
if [ "$TARGET_ENV" = "dev" ]; then
|
||||
echo -e "${CYAN}🔗 Dev Access Points:${NC}"
|
||||
echo " Dragonfly: localhost:6380"
|
||||
echo " PostgreSQL: localhost:5433 (trading_bot_dev)"
|
||||
echo " MongoDB: localhost:27018 (stock_dev - ingestion writes)"
|
||||
echo " QuestDB: http://localhost:9100"
|
||||
echo " QA MongoDB: localhost:27017 (read-only via MONGODB_READ_URI for data-pipeline)"
|
||||
elif [ "$TARGET_ENV" = "qa" ]; then
|
||||
echo -e "${CYAN}🔗 QA Access Points:${NC}"
|
||||
echo " Dragonfly: localhost:6379"
|
||||
echo " PostgreSQL: localhost:5432 (trading_bot)"
|
||||
echo " MongoDB: localhost:27017 (stock)"
|
||||
echo " QuestDB: http://localhost:9000"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
"stop")
|
||||
echo -e "${YELLOW}🛑 Stopping Trading Bot infrastructure...${NC}"
|
||||
if [ "$TARGET_ENV" = "qa" ] || [ "$TARGET_ENV" = "prod" ]; then
|
||||
echo -e "${YELLOW}⚠️ Stopping [${TARGET_ENV}] containers (volumes are preserved)...${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}🛑 Stopping [${TARGET_ENV}] infrastructure...${NC}"
|
||||
fi
|
||||
if [ -n "$SERVICE" ]; then
|
||||
docker compose "${COMPOSE_FILES[@]}" stop "$SERVICE"
|
||||
else
|
||||
docker compose "${COMPOSE_FILES[@]}" down
|
||||
docker compose "${COMPOSE_FILES[@]}" stop
|
||||
fi
|
||||
echo -e "${GREEN}✅ Infrastructure stopped!${NC}"
|
||||
echo -e "${GREEN}✅ [${TARGET_ENV}] Infrastructure stopped (volumes preserved).${NC}"
|
||||
;;
|
||||
|
||||
|
||||
"restart")
|
||||
echo -e "${YELLOW}🔄 Restarting Trading Bot infrastructure...${NC}"
|
||||
echo -e "${YELLOW}🔄 Restarting [${TARGET_ENV}] infrastructure...${NC}"
|
||||
if [ -n "$SERVICE" ]; then
|
||||
docker compose "${COMPOSE_FILES[@]}" restart "$SERVICE"
|
||||
else
|
||||
docker compose "${COMPOSE_FILES[@]}" restart
|
||||
fi
|
||||
echo -e "${GREEN}✅ Infrastructure restarted!${NC}"
|
||||
echo -e "${GREEN}✅ [${TARGET_ENV}] Infrastructure restarted!${NC}"
|
||||
;;
|
||||
|
||||
|
||||
"status")
|
||||
echo -e "${CYAN}📊 Trading Bot Infrastructure Status:${NC}"
|
||||
echo -e "${CYAN}📊 Stock Bot [${TARGET_ENV}] Infrastructure Status:${NC}"
|
||||
docker compose "${COMPOSE_FILES[@]}" ps
|
||||
echo ""
|
||||
echo -e "${CYAN}🔍 Health Checks:${NC}"
|
||||
docker ps --filter "name=trading-bot" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||
echo -e "${CYAN}🔍 Containers:${NC}"
|
||||
docker ps --filter "name=${CONTAINER_FILTER}" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||
;;
|
||||
|
||||
|
||||
"logs")
|
||||
if [ -n "$SERVICE" ]; then
|
||||
echo -e "${CYAN}📋 Logs for $SERVICE:${NC}"
|
||||
echo -e "${CYAN}📋 Logs for [${TARGET_ENV}] $SERVICE:${NC}"
|
||||
docker compose "${COMPOSE_FILES[@]}" logs -f "$SERVICE"
|
||||
else
|
||||
echo -e "${CYAN}📋 All service logs:${NC}"
|
||||
echo -e "${CYAN}📋 All [${TARGET_ENV}] service logs:${NC}"
|
||||
docker compose "${COMPOSE_FILES[@]}" logs -f
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
"reset")
|
||||
echo -e "${RED}⚠️ Resetting Trading Bot infrastructure (will delete all data)...${NC}"
|
||||
if [ "$TARGET_ENV" != "dev" ]; then
|
||||
echo -e "${RED}🛑 REFUSED: 'reset' (volume wipe) is strictly forbidden for [${TARGET_ENV}].${NC}"
|
||||
echo -e "${YELLOW}QA holds the live ingested MongoDB dataset (stock-bot_mongodb_data) and must never be wiped.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${RED}⚠️ Resetting [dev] infrastructure (will delete dev volumes only)...${NC}"
|
||||
read -p "Are you sure? Type 'yes' to confirm: " confirm
|
||||
if [ "$confirm" = "yes" ]; then
|
||||
docker compose "${COMPOSE_FILES[@]}" down -v
|
||||
echo -e "${YELLOW}🗑️ Volumes removed${NC}"
|
||||
echo -e "${YELLOW}🗑️ Dev volumes removed${NC}"
|
||||
docker compose "${COMPOSE_FILES[@]}" up -d dragonfly postgres questdb mongodb
|
||||
echo -e "${GREEN}✅ Infrastructure reset complete!${NC}"
|
||||
echo -e "${GREEN}✅ Dev infrastructure reset complete!${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}❌ Reset cancelled${NC}"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
"admin")
|
||||
echo -e "${GREEN}🔧 Starting admin interfaces...${NC}"
|
||||
docker compose "${COMPOSE_FILES[@]}" up -d redis-insight pgadmin
|
||||
echo -e "${GREEN}🔧 Starting QA admin interfaces...${NC}"
|
||||
docker compose -f docker-compose.yml up -d redis-insight pgadmin
|
||||
echo -e "${GREEN}✅ Admin interfaces started!${NC}"
|
||||
echo ""
|
||||
echo -e "${CYAN}🔗 Admin Access:${NC}"
|
||||
echo " Redis Insight: http://localhost:8001"
|
||||
echo " PgAdmin: http://localhost:8080"
|
||||
echo " Email: admin@tradingbot.local"
|
||||
echo " Password: admin123"
|
||||
echo " PgAdmin: http://localhost:8080"
|
||||
;;
|
||||
|
||||
|
||||
"monitoring")
|
||||
echo -e "${GREEN}📊 Starting monitoring stack...${NC}"
|
||||
docker compose "${COMPOSE_FILES[@]}" up -d prometheus grafana loki
|
||||
echo -e "${GREEN}📊 Starting QA monitoring stack...${NC}"
|
||||
docker compose -f docker-compose.yml up -d prometheus grafana loki
|
||||
echo -e "${GREEN}✅ Monitoring started!${NC}"
|
||||
echo ""
|
||||
echo -e "${CYAN}🔗 Monitoring Access:${NC}"
|
||||
echo " Prometheus: http://localhost:9090"
|
||||
echo " Grafana: http://localhost:3000"
|
||||
echo " Username: admin"
|
||||
echo " Password: admin"
|
||||
echo " Loki: http://localhost:3100"
|
||||
echo " Grafana: http://localhost:3000"
|
||||
echo " Loki: http://localhost:3100"
|
||||
;;
|
||||
|
||||
|
||||
"help")
|
||||
show_help
|
||||
;;
|
||||
|
||||
|
||||
*)
|
||||
echo "Unknown action: $ACTION"
|
||||
show_help
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue