# ๐ 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