This won’t work in the case of the workspace setup since the node_modules folder for my app just contains symlinks, not the actual node_modules, that’s the essential problem I’m facing.
Right, what the Dockerfile is doing is building the store first inside the image using pnpm fetch. Then, when the Dockerfile does pnpm install inside the image, the resulting links in the generated node_modules are pointing to the store path inside the image. When you do COPY . ., either your .gitignore file is already ignoring node_modules or you have a separate .dockerignore file which should also exclude node_modules; thus, when copying files into the image, you're never copying the node_modules folder and thus links inside the node_modules folder to places on your host laptop are irrelevant.
Hm, thank you for the explanation but I'm still not 100% sure how it would apply.
> thus links inside the node_modules folder to places on your host laptop are irrelevant
I'm not talking about the host computer at any point of this, this is about the workspace setup, all of which happens inside the image, since packages within the workspace depend on each other the whole workspace needs to be built together in the image.
I am willing to admit that I am missing something but I'm just not sure what exactly.
Whenever pnpm installs workspace dependencies, it installs them at the root of the workspace, (in the store inside the docker build image of course, not on the host), and those are the dependencies for all 3 packages all together in one virtual store, here:
./node_modules/.pnpm
So, when I want to create my container image for say packages/app1, I don't see how I could copy only my dependencies for that app from the build image like this:
Because while of course the dependencies are installed in the build image, they are at the root of the workspace in virtual store there, and not in /app/packages/app2/node_modules/ – this directory only contains symlinks to the root virtual store.
Of course I can copy all the dependencies from the root virtual store of the build image into my image, but then those are the dependencies for ALL packages in the workspace, not just for app1
I suppose I could try to install only the dependencies for app1, but this is broken with the default pnpm settings at the moment (it still installs dependencies for everything in the workspace)
After talking to one of the contributors on Discord, it seems that they have a special "deploy" command for exactly this (copying files and dependencies for a single workspace package) which I had overlooked since the documentation for it wasn't so self explanatory, they have now updated the docs for this command [1] and opened a PR to update the docs for the Monorepo Docker example to use it instead [2].
I have to say I'm impressed with how responsive the maintainers were to my question, and this `pnpm deploy` workflow does actually make sense to me.
If you're concerned about copying the entire virtual store into the final production image, then you could also run https://pnpm.io/cli/deploy to get a smaller dist folder suitable for copying into another container layer, did you try that?
> COPY --from=deps /app/node_modules /app/node_modules
This won’t work in the case of the workspace setup since the node_modules folder for my app just contains symlinks, not the actual node_modules, that’s the essential problem I’m facing.