Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn handling in the Dockerfile doesn't account for modern installs #138

Open
jamesmeneghello opened this issue Jan 21, 2025 · 5 comments
Open

Comments

@jamesmeneghello
Copy link

jamesmeneghello commented Jan 21, 2025

During the build, the dockerfile will pull across the node_modules directory to the final image. This has a few ramifications:

  • Assumes Yarn 1/2 is being used
  • Yarn 3 pnp stores packages in .yarn instead
  • Yarn 3 can be set to use the node_modules linker which still stores packages in node_modules, but requires overriding through .yarnrc.yml, which is also not copied across in the Dockerfile

This should probably be a config option (yarn classic/modern):

Classic: copies node_modules across
Modern: copies .yarn and .yarnrc.yml, and respects node-linker, which means copying either node_modules or .yarn across

@rubys
Copy link
Collaborator

rubys commented Jan 21, 2025

Instead of a config option, is it possible to tell via inspecting the contents of the files on the machine what the right thing to do is?

@jamesmeneghello
Copy link
Author

Yes - the presence of .yarnrc.yml indicates the user is running Yarn 3+. Parsing .yarnrc.yml and pulling out the value of nodeLinker (either node-modules for legacy behaviour or pnp for modern behaviour, default pnp if no value) will let you determine whether the we need to copy .yarn/ (modern, nodeLinker: pnp), node_modules/ (classic), or both (modern, nodeLinker: node-modules).

@rubys
Copy link
Collaborator

rubys commented Jan 22, 2025

A typical Dockerfile produced for a Rails application using a jsBundler looks like the following:

https://github.com/fly-apps/dockerfile-rails/blob/main/test/results/esbuild/Dockerfile#L74-L76

What options are you specifying?

@jamesmeneghello
Copy link
Author

I realised I was missing that info yesterday when I was thinking about it - this is specifically for --precompile=defer. In fairness that's an edge case, and so the purpose of this issue may just be document the issue for others to come across, rather than provide a solution.

@rubys
Copy link
Collaborator

rubys commented Jan 23, 2025

To the contrary, that's totally fair. When I started looking into it I came to the conclusion that it would only apply in that case, and was wondering if I was missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants