This will not only work for building Docker images but also for using tools like GCP Cloud Functions or AWS Lambda. After much thought, our solution is going to be a private NPM registry. How does this fit in your vision? Even if you only deploy frontend, you'll still need common to be available as well. For example, frontend and backend will both have a dependency on common. Workspaces typically cross-reference each others. One could make the build context the entire monorepo but the lock file will still be changing a lot even if the dependencies of the package we're trying to build have not changed. If nothing changed, then nothing gets rebuilt, of course. If next time we build this image, package.json and yarn.lockfile didn't change, only layer 4 has to be rebuilt. Because we first copy the package.json and the lockfile and then run yarn install. Specifically, what prevents you from copying the global lockfile into your workspace, then run a yarn install to prune the unused entries? You'd end up with a deterministic lockfile that would only change when the workspace dependencies actually change.Īgain, this might be an oversimplification but it gets the point across.Do you run yarn install before building the image, or from within the image? I'd have thought that the image was compiled with the install artifacts (by which point you don't really need to have the lockfile at all?), but maybe that's an incorrect assumption.Workspaces typically cross-reference each others.But since there is no lockfile in this folder, you cannot run an install there.ĭid I understand correctly? If so, a few questions:.This way, Docker wouldn't see its content change unless the files inside it actually change. To solve that, you'd like to deploy a single folder from the monorepo, independent from its neighbours.So when deploying a monorepo, the layer cache for each workspace gets busted at each modification in each workspace.Docker will compare the content of the folder with what's on the latest image, and if it didn't change it won't create a new layer. You create a Docker image by essentially passing it a folder path (your project path).Let's see if I understand this properly (consider that I don't have a lot of experience with Docker - I've played with docker-compose before, but there are many subtleties I'm still missing): So the underlying thing we're working with here is that deployment platforms use lock files as a cache key for the third-party dependencies. One could copy the entire lock file to pin versions but then the caching mechanism breaks. For example, if you're deploying a workspace as a Google Cloud Function you would want the lock file to be there so that installation of dependencies was pinned as the lock file specifies. It's not just computing a "cache key" for caching, but also having a lock file to pin versions. I've seen your comment about cache layers, but I wonder if what you're looking for isn't just a way to compute a "cache key" for a given workspace? If there was a lock file at the package level then this would not be an issue. Here's the problem: because there is a single lock file at the top-level, one can't just take a package (i.e., workspace) and deploy it as one would when not using Yarn workspaces. In addition to this some tools, like Docker, can leverage the fact that versions are immutable to implement caching and reduce build and deployment times. Most deployment solutions out there will look for manifest and lock files to set up required dependencies. In various monorepos, it is desirable to treat a workspace as an independent deployable entity. I'm assuming that because all of these dependencies are managed by a single yarn install the Yarn team opted to have a single lock file at the top-level where the workspace root is defined. With PnP, I'm assuming the Node.js resolution algorithm is patched in a similar way to make it work with multiple versions of dependencies. If a single dependency can't be found that matches all requirements, that's OK, the dependency is kept in a package's node_modules folder instead of the top level and the Node.js resolution algorithm takes care of the rest. This works by picking a dependency version that fits the most dependency requirements as specified by package manifest files. Yarn workspaces has a lot of benefits for monorepos, one of them being the ability to hoist third-party dependencies to reduce installation times and disk space consumed. I'll gladly do that □ Current state of affairs
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |