![]() ![]() Read more about the turbo repo caching here. If interested, you can read more about how the docker build cache works here. ![]() With Turborepo, we can read from the remote Turborepo cache and only build what needs to be built. This is of course not useful since it’s highly likely that when making a code change in our monorepo, we will have changed code in one of our packages (the only exception being if the code change only affects end-to-end tests or CI config files). Docker Layer Caching caches the results of running instructions in your Dockerfile, but when it reached the RUN yarn build instruction (prior to turborepo), it would only read from the docker cache if ALL the files in ANY of the packages/apps haven’t been modified. The token and team arguments are ultimately read from environment variables configured on our CI that specify where the Turborepo remote cache is found.īefore Turborepo, the best we could do with caching our docker builds was to enable Docker Layer Caching on CircleCI (our CI provider). RUN yarn build - token = $ TURBO_TOKEN - team = $ TURBO_TEAM Here’s the line/instruction in our Dockerfile that runs the Turborepo build task: The great thing about this is that the remote caching also works within docker, which is important for us since when we are building our packages on our CI, we do so within docker. To get remote caching setup, see Turborepo’s documentation page. Now, if we make a pull request that only affects code in the client app, then Turborepo will only build the client app and get the builds for all the other packages from a remote cache. This is most noticeable for us when running turbo run build since building our packages is what takes the longest amount of time in our CI. Now if turbo run lint is ran again, turborepo will notice that no files have changed, so it will “replay” the output and not run the lint command for each package again (turbo repo calls this “full turbo” when everything is cached). It took 29.62s to run the lint task on our monorepo. Notice how turbo repo says “cache miss”, indicating that it doesn’t have anything to read from the cache. Here’s an example of a portion of the output shown as a result of running turbo run lint for the first time. This means that if turbo run lint is ran twice in a row without making any changes to the files in the yarn workspace packages, then Turborepo will simply use the same lint result found from the cache. Also, as long as "cache": false isn’t specified in the turbo.json config for the task, then Turborepo will cache the result of running the task for each package. The way tasks work is that when a task is run, such as turbo run lint, Turborepo will go through all the lint commands specified in the scripts of each package’s package.json file. Used when debugging things and needing to start from a clean slate. clean: Deletes all the node_modules directories as well as any build outputs (i.e.typecheck: Looks for type errors using tsc.For the client app, builds the optimized/minified HTML and JavaScript files used for a web app. build: Transpiles TypeScript code into JavaScript code for all our apps and packages.Here’s an explanation of each of our tasks: Here’s a look at the package.json in the root of the monorepo where we specify the Yarn workspace config: Yarn workspaces is how we manage to share code between our apps and packages. package.json: The root package.json contains information about how all the code is related and it contains scripts used to run Turborepo tasks.The only shared code it uses is our shared eslint config ( eslint-config-basedash) This is especially useful for Prisma enums. The reason we have our Prisma code in a prisma package instead of keeping it within the server app directory is because we use the generated Prisma types on both the client, server, and other shared packages. The code is shared between apps and can also be shared between other packages. packages: Shared code is found within this directory.apps: The code for our client react app and our node.js server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |