Add deployment scripts and webhook configuration
This commit is contained in:
57
deployment/discord_bot_deploy.sh
Normal file
57
deployment/discord_bot_deploy.sh
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BOTDIR="/root/code/discordBot"
|
||||||
|
SERVICE_NAME="discord-bot"
|
||||||
|
|
||||||
|
echo "[Discord Bot] Pulling latest code..."
|
||||||
|
|
||||||
|
# Backup .env if it exists
|
||||||
|
if [ -f "$BOTDIR/.env" ]; then
|
||||||
|
cp "$BOTDIR/.env" /tmp/.env.backup
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Backup media and logs folders
|
||||||
|
if [ -d "$BOTDIR/media" ]; then
|
||||||
|
cp -r "$BOTDIR/media" /tmp/media.backup
|
||||||
|
fi
|
||||||
|
if [ -d "$BOTDIR/logs" ]; then
|
||||||
|
cp -r "$BOTDIR/logs" /tmp/logs.backup
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$BOTDIR/.git" ]; then
|
||||||
|
echo "Directory not a git repo — performing initial clone..."
|
||||||
|
rm -rf "$BOTDIR"
|
||||||
|
git clone https://code.lotusguild.org/LotusGuild/discordBot.git "$BOTDIR"
|
||||||
|
else
|
||||||
|
echo "Updating existing repo..."
|
||||||
|
cd "$BOTDIR"
|
||||||
|
git fetch --all
|
||||||
|
git reset --hard origin/main
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restore .env if it was backed up
|
||||||
|
if [ -f /tmp/.env.backup ]; then
|
||||||
|
mv /tmp/.env.backup "$BOTDIR/.env"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restore media and logs folders
|
||||||
|
if [ -d /tmp/media.backup ]; then
|
||||||
|
rm -rf "$BOTDIR/media"
|
||||||
|
mv /tmp/media.backup "$BOTDIR/media"
|
||||||
|
fi
|
||||||
|
if [ -d /tmp/logs.backup ]; then
|
||||||
|
rm -rf "$BOTDIR/logs"
|
||||||
|
mv /tmp/logs.backup "$BOTDIR/logs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[Discord Bot] Installing/updating dependencies..."
|
||||||
|
cd "$BOTDIR"
|
||||||
|
pip3 install -r requirements.txt 2>/dev/null || echo "No requirements.txt found, skipping..."
|
||||||
|
|
||||||
|
echo "[Discord Bot] Restarting service..."
|
||||||
|
systemctl restart "$SERVICE_NAME"
|
||||||
|
|
||||||
|
echo "[Discord Bot] Deployment complete!"
|
||||||
|
echo "[Discord Bot] Service status:"
|
||||||
|
systemctl status "$SERVICE_NAME" --no-pager
|
||||||
18
deployment/hooks.json
Normal file
18
deployment/hooks.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "discord-bot-deploy",
|
||||||
|
"execute-command": "/usr/local/bin/discord_bot_deploy.sh",
|
||||||
|
"command-working-directory": "/root/code/discordBot",
|
||||||
|
"response-message": "Deploying Discord bot...",
|
||||||
|
"trigger-rule": {
|
||||||
|
"match": {
|
||||||
|
"type": "payload-hash-sha256",
|
||||||
|
"secret": "CHANGE_THIS_SECRET_KEY",
|
||||||
|
"parameter": {
|
||||||
|
"source": "header",
|
||||||
|
"name": "X-Gitea-Signature"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user