Replies: 6 comments 1 reply
WorkaroundI've hit a similar issue as I wanted to limit the Here's an example of it in use that seems to perform quite well for my use case. This copies all the # syntax=docker/dockerfile:1.7-labs
####################################################################
# base layer that enables pnpm and all package manifests in context
####################################################################
FROM node:20.11.1-alpine AS base
WORKDIR /usr/app
# pnpm setup
FROM base AS pnpm
ENV CI=true
RUN corepack enable pnpm && \
pnpm config set store-dir /pnpm/store && \
pnpm config set package-import-method clone-or-copy
#####################################################################
# manifests layer copies all package.json files and slims them down to
# the bare essentials needed for pnpm install. We'll copy these files
# in the install step rather than from disk, so that changes to other
# areas of the JSON don't break the caching. This works because the
# cache is based on a SHA256 sum of the file contents themselves when
# they're copied, so even though this layer may change / not be in the
# cache, the resulting files will have a consistent SHA256 sum and so
# will receive a cache hit, provided none of the keys have changed.
#####################################################################
FROM base AS manifests
RUN apk add --no-cache jq
COPY --link --chmod=0755 <<'EOF' /bin/slim-manifest
#!/bin/sh
CONTENTS=$(jq 'pick(
.name, .version, .private, .packageManager, .engines, .pnpm, .peerDependenciesMeta,
.dependencies, .devDependencies, .peerDependencies, .optionalDependencies
) | del(.. | nulls)' $1)
echo ${CONTENTS} > $1
EOF
COPY --link --parents **/package.json ./
RUN find . -name package.json -exec slim-manifest {} \;
#######################################################################
# pnpm install (copies only required files for install step for cache)
#######################################################################
FROM pnpm
# Copy package.json files over from the manifests layer, conforming to the same structure as the monorepo
COPY --link --parents --from=manifests /usr/app/./**/package.json ./
# pnpm install for the given package directory
ARG PKG_DIR
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
--mount=type=bind,source=/pkg/pnpm-lock.yaml,target=/usr/app/pnpm-lock.yaml \
--mount=type=bind,source=/pkg/pnpm-workspace.yaml,target=/usr/app/pnpm-workspace.yaml \
pnpm install \
--prefer-offline \
--frozen-lockfile \
--reporter=append-only \
--filter "{${PKG_DIR}}..."
# Rest of your build code here, etc.
RUN pnpm build |
Is this still true? I think the lockfile contains entries for the packages in the monorepo which list their dependencies. |
|
Bean Labs took a public-source pass on this issue. The narrowest useful next step looks like: filtered fetch semantics Public evidence checked:
A good acceptance check would be a docs diff that changes only the affected wording/link and renders without stale references. No PR opened from this pass. |
|
This is implemented in current pnpm, so closing.
If you still hit this on the latest pnpm, please comment with a reproduction and we will reopen. Written by an agent (Claude Code, claude-opus-5). |
|
@zkochan I don't think that's true. I've tried with |
|
Closing as resolved: Posted by an AI agent. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Contribution
Describe the user story
As the owner of a large PNPM monorepo, I would like to be able to utilize
pnpm fetchwithout needing to download every dependency within the monorepo. This would meaningfully improve the ergonomics and efficiency of Docker builds.Describe the solution you'd like
I would like for
pnpm fetchto respect the--filterargument that is present on most other PNPM commands (ie.pnpm install --filter @myOrg/pkg-name...).The addition of this feature should not come with any caveats that would violate the intent of the primary use-case for
pnpm fetch– downloading packages from apnpm-lock.yamlfile without requiring anypackage.jsonfiles to be present. This will allow PNPM users who are using Docker to take better advantage of Docker Layer Caching, without resorting to awkward workarounds (the current Dockerfile syntax lacks the capability to execute a command likeCOPY **/package.json)Implementing this feature would require additional metadata to be added to
pnpm-lock.yaml, as it is not currently possible to derive the dependencies of one of the packages within one's own monorepo from the lockfile alone. I imagine that this will be the most controversial change that would be needed to implement this feature.Describe the drawbacks of your solution
This change would increase the size of the
pnpm-lock.yamlfile, and could increase the frequency with which that file needs to be updated.Describe alternatives you've considered
I can't think of any other options that would allow for efficient Docker builds with a straightforward interface.
pnpm deployis arguably a better option in many Docker workflows, but it can increase build times considerably, and has been fairly buggy to use in practice.All reactions