Document git-based deployment flow and update scripts

- Add comprehensive deployment architecture documentation to DEPLOYMENT.md
- Include ASCII diagram showing local → Gitea → Unraid flow
- Document all three deployment scripts with examples
- Update scripts to use root@192.168.2.61 for SSH authentication
- Add automatic SSH config setup in deploy.sh for git server port 28
- Include troubleshooting section for common deployment issues

🤖 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:52:44 -06:00
parent 859f011dda
commit 770701e293
4 changed files with 166 additions and 3 deletions

View File

@@ -181,6 +181,156 @@ docker rm discord-stock-bot
## Unraid Deployment
### Automated Git-Based Deployment (Recommended)
This project includes automated deployment scripts for seamless deployment to Unraid via git.
#### Architecture Flow
```
┌─────────────────┐ git push ┌──────────────────┐
│ Local Machine │ ─────────────────> │ Gitea Server │
│ Development │ │ (port 28) │
└────────┬────────┘ └────────┬─────────┘
│ │
│ ./deploy.sh │
│ (SSH commands) │
│ │
v │
┌─────────────────┐ git pull │
│ Unraid Server │ <───────────────────────────┘
│ 192.168.2.61 │
│ │
│ docker compose │
│ up --build -d │
└─────────────────┘
```
#### Deployment Scripts
**1. `setup-unraid.sh`** - One-time initial setup
- Configures SSH keys on Unraid for git authentication
- Adds git.michaelsimard.ca:28 to SSH config
- Copies .env file to Unraid
- Tests git connectivity
**2. `deploy.sh`** - Deploy/update the bot
- SSHs into Unraid
- Configures git server SSH settings (port 28)
- Clones repository (first run) or pulls latest changes
- Builds and starts Docker container
- Shows deployment status
**3. `manage.sh`** - Daily operations
- `./manage.sh logs` - View live container logs
- `./manage.sh status` - Check container status
- `./manage.sh restart` - Restart the bot
- `./manage.sh stop` - Stop the bot
- `./manage.sh start` - Start the bot
- `./manage.sh rebuild` - Rebuild and restart
- `./manage.sh shell` - SSH to Unraid in bot directory
#### Deployment Process
**Initial Setup (one-time):**
```bash
# 1. Ensure you have local .env configured
cp .env.example .env
# Edit .env with your credentials
# 2. Run initial setup
./setup-unraid.sh
# This will:
# - Configure SSH on Unraid for git server (port 28)
# - Generate SSH key on Unraid if needed
# - Display public key to add to Gitea
# - Copy .env to Unraid server
# - Test git connectivity
```
**Deploy the Bot:**
```bash
# Deploy to Unraid
./deploy.sh
# This will:
# - SSH into Unraid (root@192.168.2.61)
# - Ensure git SSH config is set (port 28)
# - Clone or pull latest code from Gitea
# - Build Docker image
# - Start container in background
```
**Manage the Bot:**
```bash
# View logs
./manage.sh logs
# Check status
./manage.sh status
# Restart after config changes
./manage.sh restart
```
#### Update Workflow
```bash
# 1. Make changes locally
vim bot.py
# 2. Commit and push to git
git add .
git commit -m "Update feature"
git push
# 3. Deploy to Unraid
./deploy.sh
# 4. Verify deployment
./manage.sh logs
```
#### Configuration Details
- **Unraid Host**: `root@192.168.2.61`
- **Deployment Path**: `/mnt/user/docker/custom-dockers/discord-stock-bot`
- **Git Repository**: `git@git.michaelsimard.ca:msimard/discord-stock-bot.git`
- **Git Server Port**: 28 (configured in SSH config)
#### Troubleshooting Automated Deployment
**SSH Connection Issues:**
```bash
# Test SSH connection
ssh root@192.168.2.61
# Test git access from Unraid
ssh root@192.168.2.61 "git ls-remote git@git.michaelsimard.ca:msimard/discord-stock-bot.git HEAD"
```
**Git Authentication Fails:**
```bash
# Re-run setup to regenerate keys
./setup-unraid.sh
# Manually add SSH key to Gitea:
# https://git.michaelsimard.ca/user/settings/keys
```
**Container Won't Start:**
```bash
# Check .env exists on Unraid
ssh root@192.168.2.61 "cat /mnt/user/docker/custom-dockers/discord-stock-bot/.env"
# View detailed logs
./manage.sh logs
```
### Method 1: Docker Compose
1. Copy the project directory to your Unraid server:

View File

@@ -4,7 +4,7 @@
set -e
# Configuration
UNRAID_HOST="${UNRAID_HOST:-192.168.2.61}"
UNRAID_HOST="${UNRAID_HOST:-root@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"
@@ -13,6 +13,19 @@ echo "Deploying discord-stock-bot to ${UNRAID_HOST}..."
ssh ${UNRAID_HOST} bash << EOF
set -e
# Ensure SSH config for git server (port 28)
mkdir -p ~/.ssh
chmod 700 ~/.ssh
if ! grep -q "^Host git.michaelsimard.ca" ~/.ssh/config 2>/dev/null; then
echo "Configuring SSH for git.michaelsimard.ca (port 28)..."
cat >> ~/.ssh/config << 'SSHCONFIG'
Host git.michaelsimard.ca
Port 28
SSHCONFIG
chmod 600 ~/.ssh/config
fi
# Clone or pull repository
if [ -d "${REMOTE_PATH}/.git" ]; then
echo "Repository exists, pulling latest changes..."

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# manage.sh - Manage discord-stock-bot on Unraid
UNRAID_HOST="${UNRAID_HOST:-192.168.2.61}"
UNRAID_HOST="${UNRAID_HOST:-root@192.168.2.61}"
REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot"
CMD="$1"

View File

@@ -3,7 +3,7 @@
set -e
UNRAID_HOST="${UNRAID_HOST:-192.168.2.61}"
UNRAID_HOST="${UNRAID_HOST:-root@192.168.2.61}"
REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot"
echo "Setting up Unraid server for git-based deployment..."