docs: Add zero-downtime changes guide - stop unnecessary rebuilds

PROBLEM: Rebuilding container 4-6 times per session when most changes don't need it
- Every rebuild: 40-70 seconds downtime
- Recent session: 200 seconds downtime that could've been 50 seconds
- Rebuilding for documentation (should be git only)
- Rebuilding for n8n workflows (should be manual import)
- Rebuilding for ENV changes (should be restart only)

SOLUTION: Created comprehensive guide on what actually needs rebuilds

ZERO DOWNTIME (just commit):
- Documentation (.md files)
- Workflows (.json, .pinescript)
- Hot-reload endpoints (roadmap reload)

RESTART ONLY (5-10 seconds):
- ENV variable changes (.env)
- Database schema (prisma migrate + generate)

REBUILD REQUIRED (40-70 seconds):
- Code changes (.ts, .tsx, .js)
- Dependencies (package.json)
- Dockerfile changes

SMART BATCHING:
- Group multiple code changes into ONE rebuild
- Example: 6 fixes → 1 rebuild = 50s total (not 6× rebuilds = 300s)

CREATED FILES:
- docs/ZERO_DOWNTIME_CHANGES.md (comprehensive guide with examples)
- Updated copilot-instructions.md (quick decision matrix)

EXPECTED IMPACT:
- 60-80% reduction in rebuild frequency
- 60-80% reduction in downtime per session
- Better workflow: batch changes, test together, deploy once

User was right: We were rebuilding WAY too often unnecessarily 
This commit is contained in:
mindesbunister
2025-11-27 14:08:42 +01:00
parent 49f19b1a8c
commit a676eb4753
2 changed files with 293 additions and 0 deletions

View File

@@ -571,6 +571,50 @@ docker logs trading-bot-v4 | grep "Server starting" | head -1
**DO NOT use:** `docker compose build trading-bot` in foreground - one network hiccup kills 60s of work
### When to Actually Rebuild vs Restart vs Nothing
**⚠️ CRITICAL: Stop rebuilding unnecessarily - costs 40-70 seconds downtime per rebuild**
**See `docs/ZERO_DOWNTIME_CHANGES.md` for complete guide**
**Quick Decision Matrix:**
| Change Type | Action | Downtime | When |
|------------|--------|----------|------|
| Documentation (`.md`) | **NONE** | 0s | Just commit and push |
| Workflows (`.json`, `.pinescript`) | **NONE** | 0s | Import manually to TradingView/n8n |
| ENV variables (`.env`) | **RESTART** | 5-10s | `docker compose restart trading-bot` |
| Database schema | **MIGRATE + RESTART** | 10-15s | `prisma migrate + restart` |
| Code (`.ts`, `.tsx`, `.js`) | **REBUILD** | 40-70s | TypeScript must recompile |
| Dependencies (`package.json`) | **REBUILD** | 40-70s | npm install required |
**Smart Batching Strategy:**
- **DON'T:** Rebuild after every single code change (6× rebuilds = 6 minutes downtime)
- **DO:** Batch related changes together (6 fixes → 1 rebuild = 50 seconds total)
**Example (GOOD):**
```bash
# 1. Make multiple code changes
vim lib/trading/position-manager.ts
vim app/api/trading/execute/route.ts
vim lib/notifications/telegram.ts
# 2. Commit all together
git add -A && git commit -m "fix: Multiple improvements"
# 3. ONE rebuild for everything
docker compose build trading-bot
docker compose up -d --force-recreate trading-bot
# Total: 50 seconds (not 150 seconds)
```
**Recent Mistakes to Avoid (Nov 27, 2025):**
- ❌ Rebuilt for documentation updates (should be git commit only)
- ❌ Rebuilt for n8n workflow changes (should be manual import)
- ❌ Rebuilt 4 times for 4 code changes (should batch into 1 rebuild)
- ✅ Result: 200 seconds downtime that could have been 50 seconds
### Docker Cleanup After Builds
**CRITICAL: Prevent disk full issues from build cache accumulation**