Unitech / pm2-deploy

Deploy part of PM2
http://pm2.keymetrics.io/docs/usage/deployment/
MIT License
178 stars 71 forks source link

ENV vars doesn't get updated with `--update-env` on post-deploy #153

Open lardissone opened 6 years ago

lardissone commented 6 years ago

Referring to #152 fix, now ENV vars are sent to post-deploy command but vars are not exported apparently.

lardissone commented 6 years ago

@phra I think I've found the issue: childProcess.spawn command is not used correctly when ENV vars are sent.

In the docs they say the envs should be passed in the options object (third parameter). We should do something like in the spawn function:

function spawn(hostJSON, args, envVars, cb) {
    var shellSyntaxCommand = "echo '" + hostJSON + "' | \"" + __dirname.replace(/\\/g, '/') + "/deploy\" " + args.join(' ');
    var options = { stdio: 'inherit' };
    if (envVars && typeof envVars === 'object') {
        options.env = envVars;
    }
    var proc = childProcess.spawn('sh', ['-c', shellSyntaxCommand], options)
    ...

I wouldn't be able to work on this today, but this probably helps.

vmarchaud commented 6 years ago

@lardissone We need the env to be given in the remote server, if you give it to the spawn call it will only be used to spawn the ssh binary

lardissone commented 6 years ago

@vmarchaud ah, got it!

TheoB-dev commented 3 years ago

Hi there, Is the bug still present ? I'm facing this issue in post-deploy : the pm2 shell doesn't seems to have my ENV vars (database url for exemple). Thank you and sorry for bad english

yoursweetginger commented 2 months ago

Same problem