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

63
Jenkinsfile vendored
View File

@@ -3,8 +3,7 @@ pipeline {
environment { environment {
BOT_DIR = '/srv/fymious-tg-bot' BOT_DIR = '/srv/fymious-tg-bot'
VENV_DIR = '/srv/fymious-tg-bot/.venv' VPS_HOST = 'your-vps-ip-or-hostname'
TELEGRAM_BOT_TOKEN = credentials('telegram-bot-token')
} }
stages { stages {
@@ -15,55 +14,39 @@ 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') { stage('Deploy') {
steps { steps {
echo 'Restarting bot...' echo 'Deploying to VPS...'
sshagent(['vps-ssh-key']) {
sh ''' sh '''
# Kill existing bot process # Copy files to VPS
pkill -f "python.*main.py" || true ssh -o StrictHostKeyChecking=no root@${VPS_HOST} "mkdir -p ${BOT_DIR}"
scp -o StrictHostKeyChecking=no -r * root@${VPS_HOST}:${BOT_DIR}/
# Wait a moment # Setup and restart on VPS
sleep 2 ssh -o StrictHostKeyChecking=no root@${VPS_HOST} << 'ENDSSH'
# Start bot in background
cd ${BOT_DIR} cd ${BOT_DIR}
nohup ${VENV_DIR}/bin/python main.py > ${BOT_DIR}/bot.log 2>&1 &
# Verify bot started # Create venv if needed
sleep 3 if [ ! -d ".venv" ]; then
if pgrep -f "python.*main.py" > /dev/null; then python3 -m venv .venv
echo "Bot started successfully!"
else
echo "Failed to start bot. Check logs at ${BOT_DIR}/bot.log"
exit 1
fi 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
''' '''
} }
} }
} }
}
post { post {
success { success {