|
| 1 | +# ACT Bot Deployment Guide - Raspberry Pi 4 |
| 2 | + |
| 3 | +This guide covers deploying the ACT Discord bot to a Raspberry Pi 4 home server. |
| 4 | + |
| 5 | +## 📋 Prerequisites |
| 6 | + |
| 7 | +- Raspberry Pi 4 (ideally 4GB+ RAM) |
| 8 | +- Raspbian/Raspberry Pi OS installed |
| 9 | +- Internet connection |
| 10 | +- SSH access configured |
| 11 | +- GitHub repository access |
| 12 | + |
| 13 | +## 🔐 SSH & Tailscale Setup for GitHub Actions |
| 14 | + |
| 15 | +> [!NOTE] > **You already have Tailscale working!** Since you can `ssh comon@pi4` from different networks, we just need to set up GitHub Actions to use it too. |
| 16 | +
|
| 17 | +### Quick Setup Steps |
| 18 | + |
| 19 | +Follow the detailed guide: [SSH_SETUP.md](./SSH_SETUP.md) |
| 20 | + |
| 21 | +**TL;DR:** |
| 22 | + |
| 23 | +1. Generate SSH key: `ssh-keygen -t ed25519 -f ~/.ssh/act-deploy` |
| 24 | +2. Copy to Pi: `ssh-copy-id -i ~/.ssh/act-deploy.pub comon@pi4` |
| 25 | +3. Get Pi's Tailscale IP: `ssh comon@pi4 "tailscale ip -4"` |
| 26 | +4. Set up GitHub secrets (see below) |
| 27 | + |
| 28 | +### Required GitHub Secrets |
| 29 | + |
| 30 | +Go to your repo → **Settings** → **Secrets and variables** → **Actions**: |
| 31 | + |
| 32 | +| Secret Name | How to Get | |
| 33 | +| -------------------- | --------------------------------------------------------------------------------------------------- | |
| 34 | +| `PI_HOST` | Run on Pi: `tailscale ip -4` (will be like `100.x.x.x`) | |
| 35 | +| `PI_USER` | `comon` | |
| 36 | +| `PI_SSH_KEY` | Content of `~/.ssh/act-deploy` (private key) | |
| 37 | +| `TS_OAUTH_CLIENT_ID` | [Tailscale OAuth](https://login.tailscale.com/admin/settings/oauth) → Create OAuth client → Copy ID | |
| 38 | +| `TS_OAUTH_SECRET` | Same OAuth client → Copy Secret | |
| 39 | + |
| 40 | +> [!TIP] > **Creating Tailscale OAuth Client:** |
| 41 | +> |
| 42 | +> 1. Go to https://login.tailscale.com/admin/settings/oauth |
| 43 | +> 2. Click **Generate OAuth Client** |
| 44 | +> 3. Add tag: `tag:ci` |
| 45 | +> 4. Copy the Client ID and Secret to GitHub secrets |
| 46 | +
|
| 47 | +## 🚀 Initial Setup |
| 48 | + |
| 49 | +### 1. Run Setup Script |
| 50 | + |
| 51 | +SSH into your Pi and run: |
| 52 | + |
| 53 | +```bash |
| 54 | +cd ~ |
| 55 | +git clone https://github.com/Comon-tech/ACT.git |
| 56 | +cd ACT |
| 57 | +chmod +x deployment/setup-pi.sh |
| 58 | +./deployment/setup-pi.sh |
| 59 | +``` |
| 60 | + |
| 61 | +### 2. Configure Environment Variables |
| 62 | + |
| 63 | +Edit the `.env` file with your actual values: |
| 64 | + |
| 65 | +```bash |
| 66 | +nano /home/comon/ACT/.env |
| 67 | +``` |
| 68 | + |
| 69 | +Required variables: |
| 70 | + |
| 71 | +```env |
| 72 | +DISCORD_BOT_TOKEN=your_actual_bot_token |
| 73 | +GEMINI_AI_API_KEY=your_actual_gemini_key |
| 74 | +MONGO_DB_URI=mongodb atlas uri |
| 75 | +APP_SERVER_URL=http://localhost:8001 |
| 76 | +``` |
| 77 | + |
| 78 | +> [!NOTE] > **Port 8001** is used instead of 8000 to avoid conflict with your other app. |
| 79 | +
|
| 80 | +### 3. Start MongoDB |
| 81 | + |
| 82 | +```bash |
| 83 | +# Start MongoDB service |
| 84 | +sudo systemctl start mongodb |
| 85 | + |
| 86 | +# Enable MongoDB to start on boot |
| 87 | +sudo systemctl enable mongodb |
| 88 | +``` |
| 89 | + |
| 90 | +### 4. Start the Bot |
| 91 | + |
| 92 | +```bash |
| 93 | +# Start the service |
| 94 | +sudo systemctl start act-bot.service |
| 95 | + |
| 96 | +# Check status |
| 97 | +sudo systemctl status act-bot.service |
| 98 | + |
| 99 | +# View logs |
| 100 | +sudo journalctl -u act-bot.service -f |
| 101 | +``` |
| 102 | + |
| 103 | +## 🔄 Manual Deployment |
| 104 | + |
| 105 | +To manually deploy updates: |
| 106 | + |
| 107 | +```bash |
| 108 | +cd /home/comon/ACT |
| 109 | +git pull origin main |
| 110 | +sudo systemctl restart act-bot.service |
| 111 | +``` |
| 112 | + |
| 113 | +## 📊 Service Management |
| 114 | + |
| 115 | +```bash |
| 116 | +# Start the bot |
| 117 | +sudo systemctl start act-bot.service |
| 118 | + |
| 119 | +# Stop the bot |
| 120 | +sudo systemctl stop act-bot.service |
| 121 | + |
| 122 | +# Restart the bot |
| 123 | +sudo systemctl restart act-bot.service |
| 124 | + |
| 125 | +# Check status |
| 126 | +sudo systemctl status act-bot.service |
| 127 | + |
| 128 | +# View logs (live) |
| 129 | +sudo journalctl -u act-bot.service -f |
| 130 | + |
| 131 | +# View last 100 lines of logs |
| 132 | +sudo journalctl -u act-bot.service -n 100 |
| 133 | +``` |
| 134 | + |
| 135 | +## 🔧 Troubleshooting |
| 136 | + |
| 137 | +### Bot won't start |
| 138 | + |
| 139 | +1. Check logs: |
| 140 | + |
| 141 | + ```bash |
| 142 | + sudo journalctl -u act-bot.service -n 50 |
| 143 | + ``` |
| 144 | + |
| 145 | +2. Verify environment variables: |
| 146 | + |
| 147 | + ```bash |
| 148 | + cat /home/comon/ACT/.env |
| 149 | + ``` |
| 150 | + |
| 151 | +3. Test manually: |
| 152 | + ```bash |
| 153 | + cd /home/comon/ACT |
| 154 | + uv run python main.py --bot --db |
| 155 | + ``` |
| 156 | + |
| 157 | +### MongoDB connection issues |
| 158 | + |
| 159 | +```bash |
| 160 | +# Check MongoDB status |
| 161 | +sudo systemctl status mongodb |
| 162 | + |
| 163 | +# Check if MongoDB is listening |
| 164 | +sudo netstat -tlnp | grep 1717 |
| 165 | + |
| 166 | +# Start MongoDB if not running |
| 167 | +sudo systemctl start mongodb |
| 168 | +``` |
| 169 | + |
| 170 | +### Port conflict |
| 171 | + |
| 172 | +If port 8001 is also taken, edit `.env` and change `APP_SERVER_URL`: |
| 173 | + |
| 174 | +```env |
| 175 | +APP_SERVER_URL=http://localhost:8002 |
| 176 | +``` |
| 177 | + |
| 178 | +Then restart the service. |
| 179 | + |
| 180 | +### GitHub Actions can't connect |
| 181 | + |
| 182 | +1. Verify Tailscale is running on Pi: |
| 183 | + |
| 184 | + ```bash |
| 185 | + ssh comon@pi4 "tailscale status" |
| 186 | + ``` |
| 187 | + |
| 188 | +2. Verify you're using the correct Tailscale IP in `PI_HOST` secret: |
| 189 | + |
| 190 | + ```bash |
| 191 | + ssh comon@pi4 "tailscale ip -4" |
| 192 | + ``` |
| 193 | + |
| 194 | +3. Check GitHub Actions logs for specific errors |
| 195 | + |
| 196 | +4. Test SSH connection with the deployment key: |
| 197 | + |
| 198 | + ```bash |
| 199 | + ssh -i ~/.ssh/act-deploy comon@TAILSCALE_IP |
| 200 | + ``` |
| 201 | + |
| 202 | +5. Verify Tailscale OAuth credentials are correct in GitHub secrets |
| 203 | + |
| 204 | +## 🔒 Security Recommendations |
| 205 | + |
| 206 | +1. **Use Tailscale** ✅ (you're already doing this!) |
| 207 | +2. **Use SSH keys only** (disable password authentication) |
| 208 | +3. **Keep system updated**: `sudo apt update && sudo apt upgrade` |
| 209 | +4. **Monitor logs regularly**: `sudo journalctl -u act-bot.service -f` |
| 210 | +5. **Rotate SSH keys periodically** (regenerate deployment keys every few months) |
| 211 | + |
| 212 | +## 📝 Notes |
| 213 | + |
| 214 | +- The bot will automatically restart on system boot |
| 215 | +- Logs are managed by systemd journal |
| 216 | +- MongoDB data is stored in the default location |
| 217 | +- The API component is optional (only needed for web integrations) |
0 commit comments