File size: 5,724 Bytes
dc4e6da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | #!/bin/bash
# ============================================
# DocGenie Deployment Helper Script
# ============================================
# Quick deployment script for Railway + RunPod
set -e # Exit on error
echo "π DocGenie Deployment Helper"
echo "=============================="
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored messages
print_success() {
echo -e "${GREEN}β $1${NC}"
}
print_error() {
echo -e "${RED}β $1${NC}"
}
print_info() {
echo -e "${YELLOW}βΉ $1${NC}"
}
# Check prerequisites
echo "Checking prerequisites..."
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
print_success "Docker installed"
# Check if .env exists
if [ ! -f "api/.env" ]; then
print_error "api/.env file not found. Please create it first."
exit 1
fi
print_success "Environment file found"
# Menu
echo ""
echo "Select deployment option:"
echo "1) Build Handwriting Service Docker image"
echo "2) Push Handwriting Service to Docker Hub"
echo "3) Deploy API to Railway"
echo "4) Run local test environment (docker-compose)"
echo "5) Full deployment (Handwriting + API)"
echo "0) Exit"
echo ""
read -p "Enter option (0-5): " option
case $option in
1)
echo ""
print_info "Building Handwriting Service Docker image..."
# Build image
cd handwriting_service
docker buildx build --platform linux/amd64 \
-t docgenie-handwriting:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
.
print_success "Image built successfully"
print_info "Tag: docgenie-handwriting:latest"
;;
2)
echo ""
read -p "Enter your Docker Hub username: " docker_username
print_info "Tagging image for Docker Hub..."
docker tag docgenie-handwriting:latest ${docker_username}/docgenie-handwriting:latest
print_info "Pushing to Docker Hub..."
docker push ${docker_username}/docgenie-handwriting:latest
print_success "Image pushed successfully"
print_info "Deploy this on RunPod: ${docker_username}/docgenie-handwriting:latest"
;;
3)
echo ""
print_info "Deploying API to Railway..."
# Check if Railway CLI is installed
if ! command -v railway &> /dev/null; then
print_error "Railway CLI not installed. Installing..."
npm i -g @railway/cli
fi
# Deploy
railway up
print_success "API deployed to Railway"
print_info "View logs: railway logs"
print_info "View URL: railway open"
;;
4)
echo ""
print_info "Starting local test environment..."
print_info "This will start: Redis, API, Worker, Handwriting Service"
# Check if GPU is available
if command -v nvidia-smi &> /dev/null; then
print_info "GPU detected, using CUDA"
docker-compose up
else
print_info "No GPU detected, using CPU for handwriting service"
DEVICE=cpu docker-compose up
fi
;;
5)
echo ""
print_info "Full deployment starting..."
# Step 1: Build handwriting image
print_info "Step 1/4: Building Handwriting Service..."
cd handwriting_service
docker buildx build --platform linux/amd64 \
-t docgenie-handwriting:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
.
cd ..
print_success "Handwriting image built"
# Step 2: Push to Docker Hub
echo ""
read -p "Enter your Docker Hub username: " docker_username
print_info "Step 2/4: Pushing to Docker Hub..."
docker tag docgenie-handwriting:latest ${docker_username}/docgenie-handwriting:latest
docker push ${docker_username}/docgenie-handwriting:latest
print_success "Image pushed"
# Step 3: Deploy to RunPod (manual)
echo ""
print_info "Step 3/4: Deploy to RunPod (manual step)"
print_info "1. Go to https://runpod.io β Serverless β New Endpoint"
print_info "2. Use image: ${docker_username}/docgenie-handwriting:latest"
print_info "3. Select GPU: RTX 4090 or A40"
print_info "4. Set port: 8080"
print_info "5. Set env: DEVICE=cuda"
read -p "Press Enter when RunPod deployment is complete..."
# Step 4: Get RunPod URL and deploy API
echo ""
read -p "Enter your RunPod endpoint URL: " runpod_url
print_info "Step 4/4: Deploying API to Railway..."
# Set HANDWRITING_SERVICE_URL
export HANDWRITING_SERVICE_URL=$runpod_url
# Deploy to Railway
if ! command -v railway &> /dev/null; then
print_error "Railway CLI not installed. Installing..."
npm i -g @railway/cli
fi
railway up
print_success "Full deployment complete!"
echo ""
print_info "Next steps:"
print_info "1. Set HANDWRITING_SERVICE_URL in Railway dashboard"
print_info "2. railway variables set HANDWRITING_SERVICE_URL=$runpod_url"
print_info "3. Test: curl https://your-domain.up.railway.app/health"
;;
0)
echo "Goodbye!"
exit 0
;;
*)
print_error "Invalid option"
exit 1
;;
esac
echo ""
print_success "Done!"
|