Add TeleBot Hostinger deployment configuration with source build

This commit is contained in:
SysAdmin 2025-09-24 18:12:27 +01:00
parent bc708bb0a3
commit 162400b987
3 changed files with 163 additions and 1 deletions

View File

@ -32,7 +32,8 @@
"Read(//mnt/c/Production/Source/SilverLABS/SilverPAY/**)", "Read(//mnt/c/Production/Source/SilverLABS/SilverPAY/**)",
"Bash(git commit:*)", "Bash(git commit:*)",
"Bash(docker build:*)", "Bash(docker build:*)",
"Bash(git fetch:*)" "Bash(git fetch:*)",
"Bash(./deploy-telebot-hostinger.sh:*)"
], ],
"deny": [], "deny": [],
"ask": [] "ask": []

View File

@ -0,0 +1,43 @@
version: '3.8'
services:
telebot:
build:
context: ../
dockerfile: TeleBot/TeleBot/Dockerfile
image: telebot:latest
container_name: telebot
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Production
- TelegramBot__BotToken=${BOT_TOKEN}
- TelegramBot__WebhookUrl=${WEBHOOK_URL}
- TelegramBot__UseWebhook=false
- LittleShopApi__BaseUrl=http://littleshop-admin:8080
- LittleShopApi__ApiKey=${LITTLESHOP_API_KEY}
- Logging__LogLevel__Default=Information
- Logging__LogLevel__Microsoft=Warning
- Logging__LogLevel__Microsoft.Hosting.Lifetime=Information
volumes:
- ./logs:/app/logs
- ./data:/app/data
- ./image_cache:/app/image_cache
networks:
- littleshop-network
depends_on:
- littleshop-admin
healthcheck:
test: ["CMD", "pgrep", "-f", "dotnet.*TeleBot"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
littleshop-admin:
external: true
name: littleshop-admin
networks:
littleshop-network:
external: true
name: littleshop-network

118
deploy-telebot-hostinger.sh Normal file
View File

@ -0,0 +1,118 @@
#!/bin/bash
# Deploy TeleBot to Hostinger server with source code build
# This script builds TeleBot from source and deploys it
set -e
echo "🚀 Starting TeleBot deployment to Hostinger..."
# Configuration
REMOTE_HOST="srv1002428.hstgr.cloud"
REMOTE_USER="root"
REMOTE_PORT="2255"
REMOTE_DIR="/opt/telebot"
REMOTE_PASS="Proxmox8426!"
# SSH command with password
SSH_CMD="sshpass -p '${REMOTE_PASS}' ssh -p ${REMOTE_PORT} -o StrictHostKeyChecking=no"
SCP_CMD="sshpass -p '${REMOTE_PASS}' scp -P ${REMOTE_PORT} -o StrictHostKeyChecking=no"
RSYNC_CMD="sshpass -p '${REMOTE_PASS}' rsync"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${YELLOW}Step 1: Creating deployment directory on remote server...${NC}"
${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} "mkdir -p ${REMOTE_DIR}"
echo -e "${YELLOW}Step 2: Copying source code to remote server...${NC}"
# Create a clean copy excluding unnecessary files
${RSYNC_CMD} -avz --delete \
--exclude 'bin/' \
--exclude 'obj/' \
--exclude '.git/' \
--exclude '*.log' \
--exclude 'logs/' \
--exclude 'data/' \
--exclude 'image_cache/' \
-e "ssh -p ${REMOTE_PORT} -o StrictHostKeyChecking=no" \
./ ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/
echo -e "${YELLOW}Step 3: Creating .env file from environment variables...${NC}"
${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} << 'EOF'
cd /opt/telebot
# Create .env file with production configuration
cat > .env << 'ENVEOF'
# 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
DATABASE_CONNECTION_STRING=Data Source=/app/data/telebot.db
# Logging
LOG_LEVEL=Information
ENVEOF
echo ".env file created"
EOF
echo -e "${YELLOW}Step 4: Building and deploying TeleBot container...${NC}"
${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} << 'EOF'
cd /opt/telebot
# Stop existing container if running
echo "Stopping existing TeleBot container..."
docker stop telebot 2>/dev/null || true
docker rm telebot 2>/dev/null || true
# Build new image from source
echo "Building TeleBot image from source code..."
docker build -t telebot:latest -f TeleBot/TeleBot/Dockerfile .
# Create necessary directories with proper permissions
echo "Creating data directories..."
mkdir -p /opt/telebot/logs
mkdir -p /opt/telebot/data
mkdir -p /opt/telebot/image_cache
# Set permissions for the telebot user inside container (UID 1001 typically)
chown -R 1001:1001 /opt/telebot/logs
chown -R 1001:1001 /opt/telebot/data
chown -R 1001:1001 /opt/telebot/image_cache
# Run the container
echo "Starting TeleBot container..."
docker run -d \
--name telebot \
--restart unless-stopped \
--network littleshop-network \
--env-file .env \
-e ASPNETCORE_ENVIRONMENT=Production \
-e LittleShopApi__BaseUrl=http://littleshop-admin:8080 \
-e TelegramBot__UseWebhook=false \
-e Logging__LogLevel__Default=Information \
-v /opt/telebot/logs:/app/logs \
-v /opt/telebot/data:/app/data \
-v /opt/telebot/image_cache:/app/image_cache \
telebot:latest
echo "Waiting for container to start..."
sleep 10
# Check container status
docker ps | grep telebot
docker logs --tail 20 telebot
EOF
echo -e "${GREEN}✅ TeleBot deployment complete!${NC}"
echo -e "${GREEN}Container should now be running with latest code from source${NC}"
echo ""
echo "To check status:"
echo " ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} 'docker logs telebot'"
echo " ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} 'docker ps | grep telebot'"