fix(docker): preserve pnpm workspace metadata

This commit is contained in:
Altay
2026-05-09 11:39:46 +03:00
committed by Peter Steinberger
parent 8b95270cc9
commit fe0cbf1c40
2 changed files with 23 additions and 5 deletions

View File

@@ -116,13 +116,16 @@ ARG OPENCLAW_BUNDLED_PLUGIN_DIR
# workspace tree subset used during `pnpm install`. The build stage only copied
# the root, `ui`, and opted-in plugin manifests into the install layer, so
# prune must not rediscover unrelated workspaces from the later full source
# copy.
RUN printf 'packages:\n - .\n - ui\n' > /tmp/pnpm-workspace.runtime.yaml && \
# copy. Restore the source workspace config after prune so runtime pnpm keeps
# patch metadata and package-manager policy.
RUN cp pnpm-workspace.yaml /tmp/pnpm-workspace.source.yaml && \
printf 'packages:\n - .\n - ui\n' > /tmp/pnpm-workspace.runtime.yaml && \
for ext in $(printf '%s\n' "$OPENCLAW_EXTENSIONS" | tr ',' ' '); do \
printf ' - %s/%s\n' "$OPENCLAW_BUNDLED_PLUGIN_DIR" "$ext" >> /tmp/pnpm-workspace.runtime.yaml; \
done && \
cp /tmp/pnpm-workspace.runtime.yaml pnpm-workspace.yaml && \
CI=true NPM_CONFIG_FROZEN_LOCKFILE=false pnpm prune --prod && \
cp /tmp/pnpm-workspace.source.yaml pnpm-workspace.yaml && \
node scripts/postinstall-bundled-plugins.mjs && \
OPENCLAW_EXTENSIONS="$OPENCLAW_EXTENSIONS" node scripts/prune-docker-plugin-dist.mjs && \
find dist -type f \( -name '*.d.ts' -o -name '*.d.mts' -o -name '*.d.cts' -o -name '*.map' \) -delete && \

View File

@@ -143,14 +143,29 @@ describe("Dockerfile", () => {
});
it("keeps package manager patch files in runtime images", async () => {
const dockerfile = await readFile(dockerfilePath, "utf8");
const dockerfile = collapseDockerContinuations(await readFile(dockerfilePath, "utf8"));
const pnpmWorkspace = YAML.parse(await readFile(pnpmWorkspacePath, "utf8")) as {
patchedDependencies?: Record<string, string>;
};
const saveSourceWorkspace = "cp pnpm-workspace.yaml /tmp/pnpm-workspace.source.yaml";
const usePruneWorkspace = "cp /tmp/pnpm-workspace.runtime.yaml pnpm-workspace.yaml";
const pruneProd = "CI=true NPM_CONFIG_FROZEN_LOCKFILE=false pnpm prune --prod";
const restoreSourceWorkspace = "cp /tmp/pnpm-workspace.source.yaml pnpm-workspace.yaml";
const finalWorkspaceCopy =
"COPY --from=runtime-assets --chown=node:node /app/pnpm-workspace.yaml .";
expect(Object.keys(pnpmWorkspace.patchedDependencies ?? {})).not.toHaveLength(0);
expect(dockerfile).toContain(
"COPY --from=runtime-assets --chown=node:node /app/pnpm-workspace.yaml .",
expect(dockerfile).toContain(saveSourceWorkspace);
expect(dockerfile).toContain(usePruneWorkspace);
expect(dockerfile).toContain(restoreSourceWorkspace);
expect(dockerfile).toContain(finalWorkspaceCopy);
expect(dockerfile.indexOf(saveSourceWorkspace)).toBeLessThan(
dockerfile.indexOf(usePruneWorkspace),
);
expect(dockerfile.indexOf(usePruneWorkspace)).toBeLessThan(dockerfile.indexOf(pruneProd));
expect(dockerfile.indexOf(pruneProd)).toBeLessThan(dockerfile.indexOf(restoreSourceWorkspace));
expect(dockerfile.indexOf(restoreSourceWorkspace)).toBeLessThan(
dockerfile.indexOf(finalWorkspaceCopy),
);
expect(dockerfile).toContain(
"COPY --from=runtime-assets --chown=node:node /app/patches ./patches",