22

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
4
  • 1
    Just ran into this as well. My current solution will be to use a private registry. Commented Jul 16, 2019 at 0:06
  • @DavidW.Keith what does that mean though? "use a private registry" ?
    – mesqueeb
    Commented Jan 28, 2021 at 5:06
  • The docs for doing this on NPMJS are here: docs.npmjs.com/creating-and-publishing-private-packages You can also host your own, but it would need to be on a server that is publicly accessible (but secured) Commented Jan 29, 2021 at 19:50
  • 1
    Yea I didn't really solve it and ended up moving to GKE
    – Algirdyz
    Commented Jan 30, 2021 at 21:19

2 Answers 2

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.

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)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.