fix(docker): reorder build stages so web-build comes after its --from= sources (#2)

Coolify's builder fails the build at parse time with:
  "cannot copy from stage 'collab-build', it needs to be defined before
   current stage 'web-build'"

The previous commit introduced forward COPY --from references that work
on newer BuildKit DAG builders but not on the legacy Docker builder
Coolify uses. Move `collab-build` and `mcp-build` above `web-build` in
lexical order so the references resolve. Functionally identical — the
DAG ordering effect is the same — just expressed in a way the older
builder accepts.

Added a NOTE comment above the stages so the next person who tries to
"clean up" the file order doesn't reintroduce the same regression.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
varutasu 2026-06-05 21:13:39 -05:00 committed by GitHub
parent 3fb79f6f04
commit 491d196384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,6 +39,37 @@ COPY packages/ai/package.json ./packages/ai/
RUN pnpm install --frozen-lockfile
# NOTE: Stage order matters. `web-build` must be defined AFTER `collab-build`
# and `mcp-build` because it `COPY --from=`s them to force BuildKit to
# finish the light tsup builds before starting the heavy Next.js compile.
# Coolify's builder requires stages referenced via `--from=` to be defined
# above the referencing stage; forward references fail with "cannot copy
# from stage X, it needs to be defined before current stage Y".
# ============================================================================
# collab-build — tsup build for Hocuspocus server
# ============================================================================
FROM deps AS collab-build
COPY apps/collab-server ./apps/collab-server
COPY packages/database ./packages/database
ENV NODE_ENV=production
RUN pnpm exec turbo build --filter=@tasks/collab-server
# ============================================================================
# mcp-build — tsup build for MCP server
# ============================================================================
FROM deps AS mcp-build
COPY apps/mcp-server ./apps/mcp-server
COPY packages/database ./packages/database
COPY packages/shared ./packages/shared
ENV NODE_ENV=production
RUN pnpm exec turbo build --filter=@tasks/mcp-server
# ============================================================================
# web-build — Next.js production build → standalone output
# ============================================================================
@ -69,29 +100,6 @@ ENV NODE_OPTIONS=--max-old-space-size=5120
RUN pnpm exec turbo build --filter=@tasks/web
# ============================================================================
# collab-build — tsup build for Hocuspocus server
# ============================================================================
FROM deps AS collab-build
COPY apps/collab-server ./apps/collab-server
COPY packages/database ./packages/database
ENV NODE_ENV=production
RUN pnpm exec turbo build --filter=@tasks/collab-server
# ============================================================================
# mcp-build — tsup build for MCP server
# ============================================================================
FROM deps AS mcp-build
COPY apps/mcp-server ./apps/mcp-server
COPY packages/database ./packages/database
COPY packages/shared ./packages/shared
ENV NODE_ENV=production
RUN pnpm exec turbo build --filter=@tasks/mcp-server
# ============================================================================
# web — runtime image (Next.js standalone)
# ============================================================================