Skip to content

fix(deploy): deferred webhook recreate to survive self-rebuild - #270

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
fix/webhook-deferred-restart
Mar 15, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
fix/webhook-deferred-restart

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Mar 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

When deploy.sh runs inside the webhook container (via deploy-wrapper.sh), the docker compose up --force-recreate webhook at the end kills the container it's running inside. This leaves the webhook in Exited(0) state with a mangled container name, breaking subsequent deploys.

Root Cause

deploy.sh lines 462-468 ran docker compose up -d -V --force-recreate --no-deps webhook synchronously as the final step. Since the script runs inside the webhook container, this command kills its own host container mid-execution, leaving Docker in an inconsistent state.

Fix

  1. Build first — docker compose build --no-cache webhook (safe, doesn't kill anything)
  2. Send success notification — deploy is complete before the risky recreate
  3. Release deploy lock — explicitly remove lock dir and clear EXIT trap before the recreate
  4. Detached recreate — nohup docker compose up -d -V --force-recreate --no-deps webhook > /dev/null 2>&1 & so the Docker daemon completes it independently

Testing

After this fix:

  • Automated CI deploys should complete green (HTTP 200 from async wrapper)
  • The webhook container will be recreated by the Docker daemon even if the parent process is killed
  • No stale lock files will be left behind
  • Subsequent deploys will work without manual intervention

Summary by CodeRabbit

  • Chores
    • Optimized deployment workflow by converting webhook container recreation to asynchronous background processing, eliminating blocking operations and accelerating deployment cycles.
    • Improved deployment reliability with enhanced lock management, including cleanup safeguards and better logging visibility into the deployment process flow.

@vercel

vercel Bot commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Mar 15, 2026 3:45pm

Request Review

@netlify

netlify Bot commented Mar 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for regal-bunny-0c8efe ready!

Name Link
🔨 Latest commit 2216efc
🔍 Latest deploy log https://app.netlify.com/projects/regal-bunny-0c8efe/deploys/69b6d3fe98e2ab0008654328
😎 Deploy Preview https://deploy-preview-270--regal-bunny-0c8efe.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Mar 15, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Converts the webhook container recreation in the deployment script from synchronous foreground execution to asynchronous background execution using nohup. Adds explicit lock-release steps before triggering the background process and updates trap handling to allow the current process to exit without blocking.

Changes

Cohort / File(s) Summary
Deploy Script Async Handling
scripts/deploy.sh
Replaces foreground docker-compose recreate with detached nohup process. Adds explicit lock-directory removal and EXIT trap clearing before async recreate. Updates logging and comments to document the asynchronous flow and volume renewal logic.

Sequence Diagram

sequenceDiagram
    participant Deploy as Deploy Process
    participant Lock as Lock Manager
    participant Docker as Docker Compose
    participant Webhook as Webhook Container

    rect rgba(200, 150, 100, 0.5)
    Note over Deploy,Webhook: Previous (Synchronous) Flow
    Deploy->>Lock: Check/hold lock
    Deploy->>Docker: Recreate container (foreground)
    Docker->>Webhook: Recreate & wait
    Webhook-->>Docker: Container ready
    Docker-->>Deploy: Return (blocking)
    Deploy->>Lock: Release lock
    Deploy->>Deploy: Exit process
    end

    rect rgba(100, 150, 200, 0.5)
    Note over Deploy,Webhook: New (Asynchronous) Flow
    Deploy->>Lock: Check/hold lock
    Deploy->>Lock: Explicitly remove lock dir
    Deploy->>Deploy: Clear EXIT trap
    Deploy->>Deploy: Spawn nohup detached recreate
    Deploy->>Lock: Release lock immediately
    Deploy->>Deploy: Exit process (non-blocking)
    par Background Execution
        Docker->>Webhook: Recreate & wait (in background)
        Webhook-->>Docker: Container ready
    end
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

ci, infra, size/s

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: deferring webhook recreation to allow the deploy script to survive self-rebuild, which is the core fix addressing the container crash issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/webhook-deferred-restart
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot added the ci label Mar 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit cd681f3 into main Mar 15, 2026
14 of 15 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2216efcb Deployed Mar 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant