From 770701e2930196b8e5bf94053e9f885d1ad5678b Mon Sep 17 00:00:00 2001 From: Michael Simard Date: Tue, 2 Dec 2025 22:52:44 -0600 Subject: [PATCH] Document git-based deployment flow and update scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- DEPLOYMENT.md | 150 ++++++++++++++++++++++++++++++++++++++++++++++++ deploy.sh | 15 ++++- manage.sh | 2 +- setup-unraid.sh | 2 +- 4 files changed, 166 insertions(+), 3 deletions(-) diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index f7a33a1..5045a28 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -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: diff --git a/deploy.sh b/deploy.sh index 9a104d3..2add3eb 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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..." diff --git a/manage.sh b/manage.sh index afb1306..912d3c5 100755 --- a/manage.sh +++ b/manage.sh @@ -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" diff --git a/setup-unraid.sh b/setup-unraid.sh index ed9356f..dc3bab8 100755 --- a/setup-unraid.sh +++ b/setup-unraid.sh @@ -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..."