pm2-auto-pull
pm2-auto-pull copied to clipboard
Working Example of pm2-auto-pull
I've been working through the various documentations for PM2 and this trying to get a better picture of exactly how you're supposed to use this.
What I want to have happen:
- I have a machine running on Machine A, with an app deployed that is running via PM2.
- Changes get returned for said app on a remote git repo.
- These changes are detected on Machine A by pm2-auto-pull, and put in place for the local app.
- pm2/pm2-auto-pull restarts the application.
I'm pretty sure that is what this does, but for the life of me I can't find an example on how I supply the git credentials, repo, etc. It looks like this might in fact rely on the "deploy" feature of pm2, but I'm again, still not absolutely positive.
Does anyone have a clear-cut simple example here, or can you at least confirm how this is used?
e.g. Am I correct in abstracting that this utilizes the settings in the "deploy" section of the environment.json to pull changes from git on a regular interval?
Can someone supply a simple environment.json that handles a private repo with creds, or at least confirm / contest with what I've said and point me in the right direction?
Nope, this module rely on the PM2 API which itself rely on vizion which itself rely on spawning a child process executing git (here and finally here).
You must be able to do a git pull without issuing any creds to use this module and generally any pm2 command (pm2-deploy will rely on spawning the ssh binary but it isn't optimised, like you will need to put multiple time your passphrase for example).
To be more precise, every command will just be thrown with the cwd of the application (so you will need your app folder to have a .git configured in it to actually authenticate etc)
What you can do however (and what i'm doing right now for personnal projects ) is to rely on github webhook to correctly pull and execute command on your server when needed, if you interested in that solution, there is pm2-githook that i just wrote last week.
Thank-you @vmarchaud that really helps. I'm going to play around with setting:
proc.pm2_env.versioning.repo_path
(per the code sample calling vizion.update). And the following git technique
To see if I can get it pulling without the creds being entered every time. If that doesn't work, I'll go the pm2-githook route. I'd rather not have an extra listener unless its needed, and I've already configured a read-only user for git.