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
46 changes: 43 additions & 3 deletions packages/shipit-cli/src/Shipit.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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 +248,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: [...new Set([...defaultOptions.rsync, ...copyOptions.rsync])]}

return this.pool.copy(src, dest, copyOptions)
}
Expand All @@ -252,7 +278,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: [...new Set([...defaultOptions.rsync, ...copyOptions.rsync])]}

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

Expand All @@ -274,7 +307,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: [...new Set([...defaultOptions.rsync, ...copyOptions.rsync])]}

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

Expand Down
78 changes: 78 additions & 0 deletions packages/shipit-cli/src/Shipit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,36 @@ describe('Shipit', () => {
rsync: ['--bar'],
})
})

it('should support show-progress flag', () => {

shipit.setShowProgress()

shipit.remoteCopy('src', 'dest', {
direction: 'remoteToLocal',
})

expect(shipit.pool.copy).toBeCalledWith('src', 'dest', {
direction: 'remoteToLocal',
ignores: [],
rsync: ["--progress"],
})
})

it('should support show-stats flag', () => {

shipit.setShowStats()

shipit.remoteCopy('src', 'dest', {
direction: 'remoteToLocal',
})

expect(shipit.pool.copy).toBeCalledWith('src', 'dest', {
direction: 'remoteToLocal',
ignores: [],
rsync: ["--stats"],
})
})
})

describe('#copyFromRemote', () => {
Expand Down Expand Up @@ -193,6 +223,30 @@ describe('Shipit', () => {
rsync: ['--bar'],
})
})

it('should support show-progress flag', () => {

shipit.setShowProgress()

shipit.copyFromRemote('src', 'dest')

expect(shipit.pool.copyFromRemote).toBeCalledWith('src', 'dest', {
ignores: [],
rsync: ["--progress"],
})
})

it('should support show-stats flag', () => {

shipit.setShowStats()

shipit.copyFromRemote('src', 'dest')

expect(shipit.pool.copyFromRemote).toBeCalledWith('src', 'dest', {
ignores: [],
rsync: ["--stats"],
})
})
})

describe('#copyToRemote', () => {
Expand Down Expand Up @@ -233,5 +287,29 @@ describe('Shipit', () => {
rsync: ['--bar'],
})
})

it('should support show-progress flag', () => {

shipit.setShowProgress()

shipit.copyToRemote('src', 'dest')

expect(shipit.pool.copyToRemote).toBeCalledWith('src', 'dest', {
ignores: [],
rsync: ["--progress"],
})
})

it('should support show-stats flag', () => {

shipit.setShowStats()

shipit.copyToRemote('src', 'dest')

expect(shipit.pool.copyToRemote).toBeCalledWith('src', 'dest', {
ignores: [],
rsync: ["--stats"],
})
})
})
})
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 @@ -337,7 +337,7 @@ class Connection {
src,
dest,
remoteShell: sshCommand,
additionalArgs: typeof rsync === 'string' ? [rsync] : rsync,
additionalArgs: (typeof rsync === 'string' ? [rsync] : rsync),
excludes: ignores,
})

Expand Down