Add automated deployment scripts for Unraid

Implements git-based deployment workflow with three scripts:
- setup-unraid.sh: One-time SSH and git configuration
- deploy.sh: Automated deployment via git pull and docker compose
- manage.sh: Remote management utilities (logs, restart, status)

Configuration targets 192.168.2.61 at /mnt/user/docker/custom-dockers/discord-stock-bot

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Michael Simard
2025-12-02 22:45:09 -06:00
parent 3b6f0cbe4a
commit 859f011dda
3 changed files with 178 additions and 0 deletions

44
deploy.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
# deploy.sh - Git-based deployment to Unraid server
set -e
# Configuration
UNRAID_HOST="${UNRAID_HOST:-192.168.2.61}"
REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot"
GIT_REPO="git@git.michaelsimard.ca:msimard/discord-stock-bot.git"
echo "Deploying discord-stock-bot to ${UNRAID_HOST}..."
ssh ${UNRAID_HOST} bash << EOF
set -e
# Clone or pull repository
if [ -d "${REMOTE_PATH}/.git" ]; then
echo "Repository exists, pulling latest changes..."
cd ${REMOTE_PATH}
git pull
else
echo "Cloning repository..."
git clone ${GIT_REPO} ${REMOTE_PATH}
cd ${REMOTE_PATH}
fi
# Check if .env exists
if [ ! -f .env ]; then
echo "WARNING: .env file not found!"
echo "Please create ${REMOTE_PATH}/.env with required configuration"
exit 1
fi
# Build and deploy
echo "Building and starting container..."
docker compose up -d --build
# Show status
echo ""
echo "Deployment complete!"
docker compose ps
echo ""
echo "View logs with: ssh ${UNRAID_HOST} 'cd ${REMOTE_PATH} && docker compose logs -f'"
EOF

52
manage.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
# manage.sh - Manage discord-stock-bot on Unraid
UNRAID_HOST="${UNRAID_HOST:-192.168.2.61}"
REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot"
CMD="$1"
run_remote() {
ssh ${UNRAID_HOST} "cd ${REMOTE_PATH} && $1"
}
case "$CMD" in
logs)
run_remote "docker compose logs -f"
;;
status)
run_remote "docker compose ps"
;;
restart)
run_remote "docker compose restart"
echo "Bot restarted"
;;
stop)
run_remote "docker compose down"
echo "Bot stopped"
;;
start)
run_remote "docker compose up -d"
echo "Bot started"
;;
rebuild)
run_remote "docker compose up -d --build"
echo "Bot rebuilt and started"
;;
shell)
ssh -t ${UNRAID_HOST} "cd ${REMOTE_PATH} && bash"
;;
*)
echo "Usage: $0 {logs|status|restart|stop|start|rebuild|shell}"
echo ""
echo "Commands:"
echo " logs - View live logs"
echo " status - Show container status"
echo " restart - Restart the bot"
echo " stop - Stop the bot"
echo " start - Start the bot"
echo " rebuild - Rebuild and restart the bot"
echo " shell - SSH into Unraid at bot directory"
exit 1
;;
esac

82
setup-unraid.sh Executable file
View File

@@ -0,0 +1,82 @@
#!/bin/bash
# setup-unraid.sh - Initial Unraid setup for git-based deployment
set -e
UNRAID_HOST="${UNRAID_HOST:-192.168.2.61}"
REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot"
echo "Setting up Unraid server for git-based deployment..."
echo ""
# Setup SSH config on Unraid for git access
echo "1. Configuring SSH for git.michaelsimard.ca..."
ssh ${UNRAID_HOST} bash << 'EOF'
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Add SSH config for git server
if ! grep -q "git.michaelsimard.ca" ~/.ssh/config 2>/dev/null; then
cat >> ~/.ssh/config << 'SSHCONFIG'
Host git.michaelsimard.ca
Port 28
SSHCONFIG
chmod 600 ~/.ssh/config
echo "SSH config updated"
else
echo "SSH config already contains git.michaelsimard.ca"
fi
# Add host key
ssh-keyscan -p 28 git.michaelsimard.ca >> ~/.ssh/known_hosts 2>/dev/null || true
echo "Host key added to known_hosts"
EOF
echo ""
echo "2. Checking for SSH key on Unraid..."
ssh ${UNRAID_HOST} bash << 'EOF'
if [ ! -f ~/.ssh/id_rsa ] && [ ! -f ~/.ssh/id_ed25519 ]; then
echo "No SSH key found. Generating ed25519 key..."
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -C "unraid@discord-bot"
echo ""
echo "=== PUBLIC KEY - Add this to your Gitea account ==="
cat ~/.ssh/id_ed25519.pub
echo "=== END PUBLIC KEY ==="
echo ""
echo "Add this key at: https://git.michaelsimard.ca/user/settings/keys"
echo "Press Enter when done..."
read
else
echo "SSH key exists"
if [ -f ~/.ssh/id_ed25519.pub ]; then
cat ~/.ssh/id_ed25519.pub
elif [ -f ~/.ssh/id_rsa.pub ]; then
cat ~/.ssh/id_rsa.pub
fi
fi
EOF
echo ""
echo "3. Testing git access..."
if ssh ${UNRAID_HOST} "git ls-remote git@git.michaelsimard.ca:msimard/discord-stock-bot.git HEAD" &>/dev/null; then
echo "✓ Git access successful"
else
echo "✗ Git access failed. Ensure SSH key is added to Gitea"
exit 1
fi
echo ""
echo "4. Creating .env file on Unraid..."
if ssh ${UNRAID_HOST} "[ -f ${REMOTE_PATH}/.env ]"; then
echo ".env already exists on Unraid"
else
echo "Copying local .env to Unraid..."
ssh ${UNRAID_HOST} "mkdir -p ${REMOTE_PATH}"
scp .env ${UNRAID_HOST}:${REMOTE_PATH}/.env
echo "✓ .env copied"
fi
echo ""
echo "=== Setup Complete ==="
echo "Run './deploy.sh' to deploy the bot"