From fd0283645030cbe19ed0bb99494cafe0ca6cc159 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Sat, 27 Sep 2025 09:53:43 +0100 Subject: [PATCH] Add TeleBot CI/CD pipeline configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created .gitlab-ci.yml for automated builds and deployment - Added docker-compose.production.yml for VPS deployment - Added .env.production.example for configuration template - Follows LittleShop deployment pattern - Auto-deploy on main branch commits 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- TeleBot/.env.production.example | 21 +++++++++ TeleBot/.gitlab-ci.yml | 61 +++++++++++++++++++++++++++ TeleBot/docker-compose.production.yml | 43 +++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 TeleBot/.env.production.example create mode 100644 TeleBot/.gitlab-ci.yml create mode 100644 TeleBot/docker-compose.production.yml diff --git a/TeleBot/.env.production.example b/TeleBot/.env.production.example new file mode 100644 index 0000000..ef33da0 --- /dev/null +++ b/TeleBot/.env.production.example @@ -0,0 +1,21 @@ +# TeleBot Production Environment Variables +# Copy this file to /opt/telebot/.env on the VPS and fill in the values + +# Telegram Bot Configuration +TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here +TELEGRAM_ADMIN_CHAT_ID=your_admin_chat_id_here + +# LittleShop API Configuration +LITTLESHOP_API_URL=http://littleshop-admin:8080 +LITTLESHOP_USERNAME=admin +LITTLESHOP_PASSWORD=your_admin_password_here + +# Database Encryption +DB_ENCRYPTION_KEY=your_32_character_encryption_key_here + +# Optional: Redis Configuration (if enabled) +# REDIS_CONNECTION_STRING=localhost:6379 + +# Optional: Tor Configuration (if enabled) +# PRIVACY_ENABLE_TOR=false +# PRIVACY_TOR_SOCKS_PORT=9050 \ No newline at end of file diff --git a/TeleBot/.gitlab-ci.yml b/TeleBot/.gitlab-ci.yml new file mode 100644 index 0000000..36031d4 --- /dev/null +++ b/TeleBot/.gitlab-ci.yml @@ -0,0 +1,61 @@ +variables: + DOCKER_HOST: unix:///var/run/docker.sock + +stages: + - build + - deploy + +build: + stage: build + image: docker:24 + script: + - docker build -f TeleBot/Dockerfile -t localhost:5000/telebot:latest ../ + - docker tag localhost:5000/telebot:latest localhost:5000/telebot:$CI_COMMIT_SHORT_SHA + - docker push localhost:5000/telebot:latest + - docker push localhost:5000/telebot:$CI_COMMIT_SHORT_SHA + rules: + - if: '$CI_COMMIT_BRANCH == "main"' + - if: '$CI_COMMIT_TAG' + +deploy:vps: + stage: deploy + image: docker:24 + before_script: + - apk add --no-cache openssh-client bash curl + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo "$VPS_SSH_KEY_B64" | base64 -d > /tmp/deploy_key + - chmod 600 /tmp/deploy_key + - ssh-keyscan -p "$VPS_PORT" "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null + script: + - | + # Save and transfer Docker image + docker save localhost:5000/telebot:latest | ssh -i /tmp/deploy_key -p "$VPS_PORT" "$VPS_USER@$VPS_HOST" "docker load" + + # Deploy on VPS + ssh -i /tmp/deploy_key -p "$VPS_PORT" "$VPS_USER@$VPS_HOST" bash -s << 'EOF' + cd /opt/telebot + docker-compose down + docker-compose up -d + + # Health check + for i in 1 2 3 4 5 6; do + if pgrep -f "dotnet.*TeleBot" > /dev/null 2>&1; then + echo "✅ TeleBot deployment successful" + exit 0 + fi + echo "Waiting for TeleBot to start... ($i/6)" + sleep 10 + done + + echo "❌ TeleBot deployment failed - health check timeout" + docker-compose logs --tail=50 + exit 1 + EOF + rules: + - if: '$CI_COMMIT_BRANCH == "main"' + when: on_success + - if: '$CI_COMMIT_TAG' + when: manual + after_script: + - rm -f /tmp/deploy_key \ No newline at end of file diff --git a/TeleBot/docker-compose.production.yml b/TeleBot/docker-compose.production.yml new file mode 100644 index 0000000..533aa5f --- /dev/null +++ b/TeleBot/docker-compose.production.yml @@ -0,0 +1,43 @@ +version: '3.8' + +services: + telebot: + image: localhost:5000/telebot:latest + container_name: telebot + restart: unless-stopped + environment: + - ASPNETCORE_ENVIRONMENT=Production + - Telegram__BotToken=${TELEGRAM_BOT_TOKEN} + - Telegram__AdminChatId=${TELEGRAM_ADMIN_CHAT_ID} + - Telegram__UseWebhook=false + - LittleShop__ApiUrl=${LITTLESHOP_API_URL} + - LittleShop__Username=${LITTLESHOP_USERNAME} + - LittleShop__Password=${LITTLESHOP_PASSWORD} + - Database__EncryptionKey=${DB_ENCRYPTION_KEY} + - Logging__LogLevel__Default=Information + - Logging__LogLevel__Microsoft=Warning + volumes: + - ./logs:/app/logs + - ./data:/app/data + - ./image_cache:/app/image_cache + networks: + - telebot-network + - littleshop_littleshop-network + depends_on: + - littleshop-admin + healthcheck: + test: ["CMD", "pgrep", "-f", "dotnet.*TeleBot"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s + +networks: + telebot-network: + driver: bridge + ipam: + config: + - subnet: 172.24.0.0/16 + + littleshop_littleshop-network: + external: true \ No newline at end of file