Skip to content

Why your PaaS deploy hangs on the build step

A PaaS deploy that runs cleanly locally hangs at "Building image" for ten or fifteen minutes before timing out. Here is what is blocked and how to fix it.

You push to main, the PaaS pipeline starts, the “Build” step prints the first few lines of output, and then nothing. Ten minutes later the deploy times out. The same build runs in 90 seconds on your laptop. The platform isn’t broken; the build is doing work it shouldn’t be doing.

What’s happening

A PaaS build runs in a sandboxed environment with constrained CPU and memory and a smaller filesystem cache than your laptop. Three classes of work that look fast locally turn pathological:

  • Dependency resolution against a slow or rate-limited registry. npm with no lockfile, Composer with --no-cache, pip pulling wheels over constrained egress.
  • Native compilation of dependencies you didn’t pull as prebuilt wheels. node-gyp building from source; sharp rebuilding libvips; cryptography compiling OpenSSL bindings.
  • A RUN step that copies the source tree before installing dependencies, busting the layer cache on every commit.

The hang isn’t a hang. It is honest work in the wrong layer, with no progress output because the tool buffered stdout.

How to verify

Pull the raw build logs (most PaaS panels expose a “raw log” toggle) and find the last line before the gap. Common signatures:

  • node-gyp configure or gyp info spawn — native module compilation.
  • Resolving dependencies for Composer with no further output — registry timeout.
  • Building wheel for cryptography — OpenSSL compile.
  • A long silence right after COPY . . — the next layer is downloading everything fresh because the cache key changed.

Reproduce locally against a clean cache (docker buildx build --platform linux/amd64). If the clean-cache build takes 12 minutes locally, the PaaS isn’t slow — your build is.

The fix

  1. Commit your lockfile. package-lock.json, composer.lock, pipfile.lock, cargo.lock. Every build starts from the same dependency graph.
  2. Restructure the Dockerfile to copy lockfile + manifest first, install dependencies, then copy source. The dependency-install layer caches on lockfile content, not source content.
  3. Pin to platforms with prebuilt binaries available. node:20-slim on linux/amd64 instead of node:20-alpine if alpine forces source compilation of native modules.
  4. Use the platform’s build cache where available — most managed PaaS expose a persistent cache mount for ~/.npm, ~/.cache/composer, ~/.cache/pip.
  5. If the registry is the bottleneck, mirror it. A private package proxy (Verdaccio, Sonatype Nexus, GitHub Packages) inside the same network turns 30-second downloads into 1-second downloads.

A healthy PaaS build for a typical web application is two to four minutes. If yours is longer, the layer hierarchy is wrong before the registry is slow.

Stack Harbor’s Cloud PaaS practice templates the build pipeline as part of platform onboarding — we can audit yours.