From 162400b9873947e4c10560060ecdbf46b02a82e0 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Wed, 24 Sep 2025 18:12:27 +0100 Subject: [PATCH] Add TeleBot Hostinger deployment configuration with source build --- .claude/settings.local.json | 3 +- TeleBot/docker-compose.hostinger.yml | 43 ++++++++++ deploy-telebot-hostinger.sh | 118 +++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 TeleBot/docker-compose.hostinger.yml create mode 100644 deploy-telebot-hostinger.sh diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 5d5d2d5..d40d3c8 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -32,7 +32,8 @@ "Read(//mnt/c/Production/Source/SilverLABS/SilverPAY/**)", "Bash(git commit:*)", "Bash(docker build:*)", - "Bash(git fetch:*)" + "Bash(git fetch:*)", + "Bash(./deploy-telebot-hostinger.sh:*)" ], "deny": [], "ask": [] diff --git a/TeleBot/docker-compose.hostinger.yml b/TeleBot/docker-compose.hostinger.yml new file mode 100644 index 0000000..b86df25 --- /dev/null +++ b/TeleBot/docker-compose.hostinger.yml @@ -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 \ No newline at end of file diff --git a/deploy-telebot-hostinger.sh b/deploy-telebot-hostinger.sh new file mode 100644 index 0000000..02c2783 --- /dev/null +++ b/deploy-telebot-hostinger.sh @@ -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'" \ No newline at end of file