115 lines
3.3 KiB
Bash
115 lines
3.3 KiB
Bash
#!/bin/bash
|
|
# Run this script ON THE HOSTINGER SERVER after pulling latest code
|
|
# This builds TeleBot from source and deploys it with latest fixes
|
|
|
|
set -e
|
|
|
|
echo "🚀 TeleBot Server-Side Deployment Script"
|
|
echo "========================================="
|
|
|
|
# Navigate to deployment directory
|
|
cd /opt
|
|
echo "📁 Working directory: $(pwd)"
|
|
|
|
# Clone or update repository
|
|
if [ -d "LittleShop" ]; then
|
|
echo "📦 Updating existing repository..."
|
|
cd LittleShop
|
|
git pull origin main
|
|
else
|
|
echo "📦 Cloning repository..."
|
|
git clone https://git.silverlabs.uk/SilverLABS/LittleShop.git
|
|
cd LittleShop
|
|
fi
|
|
|
|
echo "✅ Repository updated"
|
|
git log --oneline -5
|
|
|
|
# Stop and remove existing TeleBot container
|
|
echo "🛑 Stopping existing TeleBot container..."
|
|
docker stop telebot 2>/dev/null || echo "No existing container to stop"
|
|
docker rm telebot 2>/dev/null || echo "No existing container to remove"
|
|
|
|
# Remove old TeleBot image to force rebuild
|
|
echo "🗑️ Removing old TeleBot image..."
|
|
docker rmi telebot:latest 2>/dev/null || echo "No existing image to remove"
|
|
|
|
# Build new image from source
|
|
echo "🔨 Building TeleBot from source code..."
|
|
echo "This will include all latest fixes including:"
|
|
echo " - Fixed duplicate /review case"
|
|
echo " - TeleBot compilation error fixes"
|
|
echo " - Improved shipping address collection"
|
|
echo " - Network connectivity improvements"
|
|
|
|
docker build -t telebot:latest -f TeleBot/TeleBot/Dockerfile .
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Docker image built successfully"
|
|
else
|
|
echo "❌ Docker build failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Create necessary directories
|
|
echo "📁 Creating data directories..."
|
|
mkdir -p /opt/telebot/logs
|
|
mkdir -p /opt/telebot/data
|
|
mkdir -p /opt/telebot/image_cache
|
|
|
|
# Set proper permissions (assuming container user is UID 1001)
|
|
chown -R 1001:1001 /opt/telebot/logs
|
|
chown -R 1001:1001 /opt/telebot/data
|
|
chown -R 1001:1001 /opt/telebot/image_cache
|
|
|
|
# Create .env file for TeleBot
|
|
echo "📝 Creating environment configuration..."
|
|
cat > /opt/telebot/.env << 'EOF'
|
|
# TeleBot Production Configuration
|
|
BOT_TOKEN=7569267607:AAFcXs3qeHqr_KKiGSb2EShJJLznNBXRfB8
|
|
WEBHOOK_URL=https://telebot.thebankofdebbie.giize.com/api/telegram/webhook
|
|
LITTLESHOP_API_KEY=your-api-key-here
|
|
DATABASE_CONNECTION_STRING=Data Source=/app/data/telebot.db
|
|
LOG_LEVEL=Information
|
|
EOF
|
|
|
|
# Run the new container
|
|
echo "🚀 Starting TeleBot container..."
|
|
docker run -d \
|
|
--name telebot \
|
|
--restart unless-stopped \
|
|
--network littleshop-network \
|
|
--env-file /opt/telebot/.env \
|
|
-e ASPNETCORE_ENVIRONMENT=Production \
|
|
-e LittleShopApi__BaseUrl=http://littleshop-admin:8080 \
|
|
-e TelegramBot__UseWebhook=false \
|
|
-e Logging__LogLevel__Default=Information \
|
|
-e Logging__LogLevel__Microsoft=Warning \
|
|
-v /opt/telebot/logs:/app/logs \
|
|
-v /opt/telebot/data:/app/data \
|
|
-v /opt/telebot/image_cache:/app/image_cache \
|
|
telebot:latest
|
|
|
|
# Wait for container to start
|
|
echo "⏳ Waiting for container to start..."
|
|
sleep 10
|
|
|
|
# Check container status
|
|
echo "📊 Container status:"
|
|
docker ps | grep telebot || echo "Container not running!"
|
|
|
|
echo ""
|
|
echo "📋 Container logs (last 30 lines):"
|
|
docker logs --tail 30 telebot
|
|
|
|
echo ""
|
|
echo "✅ Deployment complete!"
|
|
echo ""
|
|
echo "To monitor the bot:"
|
|
echo " docker logs -f telebot"
|
|
echo ""
|
|
echo "To check status:"
|
|
echo " docker ps | grep telebot"
|
|
echo ""
|
|
echo "Latest commits included:"
|
|
git log --oneline -5 |