pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

pm2 deploy doesn't support localhost and number type port

Open anselmo-coolstay opened this issue 3 years ago • 1 comments

What's going wrong?

I should deploy my app thru ssh tunneling, so that it should be deployed to localhost. However, localhost causes deploy failure. 127.0.0.1 works well instead of localhost.

And pm2 document does not mention port for deploy target config. port property of deploy config works, but it should be a string, not a number.

How could we reproduce this issue?

  deploy: {
    staging: {
      user: 'deployer',
      host: 'localhost',
      port: 3030,
      ref: 'origin/staging',
      repo: '[email protected]:xxxxxx/yyyyyy',
      path: '/home/deployer/yyyyyy',
      'pre-deploy-local': '',
      'post-deploy': '. ~/.profile && yarn install && pm2 reload scripts/pm2/ecosystem.config.js --env staging',
      'pre-setup': '',
    },
  }

Supporting information

$ pm2 report

--- Daemon -------------------------------------------------
pm2d version         : 5.2.0
node version         : 16.14.0
node path            : /Users/xxxxx/.nvm/versions/node/v16.14.0/bin/pm2
argv                 : /Users/xxxxx/.nvm/versions/node/v16.14.0/bin/node,/Users/xxxxx/.nvm/versions/node/v16.14.0/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : xxxxx
uid                  : 501
gid                  : 20
uptime               : 8min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.0
node version         : 16.14.0
node path            : /Users/xxxxx/.nvm/versions/node/v16.14.0/bin/pm2
argv                 : /Users/xxxxx/.nvm/versions/node/v16.14.0/bin/node,/Users/xxxxx/.nvm/versions/node/v16.14.0/bin/pm2,report
argv0                : node
user                 : xxxxx
uid                  : 501
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : arm64
platform             : darwin
type                 : Darwin
cpus                 : Apple M1 Pro
cpus nb              : 10
freemem              : 74645504
totalmem             : 17179869184
home                 : /Users/xxxxx
===============================================================================

anselmo-coolstay avatar Jun 03 '22 13:06 anselmo-coolstay

The port is typically specified as an environment variable. Try the following ecosystem.config.js

module.exports = {
  apps: [{
    name: "app",
    script: "./app.js",
    env_staging: {
      NODE_ENV: "staging",
      PORT: 3030,
    },

  }],
  deploy: {
    staging: {
      user: 'deployer',
      host: 'localhost',
      ref: 'origin/staging',
      repo: '[email protected]:xxxxxx/yyyyyy',
      path: '/home/deployer/yyyyyy',
      'pre-deploy-local': '',
      'post-deploy': '. ~/.profile && yarn install && pm2 reload scripts/pm2/ecosystem.config.js --env staging',
      'pre-setup': '',
    },
  }
}

dimitriaatos avatar May 29 '24 18:05 dimitriaatos