Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 328
Algirdyz Avatar asked Jun 12 '19 14:06

Algirdyz


1 Answers

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.

like image 73
Stav Alfi Avatar answered Sep 17 '22 13:09

Stav Alfi