Unitech / pm2-deploy

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

Allowing bash-unfriendly chars in post-deploy script #141

Open austindebruyn opened 7 years ago

austindebruyn commented 7 years ago

It's impossible to have a post-deploy script like secret='2$(8k3n!a' /bin/sh ./post-deploy.sh You will get a sh: 1: Syntax error: end of file unexpected (expecting ")") error from the child process node tries to spawn. example

It looks like a couple people have run into similar issues and can manage with lots and lots of escaping, but this seems to do it for me. also solves issue https://github.com/Unitech/pm2-deploy/issues/122 .

Escaping hostJSON and wrapping it in double quotes instead:

  hostJSON = hostJSON
    .replace(/\(/g, '\\(')
    .replace(/!/g, '\\!')
    .replace(/"/g, '\\"')
  var shellSyntaxCommand = "echo \"" + hostJSON + "\" | \"" + __dirname.replace(/\\/g, '/') + "/deploy\" " + args.join(' ');

and I can now deploy with ! and ( and the rest of the json is preserved.

Is this change in the spirit of the project?

fritx commented 6 years ago

+1. I cant add strings like npm config set registry "http://xxxxx" into 'post-deploy' command, it would become npm config set registry "" and cause errors.


None of the following works:

  1. 'post-deploy': '... && npm config set registry="http://xxxx" && ...'
  2. 'post-deploy': '... && npm config set registry "http://xxxx" && ...'
  3. 'post-deploy': '... && npm config set registry \'http://xxxx\' && ...'
  4. 'post-deploy': '... && npm config set registry \\"http://xxxx\\" && ...'
phra commented 6 years ago

i will try to investigate it.

leopucci commented 2 years ago

I just got this problem today on a ecosystem.config.js

bonniss commented 2 years ago

anything new guys?

alexislefebvre commented 11 months ago

I used a workaround: I put the commands with the quotes in a script named restart-prod.sh:

#!/usr/bin/env bash

docker-compose --file docker-compose.yml --file docker-compose-prod.yml exec -T front su-exec foo \
sh -c "YARN_CACHE_FOLDER=/srv/.cache/yarn yarn install && yarn next build && killall node"

I versioned it so that it would be deployed, then configured pm2 to call it when deploying:

module.exports = {
  deploy: {
    prod: {
      '[…]': '[…]',
      'post-deploy': './restart-prod.sh',
    },
  },
}

Then pm2 doesn't complain about the quotes and it just works.