dasuchin / grunt-ssh-deploy Goto Github PK
View Code? Open in Web Editor NEWGrunt SSH Deployment
License: MIT License
Grunt SSH Deployment
License: MIT License
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?
In examples, there is debug
option, but it is not described in readme.md.
What does it do?
Sometimes I get the error file changed as we read it
when I set the deploy_zip
option to true
. It is totally random.
When I try to run my task, I keep getting:
Running "ssh_deploy:staging" (ssh_deploy) task
Warning: Cannot read property 'staging' of undefined Use --force to continue.
I am using load-grunt-config and my config file looks like this:
module.exports = {
environments: {
staging: {
options: {
host: '<%= secret.staging.host %>',
username: '<%= secret.staging.username %>',
password: '<%= secret.staging.password %>',
port: '<%= secret.staging.port %>',
deploy_path: '<%= secret.staging.deployPath %>',
local_path: '<%= secret.staging.localPath %>',
current_symlink: 'current',
debug: true
}
}
}
}
Any Ideas, I'm completely stumped.
Cheers.
I need to deploy files to 2 locations on the target machine however due to a bug in scp2 v0.1.4 the server connection isn't closed properly after the 1st deploy, which causes the 2nd deploy to fail, see this spmjs/node-scp2#10
Apparently this has been fixed in v0.2.0 so it would be good to update to this.
Hi Dustin,
With the latest version (0.3.1), I always get this error Cannot call method 'join' of undefined
. I tried both on Ubuntu 15 and Windows 10, same problem.
I tried with an older version of this plugin (0.2.6) and the deployment worked without changing anything in my Gruntfile.js
(just updating the content of /node_modules/grunt-ssh-deploy) . But I need the features that have been recently introduced (options.release_subdir + options.release_root).
I tried running grunt ssh_deploy:digitalocean --debug
but it didn't help me figure out what's wrong. Please let me know what debug information I should provide you to help me solve this.
Thanks!
PS: I'm cc'ing @julien731
Hello there,
In most projects I use grunt-dploy to deploy my local projects. It has an option to exclude stuff. Normally, I exclude the following files and folders: like *.less
, *.coffee
, */node_modules
.
What's the workflow with grunt-ssh-deploy? Also, I don't understand how you deal with the different releases folders that are created. I'd be grateful if you can provide further explanation :)
Thanks
Suggestion: replace var childProcessExec = require('child_process').exec; with var childProcessExec = require('exec-sync');
This way post execution actions would execute after all the files are uploaded.
When I run the command 'grunt ssh_deploy:staging' command, I'm getting the error...
Warning: Cannot call method 'join' of undefined Use --force to continue.
I fixed this by replacing all instances of 'path.posix.join' to 'path.join' in ssh_deploy - I can put in a pull request with this fix if you want.
Hi there,
First of all. Thank you!
I am using your module with grunt-build-control also.
Wouldn't it be helpful that, instead of uploading the files straight from the local filesystem, the module clones the repository while logged on the server?
Basically all it's needed in the configuration is the repository url and the branch to pull from. And the command to do that obviously.
What do you think?
npm install grunt-ssh-deploy
installs a version without some of the newer bug fixes.
This has caused some headaches:
#11
Connecting with ssh manually works for me,
when i try to deploy using ssh_deploy i get
Error: Timed out while waiting for handshake
My config:
secret: grunt.file.readJSON('secret.json'),
environments: {
theme: {
options: {
host: '<%= secret.theme.host %>',
username: '<%= secret.theme.username %>',
password: '<%= secret.theme.password %>',
port: '<%= secret.theme.port %>',
deploy_path: '/public_html/newfolder',
readyTimeout: 99999,
local_path: '../wp-content/themes/mytheme/',
current_symlink: 'current',
debug: console.log
}
},
The command:
grunt ssh_deploy:theme
The Output:
Running "ssh_deploy:theme" (ssh_deploy) task
Connecting :: myserver.com
DEBUG: Parser: STATE_INIT
Is there any way to have the symlinked folder and the releases
folder at a different level on the server? And if not, is there any way to get the name of the folder that's just been created for the new release so that I can manually create a symlink after deployment?
Hi,
Current version of grunt-ssh-deploy
depends on version 0.1.4
of scp2
which is vulnerable to the Regular Expression Denial of Service, as per npm audit
output:
High Regular Expression Denial of Service
Package minimatch
Patched in >=3.0.2
Dependency of grunt-ssh-deploy [dev]
Path grunt-ssh-deploy > scp2 > glob > minimatch
More info https://nodesecurity.io/advisories/118
Upgrading scp2
from 0.1.4
to 0.5.0
would fix it.
Tried to figure out the reason for that problem and found -i Parameter and path to key file is missing.
In ssh-deploy configuration is only an option to import appropriate key files content.
In ssh_deploy.js task file on line 112:
var command = 'scp -P ' + options.port + ' -r ' + options.local_path + '/ ' + remote_string;
Adding a new option (privateKeyPath) solves the issue for me with a fix on scp command
var command = 'scp -i ' + options.privateKeyPath + ' -P ' + options.port + ' -r ' + options.local_path + '/ ' + remote_string;
When sorting the releases
directory to determine which releases to keep, it would be great if it listed the contents of the directory in a reversed natural sort order by adding the -v
flag to the existing ls -r
command.
This should get over the naming issue when using version numbers for release directories.
In the documentation the option for deleting old releases is named releases_to_keep
. But in the code it is called number_of_releases
. This makes this functionality not to work.
see pull request #7
So, when i execute, for exemple npm install after_deploy, i'd like to receive npm output. is it possible?
Hi
Have a simple conf:
environments: {
prod: {
options: {
hosts: 'website.net',
username: 'username',
privateKey: require('fs').readFileSync('/path/to/id_rsa'),
deploy_path: '/srv/www/mywebsite',
local_path: 'dist',
}
}
}
When I launch grunt ssh_deploy:prod
I got this error:
Running "ssh_deploy:prod" (ssh_deploy) task
Connecting :: website.net
Fatal error: must start with number, buffer, array or string
Best regard
hi guys,
maybe you do have an idea:
I have a rather big release (150mb, gzipped with max compression). If I upload it from the shell via SCP, I get ~1.5 mb/sec. but if I upload it with grunt-ssh-deploy, I only get ~100 kb/sec which makes the deployment painfully long...
have you ever experienced something like this?
this is my config:
environments: {
options: {
local_path: "atlas-release.tar.gz",
deploy_path: "~/releases"
},
aws_test: {
options: {
host: "xxx",
username: "devenv",
port: 2222,
agent: process.env.SSH_AUTH_SOCK,
debug: true,
releases_to_keep: 1,
after_deploy: "cd ~/releases/current && tar -zxf release.tar.gz"
}
}
}
Source code uses extensively path.posix
which is only available from node 0.12.0 up. While this is not worth a pull request, you should add this info to the README as the error message that comes out of the console does not state it clear the problem.
You cannot make deploy to empty directory. If Releases directory not there, first step fails.
(I have fix in my fork)
hey guys, what about keep release options?)
I have an after_deploy
command that is not being triggered correctly.
Output says it is
--------------- RUNNING PRE-DEPLOY COMMANDS
--- kill -KILL `ps o pid= -C main`
--------------- CREATING NEW RELEASE
--- cd /var/www && mkdir -p releases/20150320151525912
--------------- UPLOADING NEW BUILD
--- DONE UPLOADING
--------------- UPDATING SYM LINK
--- rm -rf /var/www/current && cd /var/www && ln -s releases/20150320151525912 current
--------------- RUNNING POST-DEPLOY COMMANDS
--- cd /var/www/current && go build main.go && nohup ./main &
But I am not getting anything on the directory.
And releases_to_keep
is not removing any releases.
The Gruntfile
enviroments: {
options: {
privateKey: key,
username: username,
host: host,
deploy_path: '/var/www',
local_path: 'dist',
releases_to_keep: 2
},
production: {
options: {
before_deploy: 'kill -KILL `ps o pid= -C main`',
after_deploy: 'cd /var/www/current && go build main.go && nohup ./main &',
}
}
}
Hi,
Symlink is not created even if i have success message.
same issue as in :
Thank you for your help.
Hi I'am setting up grunt-ssh-deploy at the moment, however I can't figure out why my excluded folders and files still getting uploaded. Here are my Grunt settings:
environments: {
options: {
local_path: './',
current_symlink: 'current',
deploy_path: '/apps'
},
production: {
options: {
host: '<%= secret.production.host %>',
username: '<%= secret.production.username %>',
password: '<%= secret.production.password %>',
port: '<%= secret.production.port %>',
releases_to_keep: '3',
release_subdir: 'zahnarzt',
exclude: [
// Exclude Folders
'bower_components',
'node_modules',
'public/css',
'public/icons',
'public/js',
// Files
'.git',
'.gitignore',
'.idea',
'.sass-cache',
// Secrets
'secret.json'
]
}
}
}
With version 0.2.8 evertything is fine.
But in version 0.2.8 thing going wrong:
Log of success execution of grunt-ssh-deploy v0.2.9:
[4m Running "ssh_deploy:example_deploy" (ssh_deploy) task
[24m
[D]
[35m Task source: c:\path_to_project\node_modules\example-gruntproject\node_modules\grunt-ssh-deploy\tasks\ssh_deploy.js
[39m
[1mConnecting :: example.site[22m
[1mConnected :: example.site[22m
[1m--------------- CREATING NEW RELEASE[22m
[1m--- cd /home/example/www/example_deploy/v2 && mkdir -p releases/20150729104953742
[22m
[D]
[35m REMOTE: cd /home/example/www/example_deploy/v2 && mkdir -p releases/20150729104953742
[39m
[1m--------------- UPLOADING NEW BUILD
[22m
[D]
[35m SCP FROM LOCAL: build/example_deploy
TO REMOTE: /home/example/www/example_deploy/v2/releases/20150729104953742/
[39m
[1m--- DONE UPLOADING
[22m
[1m--------------- UPDATING SYM LINK
[22m
[1m--- rm -rf /home/example/www/example_deploy/v2/3eec74c8097f713f897650a8d4ad7ec9 && ln -s /home/example/www/example_deploy/v2/releases/20150729104953742 /home/example/www/example_deploy/v2/3eec74c8097f713f897650a8d4ad7ec9
[35m REMOTE: rm -rf /home/example/www/example_deploy/v2/3eec74c8097f713f897650a8d4ad7ec9 && ln -s /home/example/www/example_deploy/v2/releases/20150729104953742 /home/example/www/example_deploy/v2/3eec74c8097f713f897650a8d4ad7ec9
[39m
[32mDone, without errors.
[39m
And fail execution of grunt-ssh-deploy v0.2.8:
[4mRunning "ssh_deploy:example_deploy" (ssh_deploy) task
[24m
[D]
[35m Task source: C:\path_to_project\example-gruntproject\node_modules\grunt-ssh-deploy\tasks\ssh_deploy.js
[39m
[1mConnecting :: example.site
[22m
[1mConnected :: example.site
[22m
[1m--------------- CREATING NEW RELEASE
[22m
[1m--- mkdir -p \home\example\www\example_deploy\v2\releases\20150729110150023
[22m
[D]
[35mREMOTE: mkdir -p \home\example\www\example_deploy\v2\releases\20150729110150023
[39m
[1m--------------- UPLOADING NEW BUILD
[22m
[D]
[35mSCP FROM LOCAL: build/example_deploy
TO REMOTE: \home\example\www\example_deploy\v2\releases\20150729110150023
[39m
[1m--- DONE UPLOADING
[22m
[1m--------------- UPDATING SYM LINK
[22m
[1m--- rm -rf \home\example\www\example_deploy\v2\3eec74c8097f713f897650a8d4ad7ec9 && ln -s \home\example\www\example_deploy\v2\releases\20150729110150023 \home\example\www\example_deploy\v2\3eec74c8097f713f897650a8d4ad7ec9
[22m
[D]
[35mREMOTE: rm -rf \home\example\www\example_deploy\v2\3eec74c8097f713f897650a8d4ad7ec9 && ln -s \home\example\www\example_deploy\v2\releases\20150729110150023 \home\example\www\example_deploy\v2\3eec74c8097f713f897650a8d4ad7ec9
[39m
[32mDone, without errors.
[39m
Suppose, ploblem here:
[35mREMOTE: rm -rf \home\example\www\example_deploy\v2\3eec74c8097f713f897650a8d4ad7ec9 && ln -s \home\example\www\example_deploy\v2\releases\20150729110150023 \home\example\www\example_deploy\v2\3eec74c8097f713f897650a8d4ad7ec9
Backslashes instead of straight slashes!
Hi,
i just tried to deploy with thesse settings - but it did not work:
environments: {
staging: {
options: {
host: 'host.de',
port: 22,
agent: process.env.SSH_AUTH_SOCK,
deploy_path: '/var/www/test/',
local_path: 'dist',
current_symlink: 'current',
debug: true
}
}
}
The only errormessage was:
Warning: Password or private key required.
I thought, the input of password or key was not necessary with agent?
using ssh host.de in terminal works as expected..
thx for your help!
greetings
When using the zip option on OSX the deployment falls over because of the --ignore-failed-read flag.
Awesome library. I'm trying to deploy to 2 servers, behind an ELB. Since I cannot add an array of hosts to 1 environment, I have to make 2 environments (e.g. prod1, prod2), and combine them into 1 "deploy-prod" task. Unfortunately, I get a "Maximum call stack size exceeded". Running grunt with --verbose, everything looks clean.
Does not work: grunt.registerTask('deploy-prod', ['default', 'ssh_deploy:prod1', 'ssh_deploy:prod2']);
(1) Would be great to allow an array of hosts
or
(2) Would be great to fix the Max call stack size exceeded if deploying multiple environments
--------- logs below -----------
Connecting :: ec2-xxxxx.us-west-2.compute.amazonaws.com
Connected :: ec2-xxxxx.us-west-2.compute.amazonaws.com
--------------- CREATING NEW RELEASE
--- mkdir -p /var/www/xxxxx/prod/releases/20151027130346310
--------------- UPLOADING NEW BUILD
--- DONE UPLOADING
--------------- UPDATING SYM LINK
--- rm -rf /var/www/xxxxx/prod/v1 && ln -s /var/www/xxxxx/prod/releases/20151027130346310 /var/www/xxxxx/prod/v1
--------------- REMOVING OLD BUILDS
--- cd /var/www/xxxxx/prod/releases/ && rm -rfv `ls -r /var/www/xxxxx/prod/releases/ | awk 'NR>3'`
Running "ssh_deploy:prod2" (ssh_deploy) task
Closed :: ec2-xxxxx.us-west-2.compute.amazonaws.com
Connecting :: ec2-xxxxx.us-west-2.compute.amazonaws.com
Connected :: ec2-xxxxx.us-west-2.compute.amazonaws.com
--------------- CREATING NEW RELEASE
--- mkdir -p /var/www/xxxxxt/prod/releases/20151027130349350
--------------- UPLOADING NEW BUILD
Fatal error: Maximum call stack size exceeded
May be it is worth to put in documentation that ssh key authorisation works if you put in options:
privateKey: require('fs').readFileSync('/path/to/private/key'),
For some reason my deploy task hang after last message:
Closed :: myhostname
I get this unhelpful error message when trying to deploy with the below config:
environments: {
options: {
current_symlink: 'current',
deploy_path: '/webapps/<%= appConfig.package.name %>',
local_path: './dist'
},
dev: {
options: {
host: 'my-ec2-instance.compute.amazonaws.com',
privateKey: require('fs').readFileSync('/path/to/key'),
tag: '<%= appConfig.package.version %>',
releases_to_keep: '3'
}
}
},
Adding a username to the options causes the connection to fail with Error: Authentication failure. Available authentication methods: publickey
When I set the zip_deploy
option to true
i get the following error.
Running "ssh_deploy:test" (ssh_deploy) task
Connecting :: xyz
Connected :: xyz
--------------- ZIPPING FOLDER
--- tar -czvf ./deploy.tgz --directory=. . --exclude=deploy.tgz
>> exec error: Error: stdout maxBuffer exceeded.
Error deploying. Closing connection.
--------------- DELETING RELEASE
--- rm -rf /.../releases/20150317153853388/
Fatal error: undefined is not a function
I am using the latest version (0.2.4).
I am trying to deploy an artifact to a remote Windows machine. It gives me a connection error.
Error: connect ECONNREFUSED
Fatal error: connect ECONNREFUSED
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect as oncomplete
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.