# ๐Ÿ”„ Auto-Update System
**๐Ÿš€ Automatic updates to keep your installation current** *Set it and forget it*
--- ## ๐ŸŽฏ What is Auto-Update? The automatic update system runs **after script completion** to keep your installation current with the latest features, bug fixes, and security patches. ### **Key Features** - ๐Ÿ”„ **Automatic updates** โ€” Runs after each script completion - ๐Ÿ›ก๏ธ **Safe by design** โ€” Fast-forward only Git updates - ๐Ÿณ **Docker support** โ€” Container image updates - ๐Ÿ› ๏ธ **Custom scripts** โ€” Extensible update process - ๐Ÿ”’ **Error resilient** โ€” Failed updates don't break main script --- ## โš™๏ธ Configuration ### **Basic Setup** ```json { "update": { "git": true, "docker": false, "scriptPath": "setup/update/update.mjs" } } ``` ### **Configuration Options** | Setting | Description | Default | |---------|-------------|---------| | `git` | Enable Git-based updates | `true` | | `docker` | Enable Docker container updates | `false` | | `scriptPath` | Path to custom update script | `"setup/update/update.mjs"` | --- ## ๐Ÿš€ Update Methods ### **Git Updates (`git: true`)** #### **What It Does** - ๐Ÿ“ฅ **Fetches latest changes** from remote repository - โšก **Fast-forward only pulls** (safe updates) - ๐Ÿ“ฆ **Reinstalls dependencies** (`npm ci`) - ๐Ÿ”จ **Rebuilds the project** (`npm run build`) #### **Requirements** - โœ… Git installed and available in PATH - โœ… Repository is a Git clone (not downloaded ZIP) - โœ… No uncommitted local changes - โœ… Internet connectivity #### **Process** ```bash git fetch --all --prune git pull --ff-only npm ci npm run build ``` ### **Docker Updates (`docker: true`)** #### **What It Does** - ๐Ÿ“ฅ **Pulls latest container images** - ๐Ÿ”„ **Restarts services** with new images - ๐Ÿ’พ **Preserves configurations** and mounted volumes #### **Requirements** - โœ… Docker and Docker Compose installed - โœ… `docker-compose.yml` file present - โœ… Proper container registry access #### **Process** ```bash docker compose pull docker compose up -d ``` --- ## ๐Ÿ› ๏ธ Custom Update Scripts ### **Default Script** - **Path** โ€” `setup/update/update.mjs` - **Format** โ€” ES modules - **Arguments** โ€” Command line flags ### **Script Arguments** - `--git` โ€” Enable Git update process - `--docker` โ€” Enable Docker update process - Both flags can be combined ### **Custom Script Example** ```javascript // custom-update.mjs import { execSync } from 'child_process' const args = process.argv.slice(2) if (args.includes('--git')) { console.log('๐Ÿ”„ Running custom Git update...') execSync('git pull && npm install', { stdio: 'inherit' }) } if (args.includes('--docker')) { console.log('๐Ÿณ Running custom Docker update...') execSync('docker-compose pull && docker-compose up -d', { stdio: 'inherit' }) } ``` --- ## โฐ Execution Timing ### **When Updates Run** | Scenario | Update Runs | |----------|-------------| | **Normal completion** | โœ… All accounts processed successfully | | **Error completion** | โœ… Script finished with errors but completed | | **Interruption** | โŒ Script killed or crashed mid-execution | ### **Update Sequence** 1. **๐Ÿ Main script completion** โ€” All accounts processed 2. **๐Ÿ“Š Conclusion webhook** sent (if enabled) 3. **๐Ÿš€ Update process begins** 4. **๐Ÿ“ฅ Git updates** (if enabled) 5. **๐Ÿณ Docker updates** (if enabled) 6. **๐Ÿ”š Process exits** --- ## ๐Ÿ›ก๏ธ Safety Features ### **Git Safety** - โšก **Fast-forward only** โ€” Prevents overwriting local changes - ๐Ÿ“ฆ **Dependency verification** โ€” Ensures `npm ci` succeeds - ๐Ÿ”จ **Build validation** โ€” Confirms TypeScript compilation works ### **Error Handling** - โœ… **Update failures** don't break main script - ๐Ÿ”‡ **Silent failures** โ€” Errors logged but don't crash process - ๐Ÿ”„ **Rollback protection** โ€” Failed updates don't affect current installation ### **Concurrent Execution** - ๐Ÿ”’ **Single update process** โ€” Multiple instances don't conflict - ๐Ÿšซ **Lock-free design** โ€” No file locking needed - ๐ŸŽฏ **Independent updates** โ€” Each script copy updates separately --- ## ๐Ÿ“Š Monitoring Updates ### **Log Output** ``` [UPDATE] Starting post-run update process [UPDATE] Git update enabled, Docker update disabled [UPDATE] Running: git fetch --all --prune [UPDATE] Running: git pull --ff-only [UPDATE] Running: npm ci [UPDATE] Running: npm run build [UPDATE] Update completed successfully ``` ### **Update Verification** ```powershell # Check if updates are pending git status # View recent commits git log --oneline -5 # Verify build status npm run build ``` --- ## ๐Ÿ“‹ Use Cases ### **Development Environment** | Benefit | Description | |---------|-------------| | **Synchronized** | Keep local installation current with repository | | **Automated** | Automatic dependency updates | | **Seamless** | Integration of bug fixes and features | ### **Production Deployment** | Benefit | Description | |---------|-------------| | **Security** | Automated security patches | | **Features** | Updates without manual intervention | | **Consistent** | Same update process across servers | ### **Docker Environments** | Benefit | Description | |---------|-------------| | **Images** | Container image updates | | **Security** | Patches in base images | | **Automated** | Service restarts | --- ## ๐Ÿ“‹ Best Practices ### **Git Configuration** - ๐Ÿงน **Clean working directory** โ€” Commit or stash local changes - ๐ŸŒฟ **Stable branch** โ€” Use `main` or `stable` for auto-updates - ๐Ÿ“ **Regular commits** โ€” Keep repository history clean - ๐Ÿ’พ **Backup data** โ€” Sessions and accounts before updates ### **Docker Configuration** - ๐Ÿท๏ธ **Image tagging** โ€” Use specific tags, not `latest` for production - ๐Ÿ’พ **Volume persistence** โ€” Ensure data volumes are mounted - ๐Ÿ”— **Service dependencies** โ€” Configure proper startup order - ๐ŸŽฏ **Resource limits** โ€” Set appropriate memory and CPU limits ### **Monitoring** - ๐Ÿ“ **Check logs regularly** โ€” Monitor update success/failure - ๐Ÿงช **Test after updates** โ€” Verify script functionality - ๐Ÿ’พ **Backup configurations** โ€” Preserve working setups - ๐Ÿ“Š **Version tracking** โ€” Record successful versions --- ## ๐Ÿ› ๏ธ Troubleshooting ### **Git Issues** | Error | Solution | |-------|----------| | **"Not a git repository"** | Clone repository instead of downloading ZIP | | **"Local changes would be overwritten"** | Commit or stash local changes | | **"Fast-forward not possible"** | Repository diverged - reset to remote state | #### **Git Reset Command** ```powershell # Reset to remote state (โš ๏ธ loses local changes) git fetch origin git reset --hard origin/main ``` ### **Docker Issues** | Error | Solution | |-------|----------| | **"Docker not found"** | Install Docker and Docker Compose | | **"Permission denied"** | Add user to docker group | | **"No docker-compose.yml"** | Create compose file or use custom script | #### **Docker Permission Fix** ```powershell # Windows: Ensure Docker Desktop is running # Linux: Add user to docker group sudo usermod -aG docker $USER ``` ### **Network Issues** | Error | Solution | |-------|----------| | **"Could not resolve host"** | Check internet connectivity | | **"Connection timeout"** | Check firewall and proxy settings | --- ## ๐Ÿ”ง Manual Updates ### **Git Manual Update** ```powershell git fetch --all --prune git pull --ff-only npm ci npm run build ``` ### **Docker Manual Update** ```powershell docker compose pull docker compose up -d ``` ### **Dependencies Only** ```powershell npm ci npm run build ``` --- ## โš™๏ธ Update Configuration ### **Complete Disable** ```json { "update": { "git": false, "docker": false } } ``` ### **Selective Enable** ```json { "update": { "git": true, // Keep Git updates "docker": false // Disable Docker updates } } ``` ### **Custom Script Path** ```json { "update": { "git": true, "docker": false, "scriptPath": "my-custom-update.mjs" } } ``` --- ## ๐Ÿ”’ Security Considerations ### **Git Security** - โœ… **Trusted remote** โ€” Updates pull from configured remote only - โšก **Fast-forward only** โ€” Prevents malicious rewrites - ๐Ÿ“ฆ **NPM registry** โ€” Dependencies from official registry ### **Docker Security** - ๐Ÿท๏ธ **Verified images** โ€” Container images from configured registries - โœ๏ธ **Image signatures** โ€” Verify when possible - ๐Ÿ” **Security scanning** โ€” Regular scanning of base images ### **Script Execution** - ๐Ÿ‘ค **Same permissions** โ€” Update scripts run with same privileges - ๐Ÿšซ **No escalation** โ€” No privilege escalation during updates - ๐Ÿ” **Review scripts** โ€” Custom scripts should be security reviewed --- ## ๐ŸŽฏ Environment Examples ### **Development** ```json { "update": { "git": true, "docker": false } } ``` ### **Production** ```json { "update": { "git": false, "docker": true } } ``` ### **Hybrid** ```json { "update": { "git": true, "docker": true, "scriptPath": "setup/update/production-update.mjs" } } ``` --- ## ๐Ÿ”— Related Guides - **[Getting Started](./getting-started.md)** โ€” Initial setup and configuration - **[Docker](./docker.md)** โ€” Container deployment and management - **[Scheduler](./schedule.md)** โ€” Automated timing and execution - **[Security](./security.md)** โ€” Privacy and data protection