Back to DevLog

Zero Deploy Failures: Rewrote Our Entire Deploy Script and Shipped to 9 Apps

3 min read

Had one of those satisfying coding sessions where everything just clicks. Completely rewrote our deploy.sh script and got it working so well that I deployed to all 9 golden apps with zero failures. Let me walk you through what went down.

The Problem: Deploy Script Was Broken

Our deployment was using some janky SFTP/expect combo that kept failing. I'd been putting off fixing it, but today was the day. Ripped out 246 lines of broken code and replaced it with 134 lines of clean SSH key auth using a simple cat | ssh pattern.

The Bash Gotcha That Cost Me Hours

Found a nasty bug in our deploy loop: (( VOK++ )) exits with status 1 when VOK starts at 0. In bash, (( 0 )) is false, so our && chains were breaking and reporting false failures. The fix was simple once I figured it out: VOK=$(( VOK + 1 )) instead.

This is why I love build-in-public - sharing these gotchas saves everyone time.

The Root Cause: Missing Directories

Turns out we were getting 30+ failures per app because remote directories like js/, img/, theme/verticals/ didn't exist on the server. Added mkdir -p to the deploy function and suddenly everything started working.

The new deploy primitive is clean:

cat file | ssh master "mkdir -p '$dir' && cat > '$dest' && (chmod 664 '$dest' 2>/dev/null || true)"

Permission Drama on Cloudways

Files are owned by app system users, but we deploy as a master user. Write operations succeed, but chmod fails - and that's expected. Made chmod non-fatal since the write is what actually matters.

The Golden Deploy

After fixing all these issues, deployed to all 9 apps:

  • photo-booth: 115 files ✓
  • plumbers: 146 files (115 base + 31 vertical) ✓
  • gyms: 140 files ✓
  • barbershops: 140 files ✓
  • hvac: 140 files ✓
  • medspas: 147 files ✓
  • realtors: 148 files ✓
  • roofers: 140 files ✓
  • electricians: 134 files ✓

Zero failures across the board. Flushed WordPress rewrites and cleared Breeze cache on all apps.

What's Next

Now that deployments are rock solid, I can focus on the fun stuff:

  1. SEO audit on the medspa demo site
  2. Adding hubSlugs to verticals.json
  3. Investigating why the realtor app theme might not be active
  4. Cleaning up some hardcoded URLs in the header

Feels good to have reliable deployments again. There's something deeply satisfying about deleting more code than you write and ending up with something that actually works.

Share this post