pm2 deploy does not update or pull latest git commits

Created on 8 Jun 2017  ·  32Comments  ·  Source: Unitech/pm2

What's going wrong?

So this is really cool to have
pm2 deploy ecosystem.json dev setup
&
pm2 deploy ecosystem.json dev update

But however pm2 does not pull latest commits from github whenever i update it stuck with the original repository. I assume the git commands it executes are wrong?

How could we reproduce this issue?

I see it performs the following:
git fetch --depth=5 --all --tags
git reset --hard origin/master

And it outputs the same results when executing them manually. The head is still old, and prevents me updating & deploying the application.

Supporting information

PM2 version: 2.4.6
Node version: v.6.11.0
git version 1.8.3.1
Linux + Windows
Need More Data

Most helpful comment

Probably, it's caused by git. If you execute git fetch with depth option by using Git v1.8, fetch doesn't work in the worktree.

Use git v1.9 or later.

All 32 comments

My current workaround is to add:
"pre-deploy": "git pull",
But that sucks sicne i can not revert then..
Not sure is there any way to avoid this?

It must come from your server setup, is there any error when doing these commands manually ?

I am not sure what errors i should get:

$ git fetch --depth=5 --all --tags
Fetching origin
$ git reset --hard origin/master
HEAD is now at 155d5b9 Added hacky workaround for deploy git pull issue 

(Which is a commit from yesterday, and i have 30 new commits pushed to github since then)

It should be updated to the latest when executing:
pm2 deploy ecosystem.json update

Executing "git fetch" without "--depth=5 -all --tags" just working fine.

No idea, what might go wrong since i am not a git expert

I know a weird behavior of pm2-deploy is that it set the remote branch to master but it isnt actually master, could you try to remove the whole remote directory and re-do it from the start ?

I have tried 2 times setting up a github repository from scratch & a fresh pm2 ecosystem with a blank project before posting.

I'm having the same problem.

Same to me. I tried both version 2.4.0 & 2.5.0

Probably, it's caused by git. If you execute git fetch with depth option by using Git v1.8, fetch doesn't work in the worktree.

Use git v1.9 or later.

How about adjusting the code so that it works with 1.8 too?
I am not sure why git fetch --depth better or whats the actual use case here? Git pull or git fetch seems to do the same job. To be honest "pm2 deploy" should just work without any hassle and hacking around "just to make it work". I only have bad experiences using pm2 deploy, and i just got tired of it.

Windows is not supported.. need to use cygwin?
And now pm2 deploy just fails due to my git version?

I rather write my own deploy scripts in the future, probably saves more time.

I am having the same issue. I have updated git on ubuntu(trusty).
git version 2.13.0
pm2 version 2.6.1
node 7.8.0

Do I need to start from setup again?

You have to upgrade your git version which is kind of a pain or you can just execute a post build script

on CentOS you can use IUS repos to get the latest version of git, after installing the repo use

yum install git2u

then to fix the issue with pm2 try destroying your current deployment by deleting the folder where you deploy your code then setup the Deployment again

pm2 deploy ecosystem.json env setup
pm2 deploy env

make sure that the folder was completely deleted to have a clean new deployment.

Hope this works with you.

Wrote my own deploy scripts that work super good with pm2 and any git
version. thanks anyways.

On 5 Sep 2017 22:42, "Ben Ishak" notifications@github.com wrote:

on CentOS you can use IUS repos to get the latest version of git, after
installing the repo use

yum install git2u

then to fix the issue with pm2 try destroying your current deployment by
deleting the folder where you deploy your code then setup the Deployment
again

pm2 deploy ecosystem.json env setup
pm2 deploy env

make sure that the folder was completely deleted to have a clean new
deployment.

Hope this works with you.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Unitech/pm2/issues/2935#issuecomment-327216225, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFlNcxjUEKaQYN6mwVcXpQVYKp2P0A01ks5sfWvIgaJpZM4N0d67
.

@nukosuke Yes , it's caused by git. When use git-1.8.x ,it can't fetch the latest git commits, after update git it's works ok

I find it funny that it is easier for the authors to blame the problem on git or anything else rather than change one single line of code to make it work... excelent pm2 deploy couldn't be any more wonderfull.

Anyways, if anyone having this issue just use node-ssh and that would be it, saves the headache.
https://github.com/steelbrain/node-ssh

TLDR:
pm2 deploy is garbage, used custom deploy tool issue solved.

@azarus it was clearly a git issue!
pm2 is amazing not just for deployment but also for monitoring and keeping your node up and running and to manage multiple node processes

from another hand
I suggest using AWS CodeDeploy for deployment and pm2 for managing node processes.

AWS CodeDeploy can run on any machine, doesn't have to be on AWS, but you need to have AWS account to set it up

I tried upgrading git and have the same issue. Ended up adding 'git pull'
to the post-deploy script. :(

On Tue, Sep 12, 2017 at 9:26 AM, Ben Ishak notifications@github.com wrote:

@azarus https://github.com/azarus it was clearly a git issue!
pm2 is amazing not just for deployment but also for monitoring and keeping
your node up and running and to manage multiple node processes

from another hand
I suggest using AWS CodeDeploy for deployment and pm2 for managing node
processes.

AWS CodeDeploy can run on any machine, doesn't have to be on AWS, but you
need to have AWS account to set it up


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Unitech/pm2/issues/2935#issuecomment-328906992, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEJ8C-vDIYnEyy-vJuastxyDGICB6ngXks5shrC3gaJpZM4N0d67
.

you should update git on remote and local machine
then you should start a clean deployment

  • delete the folder where you deploy your code
  • run these on your remote machine
pm2 stop all
pm2 delete all
pm2 kill
rm -rf ~/.pm2/*
pm2 save
  • run these on your local machine
pm2 deploy ecosystem.json production setup
pm2 deploy ecosystem.json production

@benishak indeed pm2 is amazing! BUT pm2 deploy is garbage.

this issues just produced by git. In git-1.8.3.x , when we use git fetch --tags , the default refspecs
are overridden and not used. It make us can not get the right commit ... you can update git on your remote . Also pm2 was not take very good when do 'pm2 deploy' . If pm2 check git version first and execute 'git fetch --all --depth=5' with git version < 1.8.3.x , all is ok . I'm sorry for my bad english~

em... for this issues , i try to read the 'git fetch' code and 'pm2-deploy' code ,and change it for test , then get this conclusion...

@Program-Monkey Surprisingly my own deploy tool i wrote for myself works fine with any git version.
The issue was closed since the developers don't care about deployment. So unless you got a PR that is accepted its pointless to talk about anything here.

Or probably all of my 25 server setups with basic centos 7 setup are wrong?

em... I did not mean you were wrong , just want to express that had a problem with git fetch in previous git version. And your deploy tool is very good ~ I see that in git -1.8.3.1 : --tags make acts as an explicit refspec, the default refspecs (configured with the remote.$name.fetch variable) are overridden and not used. After 1.9.0,fixed it , it take 'tags === TAGS_SET' out of ' if(refspec_count) ' . We only have technical exchanges ~ @azarus

Ok, yes i know that is an issue in git. And sadly this is the default version that comes with many OS rpms, including the latest centos 7. And the main reason why pm2 should fix this on its side is because nobody feels like to build a git just to fix this, or hunt for a new rpm that has the proper git version. The goal for pm2 deploy is to make deployment easy and quick NO?. Now deployment also includes the setup of the environment in most cases. Which pm2 deploy makes difficult due to the issue with git. So really changing one line just to make it work with a buggy git version really seems like nothing compared to how long it takes to set up a new server and fix the git version everytime before deploying to a new machine.

pm2 deploy also could use a couple of features such as transfering files from the local computer to the remote, so that was we could use configuration files. Environment variables are such a mess sometimes.

yes~ learned a lot ~

@azarus , I cannot understand you say "But that sucks sicne i can not revert then.."

can you give a scenes or demo?

my git version is 2.8.1,also have this question...

Please stop quoting me here! I created my own deployment tool that has more features and works well with pm2. So i am no longer intersted in fixing the issue. I reported it, now its up to the pm2 team to change the git pull command.

But to answer your question, if you use a pre-deploy command such as:

"pre-deploy": "git pull",

you end up executing this command all the time. Even if you wish to deploy a specific re-version, or revert to a previous version. Since after pulling the required version you end up pulling the latest one as well.

@henryzp 你确定你部署服务器上的是2.8.1 ? 因为pm2-depoy 工具的fetch代码执行的是加--tags的,在git源码中1.9.0之前的版本加上这个参数会导致映射关系丢失...

@Program-Monkey ,thx。。。

我上面的git版本是我的mac上的git版本,搞错了。。orz

On CentOS you should'nt install the repository version but you must install the last one from the git repo.

@nukosuke thx, solve the problem!

updating git didn't help me.

pm2 reload APP_NAME solved my issue

Was this page helpful?
0 / 5 - 0 ratings