Friday, March 31, 2017

Deploy files or directory hierarchies to a server using Grunt and ppk file


Grunt Sftp Deployment using ppk file

Add Grunt sftp-deploy plugin using below command

npm install grunt-sftp-deploy

Create the Gruntfile.js

module.exports = function(grunt) {
grunt.initConfig({
//server deployment
'sftp-deploy': {
build: {
auth: {
host: 'wwww.hostname.com',
port: 22,
authKey: 'privateKeyCustom'
},
cache: 'sftpCache.json',
src: "js_files/",
dest: "/var/www/root2",
serverSep: '/',
concurrency: 4,
progress: true
}
},
});
grunt.loadNpmTasks('grunt-sftp-deploy');
};
view raw GruntFile.js hosted with ❤ by GitHub

Create the .ftppass The below file will contains the server connection details

{
"privateKeyCustom": {
"username": "root",
"keyLocation": "E:/credentials/keys/serverkey.ppk"
}
}
view raw .ftppass hosted with ❤ by GitHub
With any luck, you will get a sweet deployment result like this after enter the below command
$ grunt sftp-deploy:build
>> Logging in with key at E:/credentials/keys/serverkey.ppk
>> Concurrency : 4
transferred=[1/3] elapsed=[0.0s] overall=[33%] eta=[0.0s] [====== ]
>> Directories done.
transferred=[2/3] elapsed=[0.7s] overall=[67%] eta=[0.4s] [============ ]
>> Transferred : 0 Mb
Done, without errors.