Expect PM2 to deploy the latest version of the code in my master branch
It always deploys the code that was already on the machine. If I ran setup before running deploy it redeploys the code that was pulled when setup was run. If I do a manual pull by ssh-ing into the machine, that is the version that gets deployed. It never pulls and deploys the latest version.
pm2 deploy
pm2 deploy
then commit and push some changes to the branch and run
pm2 deploy
it always checks out older commit during deployment
OS : CentOS 7 - 3.10.0-327.4.4.el7.x86_64
node.js : v6.9.4
PM2 : 2.2.3
I'm running the deploy command with Gitlab-CI but I get the same results if I run it on my local machine.
Build server output, there are some errors there that i don't get when deploying on my local machine. However I still get the same result on my machine.
Running with gitlab-ci-multi-runner 1.9.2 (ade6572)
Using Shell executor...
Running on build-server.local...
Fetching changes...
Removing node_modules/
HEAD is now at daf9395 The latest version of the code
Checking out daf93957 as master...
Downloading artifacts for install (683)...
Downloading artifacts from coordinator... ok id=683 responseStatus=200 OK token=anvaGQ_9
$ npm run deploy-staging
> [email protected] deploy-staging /home/gitlab-runner/builds/7011119b/0/Project
Project
> pm2 deploy staging
--> Deploying to staging environment
--> on host staging-server.local
error: HEAD does not point to a branch # Doesn't happen on my local machine, still get the same results.
error: HEAD does not point to a branch
error: HEAD does not point to a branch
fatal: ambiguous argument '@{upstream}..': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
â—‹ deploying origin/master
â—‹ executing pre-deploy-local
â—‹ hook pre-deploy
â—‹ fetching updates
Fetching origin
â—‹ resetting HEAD to origin/master
HEAD is now at 945edf8 The previous version of the code
â—‹ executing post-deploy `npm install --production && pm2 startOrRestart ecosystem.json --env staging`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/project/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
tee: /tmp/pm2-deploy.log: Permission denied
[PM2] Applying action restartProcessId on app [project](ids: 0)
[PM2] [project(0) ✓
<-- removed unimportant output -->
Use `pm2 show <id|name>` to get more details about an app
â—‹ hook test
â—‹ successfully deployed origin/master
--> Success
Build succeeded
My ecosystem.json file
{
"apps": [{
"name": "project",
"script": "index.js",
"env": {},
"env_production": {
"NODE_ENV": "production"
},
"env_staging": {
"NODE_ENV": "staging"
}
}],
"deploy": {
"production": {
"user": "node",
"host": "production-server.local",
"ref": "origin/production",
"repo": "[email protected]:project.git",
"path": "/usr/local/share/nodejs-applications/project",
"post-deploy": "npm install --production && pm2 startOrRestart ecosystem.json --env production"
},
"staging": {
"user": "node",
"host": "staging-server.local",
"ref": "origin/master",
"repo": "[email protected]:project.git",
"path": "/usr/local/share/nodejs-applications/project",
"post-deploy": "npm install --production && pm2 startOrRestart ecosystem.json --env staging"
}
}
}
fatal: ambiguous argument '@{upstream}..': unknown revision or path not in the working tree.
Please try to upgrade your git version, people had some problem on centos before cause it ship older version of git.
Thanks @vmarchaud, updating git solved the problem.
For people with the same issue and using RHEL / CentOS, I used the IUS repository to replace my git installation with latest version.
See instructions here on how to install IUS repository on RHEL. Make sure you also set up the yum-replace plugin.
When this is done, use this command to replace the installed git with the git2u package from IUS:
sudo yum replace git --replace-with git2u
Most helpful comment
Thanks @vmarchaud, updating git solved the problem.
For people with the same issue and using RHEL / CentOS, I used the IUS repository to replace my git installation with latest version.
See instructions here on how to install IUS repository on RHEL. Make sure you also set up the yum-replace plugin.
When this is done, use this command to replace the installed git with the git2u package from IUS: