Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Speed up Docker installs with pnpm fetch and offline linking.

debajyoti-truefoundry06ca6ab7e918
diff --git a/packages/frontend/Dockerfile b/packages/frontend/Dockerfile
index 144639fec..4b380ddbb 100644
--- a/packages/frontend/Dockerfile
+++ b/packages/frontend/Dockerfile
@@ -2,23 +2,32 @@
#
# Multi-stage build for the private frontend app (not published to npm).
# Context must be the repository root (pnpm workspace).
+#
+# Dependency install uses pnpm fetch (lockfile-only) then install --offline so
+# the download layer stays cached when only package.json / scripts change.
+# See https://pnpm.io/cli/fetch
FROM node:24-slim AS base
ENV PNPM_HOME=/pnpm
ENV PATH="$PNPM_HOME:$PATH"
-RUN corepack enable
+RUN corepack enable && pnpm config set store-dir /pnpm/store
WORKDIR /app
FROM base AS builder
-COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
+# Populate the store from the lockfile only (stable when manifests churn).
+COPY pnpm-lock.yaml pnpm-workspace.yaml ./
COPY patches patches
+RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm fetch
+
+COPY package.json .npmrc ./
COPY packages/harness/package.json packages/harness/package.json
COPY packages/server/package.json packages/server/package.json
COPY packages/frontend/package.json packages/frontend/package.json
# Root postinstall builds utils gen scripts — copy the inputs it needs.
COPY packages/harness/scripts packages/harness/scripts
COPY packages/harness/src/core/sandbox/scripts packages/harness/src/core/sandbox/scripts
-RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --filter frontend...
+RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
+ pnpm install --frozen-lockfile --offline --filter frontend...
COPY packages/frontend packages/frontend
RUN pnpm --filter frontend build
diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile
index e8b7c9225..1fee9ba1b 100644
--- a/packages/server/Dockerfile
+++ b/packages/server/Dockerfile
@@ -5,19 +5,27 @@
# The build context must be the repository root (this is a pnpm workspace and
# the server depends on the workspace package @truefoundry/utils). See the
# docker-compose.yml / build command at the repo root.
+#
+# Dependency install uses pnpm fetch (lockfile-only) then install --offline so
+# the download layer stays cached when only package.json / scripts change.
+# See https://pnpm.io/cli/fetch
FROM node:24-slim AS base
ENV PNPM_HOME=/pnpm
ENV PATH="$PNPM_HOME:$PATH"
-RUN corepack enable
+RUN corepack enable && pnpm config set store-dir /pnpm/store
WORKDIR /app
# ---------------------------------------------------------------------------
# builder: install all deps (incl. dev) and build utils + server.
# ---------------------------------------------------------------------------
FROM base AS builder
-COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc tsconfig.base.json ./
+# Populate the store from the lockfile only (stable when manifests churn).
+COPY pnpm-lock.yaml pnpm-workspace.yaml ./
COPY patches patches
+RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm fetch
+
+COPY package.json .npmrc tsconfig.base.json ./
COPY packages/harness/package.json packages/harness/package.json
COPY packages/server/package.json packages/server/package.json
# Workspace lockfile lists frontend; package.json must exist for install.
@@ -26,7 +34,8 @@ COPY packages/frontend/package.json packages/frontend/package.json
# the generator script and the sandbox Python sources it inlines.
COPY packages/harness/scripts packages/harness/scripts
COPY packages/harness/src/core/sandbox/scripts packages/harness/src/core/sandbox/scripts
-RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --filter @truefoundry/server...
+RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
+ pnpm install --frozen-lockfile --offline --filter @truefoundry/server...
COPY packages/harness packages/harness
COPY packages/server packages/server
RUN pnpm --filter @truefoundry/utils build && pnpm --filter @truefoundry/server build
@@ -35,15 +44,19 @@ RUN pnpm --filter @truefoundry/utils build && pnpm --filter @truefoundry/server
# prod-deps: resolve only production dependencies (no dev tooling).
# ---------------------------------------------------------------------------
FROM base AS prod-deps
-COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
+COPY pnpm-lock.yaml pnpm-workspace.yaml ./
COPY patches patches
+RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm fetch --prod
+
+COPY package.json .npmrc ./
COPY packages/harness/package.json packages/harness/package.json
COPY packages/server/package.json packages/server/package.json
COPY packages/frontend/package.json packages/frontend/package.json
# Same as builder: the root postinstall hook needs the build:gen inputs.
COPY packages/harness/scripts packages/harness/scripts
COPY packages/harness/src/core/sandbox/scripts packages/harness/src/core/sandbox/scripts
-RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prod --filter @truefoundry/server...
+RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
+ pnpm install --frozen-lockfile --offline --prod --filter @truefoundry/server...
# ---------------------------------------------------------------------------
# runner: minimal image with prod node_modules + built artifacts.