Question

How to deploy subdirectory in monorepo without lockfile?

Posted June 19, 2021 121 views
Node.js

Hey! I have a yarn workspaces monorepo with packages/frontend and packages/backend directories and I just want to deploy packages/backend. I already defined the source_dir so it points to it but then DO can’t find a yarn.lock because it only exists at the root and not in packages/backend.

How can I configure it so it can find the yarn.lock at the root but only deploys the packages/backend directory?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @rudolphmarvin,

If you want to deploy the code present in packages/backend folder, specifying the sourcedir with the folder name(packages/backend) is the right way. When you specify the sourcedir that becomes the current working directory for your applications and only the files present in that folder are considered.

Since yarn.lock is not present in the packages/backend and app does not have access to the trailing folders(root folder of your repo), it is not found. In order for it to be detected, please ensure that the package.json, yarn.lock and other necessary files are present in the current folder(packages/backend) in this case.

In case you have any doubts, please reach out to our support team and we’d be glad to help.

Cheers,
Taha Fatima

  • Thanks for your answer! I generate a lockfile for each package now and the build step works fine. But the deployment doesn’t because I use yarn workspaces and it hoists the dependencies which DO can’t find in the node_modules.

    I can exclude all the dependencies from hoisting but that’s not the point of having a monorepo. Is there an easy way to use a monorepo with DO? Sadly it doesn’t look like it works out-of-the-box without having problems with the lockfile or hoisted dependencies. The example monorepo doesn’t help either in that case. :/

    • Hi @rudolphmarvin,

      Thanks for bringing this up. For your use case, I would suggest a different approach. Please do not specify the source_dir instead you might consider adjusting your build and run commands. We do have a git repo explaining a similar approach.

      Could you refer the steps in the readme under Deploying to App Platform

      Hope this helps!

      Cheers,
      Taha Fatima