pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 clones codebase with default(development branch) as origin and cannot checkout to other branches

Open sudheeshcm opened this issue 9 years ago • 8 comments

Hi,

I've been trying to deploy code from git to various machines including my localhost machine using PM2. The code cloned will always be set with default(development branch) in the .git/config file for the fetch attribute. In this case, we'll not be able to checkout to other branches as git branch -a will only be listing development branch.

I've tried changing the ref in the pm2 configurations to origin/* but didn't help. Please find the configurations thatI've tested with below.

{
  "apps" : [{
    "name": "fr-catalog-admin-v2-server",
    "script": "./server.js",
    "env_development": {
      "NODE_ENV": "development"
    },
    "env_production": {
      "NODE_ENV": "production"
    },
    "env_staging": {
      "NODE_ENV": "staging"
    },
    "cwd": "/srv/catalog/fr-catalog-admin-v2/current/server",
    "log_date_format": "YYYY-MM-DD HH:mm:ss.SSS Z",
    "watch": false
  },
  {
    "name": "fr-catalog-admin-v2-client",
    "script": "./client.js",
    "env_development": {
      "NODE_ENV": "development"
    },
    "env_production": {
      "NODE_ENV": "production"
    },
    "env_staging": {
      "NODE_ENV": "staging"
    },
    "cwd": "/srv/catalog/fr-catalog-admin-v2/current/client",
    "log_date_format": "YYYY-MM-DD HH:mm:ss.SSS Z",
    "watch": false
  }],
  "deploy": {
    "development": {
      "env": {
        "NODE_ENV": "development",
      },
      "ref": "origin/cat147-nodeDeploymentUpdate",
      "host": "localhost",
      "repo": "****",
      "path": "/srv/catalog/fr-catalog-admin-v2",
      "pre-deploy": "git fetch --all && git checkout cat147-nodeDeploymentUpdate",
      "post-deploy": "cd client && npm install && gulp moveStaticFiles && cd ../server && npm install && pm2 startOrRestart ./config/pm2/pm2.json --env development",
      "user": "qbuser"
    },
    ...
  }
}

Expected behavior

Code cloned should have the .git/config file fetch attribute with a * as shown below.

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = *******
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "development"]
	remote = origin
	merge = refs/heads/development

With the above configuration for git, we could fetch all branches from git and checkout into any one of them.

Actual behaviour

PM2 deploys code with incorrect .git/config fetch attributes.

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = ****
	fetch = +refs/heads/development:refs/remotes/origin/development
[branch "development"]
	remote = origin
	merge = refs/heads/development

In this case, we won't be able to find other branches even after git remote update or even after a git fetch --all.

Steps to reproduce

  • Step 1
    pm2 deploy pm2.json development setup
    
  • Step 2
    pm2 deploy pm2.json development
    

Software versions used

OS         : MacOS Sierra 10.12.2
node.js    : 6.9.2
PM2        : 2.3.0

sudheeshcm avatar Jan 26 '17 09:01 sudheeshcm

Known problem, like i said in the other issue, try with deployerjs to see if its working.

vmarchaud avatar Jan 26 '17 10:01 vmarchaud

@vmarchaud @Unitech this will fix this issue that i'm experimenting too. please merge this PR and release a patch for 2.3.x

https://github.com/Unitech/pm2-deploy/pull/120

phra avatar Jan 30 '17 22:01 phra

@vmarchaud when do you plan to release the fix?

phra avatar Jan 31 '17 08:01 phra

next iteration should be around this week or next week.

vmarchaud avatar Jan 31 '17 09:01 vmarchaud

@vmarchaud looking at the package.json of pm2 it uses the ^ in front of the pm2-deploy version so i think that it will be enough publish the new pm2-deploy on npm. https://github.com/Unitech/pm2/blob/master/package.json#L169

you have already bumped the version of pm2-deploy so it only needs to be published on npm. can you do this asap in order to fix the 2.3.x version? the latest version published on npm is the 0.3.4 and on github the fixed version is 0.3.5 so a simple npm publish will be enough. https://github.com/Unitech/pm2-deploy/blob/master/package.json#L3

thanks.

phra avatar Jan 31 '17 10:01 phra

We will take the time to test it so it may be published after our internal meeting today

vmarchaud avatar Jan 31 '17 10:01 vmarchaud

@vmarchaud ok thank you. just note that reverting to 2.2x of pm2 does not fix the problem because it's still fetching the last pm2-deploy published to npm because of semver declaration.

phra avatar Jan 31 '17 11:01 phra

Published

vmarchaud avatar Feb 01 '17 15:02 vmarchaud