rahrang
rahrang
RRailway
Created by rahrang on 2/23/2024 in #✋|help
How to install only what's necessary when auto-deploying?
This isn't an issue with Railway. This is a question on how to optimize the install/build/deploy process for the applications I host on Railway. I have a "shared" monorepo in which I have a frontend and backend application (as well as others, but my issue can be conveyed with just these two apps). The monorepo uses pnpm as a package manager and turbo (https://turbo.build/repo) for building/caching. My Github repository is connected to my Railway project, so I get those sweet auto-deploys when pushing to the main branch. When I push to the main branch, the Railway service connected to the frontend application runs pnpm install, which installs all the dependencies in the repository -- all of those of frontend, backend, and all internal packages. The same happens with the service connected to the backend application. It's inefficient because the frontend service installs backend-only dependencies (prisma, @nestjs, etc.) and the backend service installs frontend-only dependencies (react, @remix-run, etc.). The question I have: is there a way to prevent the service from installing dependencies that aren't required for the given application? I'm investigating turbo prune (https://turbo.build/repo/docs/reference/command-line-reference/prune). When I run turbo prune frontend locally, it isolates the frontend application and all its dependencies into an out directory. I can then cd out and run pnpm install to install only the dependencies for the frontend app (e.g. react and @remix-run but not prisma and @nestjs). And finally I can run the build and start scripts to get the frontend running without a problem. My issue comes when trying to use turbo prune when deploying via Railway. When I push to main, Railway immediately runs pnpm install and so I can't do turbo prune frontend && cd out before that pnpm install happens. (Reaching character limit, see more in thread)
11 replies