From 680388f709973f5f0e2166d866a92d3d22b39ce4 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 28 Apr 2024 08:00:45 +0200 Subject: [PATCH 1/3] feat(baremetal): Add verbose output to ssh exec --- packages/cli/src/commands/deploy/baremetal.js | 2 +- .../src/commands/deploy/baremetal/SshExecutor.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/deploy/baremetal.js b/packages/cli/src/commands/deploy/baremetal.js index 0e0fb0b3b641..9ded79319a37 100644 --- a/packages/cli/src/commands/deploy/baremetal.js +++ b/packages/cli/src/commands/deploy/baremetal.js @@ -672,7 +672,7 @@ export const handler = async (yargs) => { verbose: yargs.verbose, }) - const ssh = new SshExecutor() + const ssh = new SshExecutor(yargs.verbose) try { const tasks = new Listr(commands(yargs, ssh), { diff --git a/packages/cli/src/commands/deploy/baremetal/SshExecutor.js b/packages/cli/src/commands/deploy/baremetal/SshExecutor.js index 428fc4e6cae3..84b2d36dbc74 100644 --- a/packages/cli/src/commands/deploy/baremetal/SshExecutor.js +++ b/packages/cli/src/commands/deploy/baremetal/SshExecutor.js @@ -1,7 +1,8 @@ export class SshExecutor { - constructor() { + constructor(verbose) { const { NodeSSH } = require('node-ssh') this.ssh = new NodeSSH() + this.verbose = verbose } /** @@ -20,9 +21,14 @@ export class SshExecutor { }) if (result.code !== 0) { - const error = new Error( - `Error while running command \`${command} ${args.join(' ')}\``, - ) + const error = this.verbose + ? new Error( + `Error while running command \`${command} ${args.join(' ')}\` in ${path}\n` + + result.stderr, + ) + : new Error( + `Error while running command \`${command} ${args.join(' ')}\``, + ) error.exitCode = result.code throw error } From 66d6eaef5719ea9550588050a71d035207ee9c2d Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 28 Apr 2024 08:11:08 +0200 Subject: [PATCH 2/3] changeset --- .changesets/10525.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changesets/10525.md diff --git a/.changesets/10525.md b/.changesets/10525.md new file mode 100644 index 000000000000..ab05c620a06c --- /dev/null +++ b/.changesets/10525.md @@ -0,0 +1,13 @@ +- feat(baremetal): Add verbose output to ssh exec (#10525) by @Tobbe + +Passing `--verbose` to the baremetal deploy command is supposed to give you more detailed info about what's happening. This is especially useful if something goes wrong and you get an error. Previously however passing `--verbose` didn't actually provide any extra information about why an SSH command might have failed. With this PR you'll now see what path it's trying to execute the command in, and what the exact error message was if it failed. + +Standard output (this stays the same before and after) +![image](https://github.com/redwoodjs/redwood/assets/30793/588fcf3d-b059-42d2-a1af-d2fff8b3e4bd) + +## Before (verbose output) +![image](https://github.com/redwoodjs/redwood/assets/30793/65fdfe46-2e82-4c87-897b-99a438e16149) +Doesn't really help much compared to the standard output 😅 + +## After (verbose output) +![image](https://github.com/redwoodjs/redwood/assets/30793/02e42560-8e6e-439c-9dd8-1360ba673ffe) From f291b4bc1661f87f91551c7679b76d774062c94e Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 29 Apr 2024 10:38:47 +0200 Subject: [PATCH 3/3] Only --verbose logging, no error changes --- .changesets/10525.md | 8 ++++++-- .../commands/deploy/baremetal/SshExecutor.js | 17 +++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.changesets/10525.md b/.changesets/10525.md index ab05c620a06c..e35350599a70 100644 --- a/.changesets/10525.md +++ b/.changesets/10525.md @@ -1,6 +1,10 @@ - feat(baremetal): Add verbose output to ssh exec (#10525) by @Tobbe -Passing `--verbose` to the baremetal deploy command is supposed to give you more detailed info about what's happening. This is especially useful if something goes wrong and you get an error. Previously however passing `--verbose` didn't actually provide any extra information about why an SSH command might have failed. With this PR you'll now see what path it's trying to execute the command in, and what the exact error message was if it failed. +Passing `--verbose` to the baremetal deploy command is supposed to give you +more detailed info about what's happening. Previously however passing +`--verbose` didn't actually provide any extra information. This PR adds logging +to the new SshExecutor class so that you can see exactly what SSH commands are +being run, and in what path. Standard output (this stays the same before and after) ![image](https://github.com/redwoodjs/redwood/assets/30793/588fcf3d-b059-42d2-a1af-d2fff8b3e4bd) @@ -10,4 +14,4 @@ Standard output (this stays the same before and after) Doesn't really help much compared to the standard output 😅 ## After (verbose output) -![image](https://github.com/redwoodjs/redwood/assets/30793/02e42560-8e6e-439c-9dd8-1360ba673ffe) +![image](https://github.com/redwoodjs/redwood/assets/30793/4a87bde4-072f-4bae-a84e-50ac72afe964) diff --git a/packages/cli/src/commands/deploy/baremetal/SshExecutor.js b/packages/cli/src/commands/deploy/baremetal/SshExecutor.js index 84b2d36dbc74..c9f5ebe8daf4 100644 --- a/packages/cli/src/commands/deploy/baremetal/SshExecutor.js +++ b/packages/cli/src/commands/deploy/baremetal/SshExecutor.js @@ -16,19 +16,20 @@ export class SshExecutor { sshCommand += ` ${args.join(' ')}` } + if (this.verbose) { + console.log( + `SshExecutor::exec running command \`${command} ${args.join(' ')}\` in ${path}`, + ) + } + const result = await this.ssh.execCommand(sshCommand, { cwd: path, }) if (result.code !== 0) { - const error = this.verbose - ? new Error( - `Error while running command \`${command} ${args.join(' ')}\` in ${path}\n` + - result.stderr, - ) - : new Error( - `Error while running command \`${command} ${args.join(' ')}\``, - ) + const error = new Error( + `Error while running command \`${command} ${args.join(' ')}\``, + ) error.exitCode = result.code throw error }