Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Add show-progress and show-stats flags to enable logging during rsync #240

Closed
1 change: 1 addition & 0 deletions packages/shipit-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"chalk": "^2.4.1",
"commander": "^2.15.0",
"lodash": "^4.17.10",
utkarsh-dixit marked this conversation as resolved.
Show resolved Hide resolved
"interpret": "^1.1.0",
"liftoff": "^2.5.0",
"orchestrator": "^0.3.7",
Expand Down
47 changes: 44 additions & 3 deletions packages/shipit-cli/src/Shipit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LineWrapper from 'stream-line-wrapper'
import Orchestrator from 'orchestrator'
import chalk from 'chalk'
import prettyTime from 'pretty-hrtime'
import _ from 'lodash'

/**
* An ExecResult returned when a command is executed with success.
Expand Down Expand Up @@ -170,6 +171,26 @@ class Shipit extends Orchestrator {
return this
}

/**
* Add --progress flag to rsync config.
*
* @returns {Shipit} for chaining
*/
setShowProgress(){
this.config.rsync = this.config.rsync ? [...this.config.rsync, "--progress"] : ["--progress"]
return this
}

/**
* Add --stats flag to rsync config.
*
* @returns {Shipit} for chaining
*/
setShowStats(){
this.config.rsync = this.config.rsync ? [...this.config.rsync, "--stats"] : ["--stats"]
return this
}

/**
* Initialize shipit configuration.
*
Expand Down Expand Up @@ -228,7 +249,13 @@ class Shipit extends Orchestrator {
ignores: this.config && this.config.ignores ? this.config.ignores : [],
rsync: this.config && this.config.rsync ? this.config.rsync : [],
}
const copyOptions = { ...defaultOptions, ...options }
let copyOptions = { ...defaultOptions, ...options }

// Stop rsync config to be overwrited from the deploy rsync options.
if(typeof copyOptions.rsync === 'string') {
copyOptions.rsync = [copyOptions.rsync]
}
copyOptions = {...copyOptions, rsync: _.uniq([...defaultOptions.rsync, ...copyOptions.rsync])}

return this.pool.copy(src, dest, copyOptions)
}
Expand All @@ -252,7 +279,14 @@ class Shipit extends Orchestrator {
ignores: this.config && this.config.ignores ? this.config.ignores : [],
rsync: this.config && this.config.rsync ? this.config.rsync : [],
}
const copyOptions = { ...defaultOptions, ...options }
let copyOptions = { ...defaultOptions, ...options }

// Stop rsync config to be overwrited from the deploy rsync options.
if(typeof copyOptions.rsync === 'string') {
copyOptions.rsync = [copyOptions.rsync]
}
copyOptions = {...copyOptions, rsync: _.uniq([...defaultOptions.rsync, ...copyOptions.rsync])}

return this.pool.copyToRemote(src, dest, copyOptions)
}

Expand All @@ -274,7 +308,14 @@ class Shipit extends Orchestrator {
ignores: this.config && this.config.ignores ? this.config.ignores : [],
rsync: this.config && this.config.rsync ? this.config.rsync : [],
}
const copyOptions = { ...defaultOptions, ...options }
let copyOptions = { ...defaultOptions, ...options }

// Stop rsync config to be overwrited from the deploy rsync options.
if(typeof copyOptions.rsync === 'string') {
copyOptions.rsync = [copyOptions.rsync]
}
copyOptions = {...copyOptions, rsync: _.uniq([...defaultOptions.rsync, ...copyOptions.rsync])}

return this.pool.copyFromRemote(src, dest, copyOptions)
}

Expand Down
17 changes: 17 additions & 0 deletions packages/shipit-cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ program
.option('--require <files...>', 'Script required before launching Shipit')
.option('--tasks', 'List available tasks')
.option('--environments', 'List available environments')
.option('-p, --show-progress', 'Show rsync Progress')
.option('-s, --show-stats', 'Show rsync Stats')

program.parse(process.argv)

Expand All @@ -49,6 +51,14 @@ function logEnvironments(shipit) {
)
}

function logProgress(shipit) {
shipit.setShowProgress()
}

function logStats(shipit) {
shipit.setShowStats()
}

async function asyncInvoke(env) {
if (!env.configPath) {
console.error(chalk.red('shipitfile not found'))
Expand All @@ -71,6 +81,13 @@ async function asyncInvoke(env) {
throw error
}

if(program.showProgress) {
logProgress(shipit)
}
if(program.showStats){
logStats(shipit)
}

if (program.tasks === true) {
logTasks(shipit)
} else if (program.environments === true) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ssh-pool/src/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class Connection {
src,
dest,
remoteShell: sshCommand,
additionalArgs: typeof rsync === 'string' ? [rsync] : rsync,
additionalArgs: (typeof rsync === 'string' ? [rsync] : rsync),
excludes: ignores,
})

Expand Down