Skip to content

Add automatic deployment system#3

Merged
Bootjack merged 6 commits intomainfrom
auto-deployment
Mar 1, 2026
Merged

Add automatic deployment system#3
Bootjack merged 6 commits intomainfrom
auto-deployment

Conversation

@mitzimare
Copy link
Copy Markdown
Collaborator

Summary

Implements polling-based automatic deployment that detects when the main branch is updated and automatically deploys changes to the host system.

Key Features

  • Polling Loop: Checks origin/main every 60 seconds (configurable via AUTO_DEPLOY_POLL_INTERVAL)
  • Full Deployment Pipeline:
    • Record current state (for rollback capability)
    • Stash uncommitted changes (non-destructive)
    • Pull latest changes from origin/main
    • Analyze what changed (dependencies, source code, etc.)
    • Install dependencies (if package.json changed)
    • Build TypeScript (if source changed)
    • Restart systemd service
    • Verify service is running
  • Real-Time Notifications: Sends deployment progress updates to main chat
  • Error Handling: Comprehensive error handling with notifications on failure
  • Safety: Read-only git operations, non-destructive stashing, rollback info recorded

Configuration

# Disable auto-deployment (enabled by default)
AUTO_DEPLOY_ENABLED=false

# Change polling interval (default: 60000ms = 1 minute)
AUTO_DEPLOY_POLL_INTERVAL=120000  # Check every 2 minutes

Example Notifications

Successful deployment:

🔄 Deployment started
Current commit: a1b2c3d

📊 Changes detected
• 12 files changed
• Dependencies: No
• Source code: Yes

🔨 Building TypeScript...

🔄 Restarting service...

✅ Deployment successful!
• Previous: a1b2c3d
• Current: e4f5g6h
• Duration: 45.2s

Failed deployment:

❌ Deployment failed!
• Error: Failed to restart service: Unit not found
• Duration: 15.3s
• Manual intervention may be required

Changes

  • src/auto-deploy.ts: Core deployment logic and polling loop
  • src/index.ts: Wire up auto-deploy on startup (notifies main chat)
  • src/config.ts: Add AUTO_DEPLOY_* config, export PROJECT_ROOT and HOME_DIR
  • docs/AUTO_DEPLOYMENT.md: Comprehensive documentation (usage, config, troubleshooting, security)

Testing Plan

Once PR #3 is merged:

  1. Auto-deployment will be active on the host
  2. Merge PR feat: Add Firefox audio support and pre-install Widevine CDM #2 (browser-audio-drm-fixes)
  3. Within ~1 minute, auto-deployment should detect the change and deploy it
  4. You'll receive notifications in your main chat about the deployment
  5. Verify PR feat: Add Firefox audio support and pre-install Widevine CDM #2 changes are live on the host

This PR sets up the infrastructure, and PR #2 will be the first real test of the automation!

Security Considerations

  • ✅ Read-only git operations (only fetch/pull)
  • ✅ Non-destructive stashing of local changes
  • ✅ Rollback information recorded before deployment
  • ✅ Service verification after restart
  • ❌ No automatic rollback on failure (manual intervention required)
  • ❌ Container rebuild not yet automated (Dockerfile changes require manual rebuild)

Future Enhancements

  • Automatic rollback on service failure
  • Health checks after deployment
  • Deployment approval flow (manual confirmation)
  • Webhook support (instead of polling)
  • Deploy only on git tags (e.g., v1.0.0)
  • Container rebuild detection

Documentation

See docs/AUTO_DEPLOYMENT.md for:

  • How it works
  • Configuration options
  • Notification examples
  • Security considerations
  • Troubleshooting guide
  • Manual rollback procedures
  • Comparison to manual deployment

Implements polling-based auto-deployment that detects changes to the main
branch and automatically deploys them to the host system.

Features:
- Polls origin/main every 60 seconds (configurable) for new commits
- Executes full deployment: pull, install deps, build, restart service
- Sends real-time notifications to main chat about deployment progress
- Handles uncommitted changes by stashing them
- Verifies service is running after deployment
- Comprehensive error handling and notifications

Configuration:
- AUTO_DEPLOY_ENABLED (default: true)
- AUTO_DEPLOY_POLL_INTERVAL (default: 60000ms)

Changes:
- src/auto-deploy.ts: Core deployment logic and polling loop
- src/index.ts: Wire up auto-deploy on startup
- src/config.ts: Add auto-deploy config, export PROJECT_ROOT and HOME_DIR
- docs/AUTO_DEPLOYMENT.md: Comprehensive documentation

This will enable PR #2 to deploy automatically once PR #3 is merged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread docs/AUTO_DEPLOYMENT.md Outdated
AUTO_DEPLOY_ENABLED=false

# Change polling interval (default: 60000ms = 1 minute)
AUTO_DEPLOY_POLL_INTERVAL=120000 # Check every 2 minutes
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polling faster than 1 second is never going to be reasonable, so we don't need millisecond precision here. To make the configuration more obvious and hint at its intent, lets configure by seconds instead

Comment thread docs/AUTO_DEPLOYMENT.md Outdated
- ✅ Documentation updates
- ✅ Any other changes to tracked files

**Note:** Container rebuild (Dockerfile changes) is not yet automated. If the Dockerfile changes, you'll need to rebuild manually:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why stop here? We should automate this part, too.

Changed AUTO_DEPLOY_POLL_INTERVAL (ms) to AUTO_DEPLOY_POLL_INTERVAL_SECONDS
to make configuration more obvious and hint at its intent. Sub-second polling
is never reasonable for git operations.

Changes:
- src/config.ts: Rename to AUTO_DEPLOY_POLL_INTERVAL_SECONDS, default 60
- src/index.ts: Convert seconds to ms when calling startAutoDeployLoop
- docs/AUTO_DEPLOYMENT.md: Update all examples to use seconds

Examples:
- Default: 60 (1 minute)
- Production: 300 (5 minutes)
- Development: 30 (30 seconds)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread docs/AUTO_DEPLOYMENT.md
### What It CAN Do

- ✅ Pull changes from `origin/main`
- ✅ Stash local uncommitted changes (non-destructively)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When manually validating these steps, I encountered files that were committed to the branch in the container, but were untracked on the host. Pulling from main after the branch was merged caused a conflict and git prevented the pull. How does this automation address that scenario?

Comment thread docs/AUTO_DEPLOYMENT.md Outdated
Comment on lines +153 to +155
## Manual Rollback

If auto-deployment causes issues, you can manually roll back:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can tell that the npm install/build, docker build, or service restart failed, we should automatically trigger a rollback to the previous commit and rerun everything to build and restart the service from that (theoretically) known-working state.

- Add --include-untracked flag to git stash to catch untracked files
- This addresses scenario where files are committed in container but untracked on host
- Update documentation to explain this behavior and differentiate from true merge conflicts
Comment thread docs/AUTO_DEPLOYMENT.md Outdated
Comment on lines +291 to +297
GitHub API has rate limits for fetching:
- **Authenticated**: 5,000 requests/hour
- **Unauthenticated**: 60 requests/hour

With 1-minute polling, you'll make 60 requests/hour, which is fine for authenticated access.

**Solution**: Ensure git credentials are configured for authenticated access.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this in mind, we should default to 2-minute polling. That way any problem with authentication would only burn through half the allotted request rate, worst case.

Jason Hinebaugh (via Mitzi) added 2 commits March 1, 2026 14:50
- On any critical failure (install, build, container rebuild, restart, verify), automatically:
  - Reset to previous commit with git reset --hard
  - Reinstall dependencies
  - Rebuild TypeScript
  - Restart service
  - Verify service is active
- Send detailed notifications during rollback process
- If rollback fails, notify user that manual intervention is required
- Update documentation to explain automatic rollback behavior
- More conservative rate to avoid GitHub API limits
- With 2-minute polling: 30 requests/hour (safe even without auth)
- With 1-minute polling: 60 requests/hour (exhausts unauthenticated limit)
- Update all documentation to reflect new default
- Adjust examples to show 2 minutes as balanced default
@Bootjack Bootjack merged commit 1fcfb02 into main Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants