From cbf8a73f7550f62896880653eca29705f3064b9d Mon Sep 17 00:00:00 2001 From: me Date: Tue, 27 Jan 2026 14:42:58 +0300 Subject: [PATCH] upd --- Jenkinsfile | 75 +++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 909e9a1..3f63f14 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,8 +3,7 @@ pipeline { environment { BOT_DIR = '/srv/fymious-tg-bot' - VENV_DIR = '/srv/fymious-tg-bot/.venv' - TELEGRAM_BOT_TOKEN = credentials('telegram-bot-token') + VPS_HOST = 'your-vps-ip-or-hostname' } stages { @@ -15,52 +14,36 @@ pipeline { } } - stage('Setup') { - steps { - echo 'Setting up virtual environment and dependencies...' - sh ''' - # Create bot directory if it doesn't exist - mkdir -p ${BOT_DIR} - - # Copy files to bot directory - cp -r * ${BOT_DIR}/ - - cd ${BOT_DIR} - - # Create virtual environment if it doesn't exist - if [ ! -d "${VENV_DIR}" ]; then - python3 -m venv ${VENV_DIR} - fi - - # Install/update dependencies - ${VENV_DIR}/bin/pip install -r requirements.txt - ''' - } - } - stage('Deploy') { steps { - echo 'Restarting bot...' - sh ''' - # Kill existing bot process - pkill -f "python.*main.py" || true - - # Wait a moment - sleep 2 - - # Start bot in background - cd ${BOT_DIR} - nohup ${VENV_DIR}/bin/python main.py > ${BOT_DIR}/bot.log 2>&1 & - - # Verify bot started - sleep 3 - if pgrep -f "python.*main.py" > /dev/null; then - echo "Bot started successfully!" - else - echo "Failed to start bot. Check logs at ${BOT_DIR}/bot.log" - exit 1 - fi - ''' + echo 'Deploying to VPS...' + sshagent(['vps-ssh-key']) { + sh ''' + # Copy files to VPS + ssh -o StrictHostKeyChecking=no root@${VPS_HOST} "mkdir -p ${BOT_DIR}" + scp -o StrictHostKeyChecking=no -r * root@${VPS_HOST}:${BOT_DIR}/ + + # Setup and restart on VPS + ssh -o StrictHostKeyChecking=no root@${VPS_HOST} << 'ENDSSH' + cd ${BOT_DIR} + + # Create venv if needed + if [ ! -d ".venv" ]; then + python3 -m venv .venv + fi + + # Install dependencies + .venv/bin/pip install -r requirements.txt + + # Restart service + systemctl restart fymious-tg-bot + + # Check status + sleep 3 + systemctl is-active fymious-tg-bot +ENDSSH + ''' + } } } }