upd
This commit is contained in:
63
Jenkinsfile
vendored
63
Jenkinsfile
vendored
@@ -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,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') {
|
||||
steps {
|
||||
echo 'Restarting bot...'
|
||||
echo 'Deploying to VPS...'
|
||||
sshagent(['vps-ssh-key']) {
|
||||
sh '''
|
||||
# Kill existing bot process
|
||||
pkill -f "python.*main.py" || true
|
||||
# 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}/
|
||||
|
||||
# Wait a moment
|
||||
sleep 2
|
||||
|
||||
# Start bot in background
|
||||
# Setup and restart on VPS
|
||||
ssh -o StrictHostKeyChecking=no root@${VPS_HOST} << 'ENDSSH'
|
||||
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
|
||||
# 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
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
|
||||
Reference in New Issue
Block a user