This commit is contained in:
2026-01-27 14:42:58 +03:00
parent 0cd4f5dbb4
commit cbf8a73f75

75
Jenkinsfile vendored
View File

@@ -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
'''
}
}
}
}