keymetrics / pm2-plus-tech-questions

http://docs.keymetrics.io/docs/pages/faq-troubleshooting/
27 stars 3 forks source link

Offline deployment and bundling of modules #216

Closed jadell closed 5 years ago

jadell commented 5 years ago

I need to create an offline deployment for a system that won't have access to npm. I can easily include node_modules (including pm2) when building and packaging, but how do I include pm2 modules such as pm2-logrotate?

I can't call pm2 install on the host, since it will not have access to an outside internet connection.

Is there a way to tell pm2 install to look for package on the local filesystem? Then I could pull pm2-logrotate down when building my bundle, and have the deploy process use that instead of npm.

Or is there a way to include pm2-logrotate as a normal module in package.json, and tell pm2 to use it?

vmarchaud commented 5 years ago

Yes, you can give pm2 install a path to a tgz archive and it will install it as a module

jadell commented 5 years ago

Can you give an example of how to do this? I've tried a couple different methods.

Currently, I have included "pm2" and "pm2-logrotate" in package.json, to be install locally with the app (can't do a global install.)

Attempt 1: pm2-logrotate as a directory in node_modules

During build, I ran npm install in the build directory, then I tar the entire build directory, including node_modules.

On the server where the app is hosted, I untar the directory, then ran ./node_modules/.bin/pm2 install ./node_modules/pm2-logrotate

This produces to following error:

[PM2][Module] Installing NPM ./node_modules/pm2-logrotate module
[PM2][Module] Calling [NPM] to install ./node_modules/pm2-logrotate ...
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/pm2-logrotate" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-01-09T15_18_30_332Z-debug.log
[PM2][ERROR] Installation failed via NPM, module has been restored to prev version

Attempt 2: pm2-logrotate archived using npm pack

Then I tried the following during build. After running npm install in the build directory, run npm pack pm2-logrotate. On the host server, I ran ./node_modules/.bin/pm2 install ./pm2-logrotate-2.6.0.tgz and got the following error:

[PM2][Module] Installing NPM ./pm2-logrotate-2.6.0.tgz module
[PM2][Module] Calling [NPM] to install ./pm2-logrotate-2.6.0.tgz ...
npm ERR! path /home/user/pm2-logrotate-2.6.0.tgz
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall stat
npm ERR! enoent ENOENT: no such file or directory, stat '/home/user/pm2-logrotate-2.6.0.tgz'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-01-09T15_27_39_470Z-debug.log
[PM2][ERROR] Installation failed via NPM, module has been restored to prev version

And then tried ./node_modules/.bin/pm2 install --tarball ./pm2-logrotate-2.6.0.tgz with the following error:

[PM2][Module] Installing TAR module
[PM2][Module] Installing package ./pm2-logrotate-2.6.0.tgz
tar: module/package.json: Not found in archive
tar: Exiting with failure status due to previous errors
[PM2][ERROR] ENOENT: no such file or directory, open '/tmp/module/package.json'

I know I'm doing something wrong, but I'm not familiar enough with deploying node apps this way to know what.

vmarchaud commented 5 years ago

I believe there are a quick example over in this blogpost : https://blog.pm2.io/2018-10-03/PM2-Runtime-3-2-Autumn-Features/ under the Tarball Packaging section