dasuchin / grunt-ssh-deploy

Grunt SSH Deployment
MIT License
66 stars 45 forks source link

deployment not possible to *nix from a Windows machine #37

Closed tiimbz closed 9 years ago

tiimbz commented 9 years ago

First of all, thank you for this amazing plugin!

We are running into a problem where a member of our team is unable to deploy from his Windows machine, to our server. It fails because the release path that's being constructed at deploy is using the platform-specific "path.join". This means that if path.join is run on Windows, which is the case here, the release path gets separated by backslashes, instead of a forward slash, creating an invalid "mkdir" command on the server:

--------------- CREATING NEW RELEASE
--- mkdir -p \home\user\apps\app\releases\2015070709492140

Running the same process from Mac runs fine:

--------------- CREATING NEW RELEASE
--- mkdir -p /home/user/apps/app/releases/2015070709492140

Caused by ssh_deploy.js, line 60:

var releasePath = path.join(options.deploy_path, 'releases', options.release_subdir, timestamp);

Any idea how to get around this?

hurricane766 commented 9 years ago

I think adding an option for the target machine OS, or the target machine path separator, would solve this. Anywhere path.join is used the code would have to find/replace to make the path separator for the target machine.

options.path_separator defaults to '/'

var releasePath = path.join(options.deploy_path, 'releases', options.release_subdir, timestamp);

if (options.path_separator = '/') {
   releasePath = releasePath.replace('\', '/');    
} else if (options.path_separator = '/') {
   releasePath = releasePath.replace('/', '\');    
}

I would probably try to stick this in a function that also calls path.join so the code copied everywhere.

I'm not sure if there are other path separators to worry about.

tiimbz commented 9 years ago

@hurricane766 you're right, an option to override the separator would be the cleanest approach.

For now, I've patched ssh_deploy.js on two places:

Line #60, where the path is built for the mkdir command:

var releasePath = options.deploy_path+'/releases/'+timestamp;

And line 190-191, where the symlink path is built:

var current_path = options.deploy_path + '/' + options.current_symlink;
var delete_symlink = 'rm -rf ' + current_path;
var set_symlink = 'ln -s ' + releasePath + ' ' + current_path;
okoala commented 9 years ago

can use path.posix.join replace the path.join

dasuchin commented 9 years ago

I don't have a Windows machine to test this on, if someone has a fix I will accept a pull request.

tiimbz commented 9 years ago

I can confirm path.posix.join did the trick in Windows! Thanks @okoala . Pull request submitted.