How to deploy one app from a large monorepo with dependencies to packages in the same repo to google app engine?

邮差的信 提交于 2021-02-18 04:56:29

问题


I have a large node.js monorepo with several applications and packages and inter dependencies. It is all managed with yarn workspaces and a little bit of lerna. Everything works great for me, however I am having trouble trying to deploy one of the applications in this monorepo to google app engine.

The main issue is that the app engine wants to install packages that are located only locally and are not on npm, and it throws an error.

I've scoured the google cloud documentations but did not manage to find anything that I could use to specify custom node packages or anything similar.

Is there a way to make such a deployment without publishing the local packages to npm?

The basic structure of the app I want to deploy looks like this:

-root
    -packages
        -packageA
            -package.json
    -apps
        -deployable-app
            -package.json <-contains dependency: "packageA": "0.0.1"
            -app.yaml

回答1:


I have the same problem with Firebase Cloud Functions, so I decided to publish my packages into a private registry and configure the Cloud Function environment with a .npmrc to use my private registry. I suppose that you can do the same with App Engine.

For private registry, I already tried two: GitHub Package Registry(now in Beta) and Verdaccio(which is a self-hosted option)




回答2:


Create a minimal docker image by coping to the image only the deployable-app and the packages from the same monorepo that the deployable-app depends on (in your case it's packageA).

When installing, yarn will do all the work to link between them.

Notes:

  • Deterministic installation - It is recommended to do so in monorepos to force deterministic install because nodejs packag emanagers (pnpm, yarn, npm) does not read the lock files of the dependencies of your app so when you run install, and packageA is located in public/private npm-registry, the package manager will install packageA dependencies as he wants. But you have a yarn.lock file in your monorepo that described what exectly should be installed and in which version.

  • Small docker image, better caching - Copy only the local packages from your monorepo that your deployable-app needs and create a script that removed all devDependencies from all the package.jsons in the monorepo (inside the dockerfile). they are not needed in production. make your image small.



来源:https://stackoverflow.com/questions/56564517/how-to-deploy-one-app-from-a-large-monorepo-with-dependencies-to-packages-in-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!