upd
This commit is contained in:
69
Jenkinsfile
vendored
69
Jenkinsfile
vendored
@@ -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,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') {
|
stage('Deploy') {
|
||||||
steps {
|
steps {
|
||||||
echo 'Restarting bot...'
|
echo 'Deploying to VPS...'
|
||||||
sh '''
|
sshagent(['vps-ssh-key']) {
|
||||||
# Kill existing bot process
|
sh '''
|
||||||
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
|
# Setup and restart on VPS
|
||||||
sleep 2
|
ssh -o StrictHostKeyChecking=no root@${VPS_HOST} << 'ENDSSH'
|
||||||
|
cd ${BOT_DIR}
|
||||||
|
|
||||||
# Start bot in background
|
# Create venv if needed
|
||||||
cd ${BOT_DIR}
|
if [ ! -d ".venv" ]; then
|
||||||
nohup ${VENV_DIR}/bin/python main.py > ${BOT_DIR}/bot.log 2>&1 &
|
python3 -m venv .venv
|
||||||
|
fi
|
||||||
|
|
||||||
# Verify bot started
|
# Install dependencies
|
||||||
sleep 3
|
.venv/bin/pip install -r requirements.txt
|
||||||
if pgrep -f "python.*main.py" > /dev/null; then
|
|
||||||
echo "Bot started successfully!"
|
# Restart service
|
||||||
else
|
systemctl restart fymious-tg-bot
|
||||||
echo "Failed to start bot. Check logs at ${BOT_DIR}/bot.log"
|
|
||||||
exit 1
|
# Check status
|
||||||
fi
|
sleep 3
|
||||||
'''
|
systemctl is-active fymious-tg-bot
|
||||||
|
ENDSSH
|
||||||
|
'''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user