Files

118 lines
3.2 KiB
Bash

#!/bin/bash
set -e
echo "=========================================="
echo " ChunYu Full Stack Docker Setup"
echo "=========================================="
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}Docker is not installed. Please install Docker first.${NC}"
exit 1
fi
# Check Docker Compose
if ! docker compose version &> /dev/null; then
echo -e "${RED}Docker Compose is not available.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Docker found: $(docker --version)${NC}"
echo -e "${GREEN}✓ Docker Compose found: $(docker compose version --short)${NC}"
echo ""
# Parse arguments
BUILD_APK=false
RUN_MEMU=false
while [[ "$#" -gt 0 ]]; do
case $1 in
--build-apk) BUILD_APK=true ;;
--mumu) RUN_MEMU=true ;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --build-apk Build Android APK before starting"
echo " --mumu Use MuMu emulator on host instead of Docker Android"
echo " --help Show this help message"
exit 0
;;
esac
shift
done
# Build APK if requested
if [ "$BUILD_APK" = true ]; then
echo -e "${YELLOW}Building Android APK...${NC}"
docker build -t chunyu-apk-builder -f android/Dockerfile.build-apk .
# Extract APK
docker create --name temp-apk chunyu-apk-builder
docker cp temp-apk:/output/app-debug.apk android/apks/app-debug.apk
docker rm temp-apk
echo -e "${GREEN}✓ APK built and copied to android/apks/${NC}"
echo ""
fi
# Check if APK exists
if [ ! -f "android/apks/app-debug.apk" ]; then
echo -e "${YELLOW}⚠ No APK found at android/apks/app-debug.apk${NC}"
echo -e "${YELLOW} Run with --build-apk to build it first${NC}"
echo ""
fi
# Start services
echo -e "${YELLOW}Starting Docker Compose services...${NC}"
echo ""
if [ "$RUN_MEMU" = true ]; then
echo -e "${GREEN}Using MuMu emulator on host${NC}"
echo -e "${GREEN}Make sure MuMu is running and ADB is connected${NC}"
echo ""
# Start only backend and frontend
docker compose up -d backend frontend
else
echo -e "${GREEN}Using Docker Android emulator (redroid)${NC}"
echo ""
# Start all services including Android
docker compose --profile android up -d
fi
echo ""
echo "=========================================="
echo " Services Started! (ADRF + Granian + PostgreSQL)"
echo "=========================================="
echo ""
echo " Frontend: http://localhost:8080 (Nginx + React SPA)"
echo " Backend API: http://localhost:8000 (Granian + ADRF async)"
echo " PostgreSQL: localhost:5432"
echo " Redis: localhost:6379"
echo " Swagger: http://localhost:8080/swagger/"
echo ""
if [ "$RUN_MEMU" = true ]; then
echo " Android: MuMu on host"
echo " ADB: adb connect <mumu-ip>:5555"
else
echo " Android ADB: adb connect localhost:5555"
fi
echo ""
echo " To view logs:"
echo " docker compose logs -f"
echo ""
echo " To stop:"
echo " docker compose down"
echo "=========================================="