Skip to content

Commit

Permalink
Remove node-ssh dependency, add to api/package.json at setup time (#4931
Browse files Browse the repository at this point in the history
)

* Removes node-ssh dependency

* Move node-ssh require to invoking function

* Add node-ssh to dependencies at setup time

Closes #4930

Co-authored-by: David Price <[email protected]>
  • Loading branch information
cannikin and thedavidprice authored Mar 26, 2022
1 parent 7aa4fa3 commit f4fc08a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 86 deletions.
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"listr": "0.14.3",
"listr-verbose-renderer": "0.6.0",
"lodash": "4.17.21",
"node-ssh": "12.0.4",
"param-case": "3.0.4",
"pascalcase": "1.0.0",
"pluralize": "8.0.0",
Expand Down
34 changes: 18 additions & 16 deletions packages/cli/src/commands/deploy/baremetal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import toml from '@iarna/toml'
import boxen from 'boxen'
import Listr from 'listr'
import VerboseRenderer from 'listr-verbose-renderer'
import { NodeSSH } from 'node-ssh'
import terminalLink from 'terminal-link'

import { getPaths } from '../../lib'
Expand All @@ -15,8 +14,6 @@ import { configFilename } from '../setup/deploy/providers/baremetal'
export const command = 'baremetal'
export const description = 'Deploy to baremetal server(s)'

const ssh = new NodeSSH()

export const execaOptions = {
cwd: path.join(getPaths().base),
stdio: 'inherit',
Expand Down Expand Up @@ -87,7 +84,7 @@ export const builder = (yargs) => {

// Executes a single command via SSH connection, capturing the exit code of the
// process. Displays an error and will exit(1) if code is non-zero
const sshExec = async (sshOptions, task, path, command, args) => {
const sshExec = async (ssh, sshOptions, task, path, command, args) => {
const result = await ssh.execCommand(`${command} ${args.join(' ')}`, {
cwd: path,
})
Expand All @@ -108,7 +105,7 @@ const sshExec = async (sshOptions, task, path, command, args) => {
}
}

const commands = (yargs) => {
const commands = (yargs, ssh) => {
// parse config and get server list
const deployConfig = toml.parse(
fs.readFileSync(path.join(getPaths().base, configFilename))
Expand Down Expand Up @@ -140,34 +137,36 @@ const commands = (yargs) => {
tasks.push({
title: `Updating codebase...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'git', ['pull'])
await sshExec(ssh, sshOptions, task, serverConfig.path, 'git', ['pull'])
},
skip: () => !yargs.pull,
})

tasks.push({
title: `Installing dependencies...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'yarn', ['install'])
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'install',
])
},
skip: () => !yargs.install,
})

tasks.push({
title: `DB Migrations...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'yarn', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'rw',
'prisma',
'migrate',
'deploy',
])
await sshExec(sshOptions, task, serverConfig.path, 'yarn', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'rw',
'prisma',
'generate',
])
await sshExec(sshOptions, task, serverConfig.path, 'yarn', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'rw',
'dataMigrate',
'up',
Expand All @@ -181,7 +180,7 @@ const commands = (yargs) => {
tasks.push({
title: `Building ${side}...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'yarn', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'rw',
'build',
side,
Expand All @@ -196,12 +195,12 @@ const commands = (yargs) => {
tasks.push({
title: `Symlinking web/serve/current...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'cp', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'cp', [
'-r',
'web/dist',
`web/serve/${yargs.releaseDir}`,
])
await sshExec(sshOptions, task, serverConfig.path, 'ln', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'ln', [
'-nsf',
yargs.releaseDir,
'web/serve/current',
Expand All @@ -219,7 +218,7 @@ const commands = (yargs) => {
tasks.push({
title: `Starting ${process} process for the first time...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'yarn', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'pm2',
'start',
'ecosystem.config.js',
Expand All @@ -233,7 +232,7 @@ const commands = (yargs) => {
tasks.push({
title: `Restarting ${process} process...`,
task: async (_ctx, task) => {
await sshExec(sshOptions, task, serverConfig.path, 'yarn', [
await sshExec(ssh, sshOptions, task, serverConfig.path, 'yarn', [
'pm2',
'restart',
process,
Expand Down Expand Up @@ -265,8 +264,11 @@ const commands = (yargs) => {
}

export const handler = async (yargs) => {
const { NodeSSH } = require('node-ssh')
const ssh = new NodeSSH()

try {
const tasks = new Listr(commands(yargs), {
const tasks = new Listr(commands(yargs, ssh), {
concurrent: true,
exitOnError: true,
renderer: yargs.verbose && VerboseRenderer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { errorTelemetry } from '@redwoodjs/telemetry'

import { getPaths } from '../../../../lib'
import c from '../../../../lib/colors'
import { addFilesTask, printSetupNotes } from '../helpers'
import { addFilesTask, addPackagesTask, printSetupNotes } from '../helpers'
import { DEPLOY, ECOSYSTEM } from '../templates/baremetal'

export const command = 'baremetal'
Expand Down Expand Up @@ -38,6 +38,10 @@ const notes = [

export const handler = async ({ force }) => {
const tasks = new Listr([
addPackagesTask({
packages: ['node-ssh'],
devDependency: true,
}),
addFilesTask({
files,
force,
Expand Down
71 changes: 3 additions & 68 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5874,7 +5874,6 @@ __metadata:
listr: 0.14.3
listr-verbose-renderer: 0.6.0
lodash: 4.17.21
node-ssh: 12.0.4
param-case: 3.0.4
pascalcase: 1.0.0
pluralize: 8.0.0
Expand Down Expand Up @@ -9888,7 +9887,7 @@ __metadata:
languageName: node
linkType: hard

"asn1@npm:^0.2.4, asn1@npm:~0.2.3":
"asn1@npm:~0.2.3":
version: 0.2.6
resolution: "asn1@npm:0.2.6"
dependencies:
Expand Down Expand Up @@ -10651,7 +10650,7 @@ __metadata:
languageName: node
linkType: hard

"bcrypt-pbkdf@npm:^1.0.0, bcrypt-pbkdf@npm:^1.0.2":
"bcrypt-pbkdf@npm:^1.0.0":
version: 1.0.2
resolution: "bcrypt-pbkdf@npm:1.0.2"
dependencies:
Expand Down Expand Up @@ -12622,16 +12621,6 @@ __metadata:
languageName: node
linkType: hard

"cpu-features@npm:0.0.2":
version: 0.0.2
resolution: "cpu-features@npm:0.0.2"
dependencies:
nan: ^2.14.1
node-gyp: latest
checksum: 54e6b66bcb3e046ce39a0116ddfde209a77202574ecedc820128021ff56e1022601d666721545342e0d08922b748a33d43c7c1e7d0040079c3c431a8bafe4b3a
languageName: node
linkType: hard

"cpy@npm:^8.1.2":
version: 8.1.2
resolution: "cpy@npm:8.1.2"
Expand Down Expand Up @@ -21897,7 +21886,7 @@ __metadata:
languageName: node
linkType: hard

"nan@npm:^2.12.1, nan@npm:^2.14.1, nan@npm:^2.15.0":
"nan@npm:^2.12.1":
version: 2.15.0
resolution: "nan@npm:2.15.0"
dependencies:
Expand Down Expand Up @@ -22219,20 +22208,6 @@ __metadata:
languageName: node
linkType: hard

"node-ssh@npm:12.0.4":
version: 12.0.4
resolution: "node-ssh@npm:12.0.4"
dependencies:
is-stream: ^2.0.0
make-dir: ^3.1.0
sb-promise-queue: ^2.1.0
sb-scandir: ^3.1.0
shell-escape: ^0.2.0
ssh2: ^1.5.0
checksum: 077ffcdca7613b9192e59b2e9246065b7b84b5c29d7ed67f4c3985d224e8aa242cc8b95f1197171383ac415a2a55e500e5328495373b88e010abb50f8e77e516
languageName: node
linkType: hard

"nodemon@npm:2.0.15":
version: 2.0.15
resolution: "nodemon@npm:2.0.15"
Expand Down Expand Up @@ -26388,22 +26363,6 @@ __metadata:
languageName: node
linkType: hard

"sb-promise-queue@npm:^2.1.0":
version: 2.1.0
resolution: "sb-promise-queue@npm:2.1.0"
checksum: 76ee74af0c7c4db89fac2acf12615c1801f2c2848fd8028a97b515d13adcc680f68f353ebb6ddc7f4253619326e62b7cf5f1afc6a675b1470d4df30b726452ed
languageName: node
linkType: hard

"sb-scandir@npm:^3.1.0":
version: 3.1.0
resolution: "sb-scandir@npm:3.1.0"
dependencies:
sb-promise-queue: ^2.1.0
checksum: 550ac637d8e4a5c05ab8220bd9d2978f6f69a32f7096200474450684d54245fed76182976b6d1348939365d6ac60b65c24be2a35715b5c694e3c36d93d00f41f
languageName: node
linkType: hard

"scheduler@npm:^0.20.2":
version: 0.20.2
resolution: "scheduler@npm:0.20.2"
Expand Down Expand Up @@ -26823,13 +26782,6 @@ __metadata:
languageName: node
linkType: hard

"shell-escape@npm:^0.2.0":
version: 0.2.0
resolution: "shell-escape@npm:0.2.0"
checksum: 501616713d13fd053b3858da18b613d83bfcdc8368e62be393dc563cc9fe2550492d403f73211e9a84429f39c8b9617f1e016dabee177b0ebdcb298fa47fc612
languageName: node
linkType: hard

"shell-exec@npm:1.0.2":
version: 1.0.2
resolution: "shell-exec@npm:1.0.2"
Expand Down Expand Up @@ -27369,23 +27321,6 @@ __metadata:
languageName: node
linkType: hard

"ssh2@npm:^1.5.0":
version: 1.7.0
resolution: "ssh2@npm:1.7.0"
dependencies:
asn1: ^0.2.4
bcrypt-pbkdf: ^1.0.2
cpu-features: 0.0.2
nan: ^2.15.0
dependenciesMeta:
cpu-features:
optional: true
nan:
optional: true
checksum: 313ab70d1cd077a878a7d7ae61204eb323c6d1b75bf1a6713099e7f3ba351f911644b845030426fdcafa3a2439e3927d16aacb812b713d1c184751176fd9c242
languageName: node
linkType: hard

"sshpk@npm:^1.14.1, sshpk@npm:^1.7.0":
version: 1.17.0
resolution: "sshpk@npm:1.17.0"
Expand Down

0 comments on commit f4fc08a

Please sign in to comment.