Skip to content

Commit

Permalink
🐛 Fix issue where node-scp was using an incorrect configuration.
Browse files Browse the repository at this point in the history
Node-SCP has been completely removed as a dependency from the project.
Everything that node-scp can do, node-ssh can do (through ssh2).

Fixes #32.
  • Loading branch information
jwir3 committed Apr 28, 2023
1 parent 0e55cfb commit ceb81fb
Show file tree
Hide file tree
Showing 7 changed files with 2,324 additions and 4,529 deletions.
1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ The number of old releases to keep on the remote host. If set to `-1`, all
cleanup of old releases will be disabled and all releases will be kept
indefinitely. Defaults to `5` if not specified.

### `verbose`
Whether or not to output debugging information. Defaults to `null`, which is
equivalent to `false`. If you want debugging information specified, use `true`.

## Running Tests
### Prerequisites
You will need the following installed prior to running tests:
- [Docker](https://docs.docker.com/engine/install/ubuntu/)
- openssh-server

To install the prerequisites with `apt`, use the following command:
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"dist",
"bin"
],
"bin": {
"shipout": "bin/shipout.js"
},
"bin": "bin/shipout.js",
"scripts": {
"start": "yarn build && node bin/shipout.js",
"build": "tsc",
Expand Down Expand Up @@ -43,8 +41,8 @@
"@babel/preset-env": "^7.10.2",
"@types/jest": "^27.0.2",
"@types/lodash": "^4.14.175",
"@types/ssh2": "^0.5.48",
"@types/node-ssh": "^7.0.1",
"@types/ssh2": "^0.5.48",
"babel-jest": "^27.0.6",
"babel-plugin-root-import": "^6.5.0",
"jest": "27.0.0",
Expand All @@ -60,11 +58,14 @@
"colors": "^1.4.0",
"mkdirp": "^1.0.4",
"moment": "^2.26.0",
"node-scp": "^0.0.15",
"node-ssh": "^13.0.0",
"pretty-logger": "^0.1.2",
"rimraf": "^3.0.2",
"ssh2": "^1.4.0",
"tar": "^6.1.11"
},
"volta": {
"node": "18.14.2",
"yarn": "1.22.19"
}
}
2 changes: 1 addition & 1 deletion src/ConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ConfigStore {
}

getIsVerboseModeForEnvironment(environment) {
return this.getConfigValueForEnvironment(environment, 'verbose');
return this.getConfigValueForEnvironment(environment, 'verbose', false);
}

getHost() {
Expand Down
12 changes: 5 additions & 7 deletions src/RemoteWorkStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class CreateCurrentLinkStage extends RemoteWorkStage {
}

run (data: any) : Promise<any> {
this.getLogger().debug('Creating current link');
this.getLogger().info('Creating current link');
let self = this;

let returnData = data;
Expand Down Expand Up @@ -197,7 +197,7 @@ export class CopyPackageToServerStage extends RemoteWorkStage {
let packedFilePath = data.path;
let deployServer = self.getConfigStore().getHost();

self.getLogger().debug(`Copying ${packedFilePath}/${packedFileName} to ${deployServer}`);
self.getLogger().info(`Copying ${packedFilePath}/${packedFileName} to ${deployServer}`);

return self.getParentWorker()
.copyPackageToServer(packedFilePath, packedFileName)
Expand Down Expand Up @@ -229,9 +229,7 @@ export class UnpackStage extends RemoteWorkStage {
throw 'Data does not contain a fileName property. Did a previous stage fail?';
}

// if (!self.getConfigStore().isTestMode()) {
self.getLogger().debug(`Unpacking ${packedFileName} on remote host...`);
// }
self.getLogger().info(`Unpacking ${packedFileName} on remote host...`);

return self.getParentWorker().unpackRemotely(packedFileName)
.then((newData) => {
Expand Down Expand Up @@ -259,7 +257,7 @@ export class RemoteCleanupStage extends RemoteWorkStage {

run (data: any) : Promise<any> {
let self = this;
self.getLogger().debug('Cleaning up remote directories');
self.getLogger().info('Cleaning up remote directories');

let returnData = data;

Expand Down Expand Up @@ -303,7 +301,7 @@ export class LocalCleanupStage extends RemoteWorkStage {

let filePacker = new FilePacker(self.getConfigStore());

self.getLogger().debug(`Cleaning up ${filePacker.getPackedFilePath()}...`);
self.getLogger().info(`Cleaning up ${filePacker.getPackedFilePath()}...`);

return filePacker.cleanUp()
.then((newData) => {
Expand Down
64 changes: 40 additions & 24 deletions src/RemoteWorker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs, { access, constants } from 'fs';
import path from 'path';
import process from 'process';
import {NodeSSH} from 'node-ssh';
import { Client as SCPClient } from 'node-scp';
import {Config, NodeSSH} from 'node-ssh';
import { RemoteWorkStage, PackageRemoteWorkStage } from 'RemoteWorkStage';
import { Logger } from 'pretty-logger';
import { ConfigStore } from './ConfigStore';
Expand Down Expand Up @@ -231,14 +230,10 @@ export default class RemoteWorker {
let sshConfig = self.getSSHConfiguration();
let remoteBaseDir = self.remoteBaseDir;
let remoteInstanceDir = self.remoteInstanceDir;
let deployUser = sshConfig.username;
let deployServer = sshConfig.host;
let port = sshConfig.port;

return new Promise((resolve, reject) => {
let response = '';
let ssh = new NodeSSH();
console.log(sshConfig);
ssh.connect(sshConfig)
.then(() => {
return ssh.execCommand(`mkdir -p "${remoteBaseDir}/${remoteInstanceDir}"`);
Expand Down Expand Up @@ -298,23 +293,33 @@ export default class RemoteWorker {
resolve();
});
} else {
return SCPClient(this.getSSHConfiguration()).then(client => {
this.logger.debug(`Connected to SSH server. Attempting file transfer from ${localPath} to ${sshConfig.host}:${remotePath}`);
this.logger.debug(`Local path exists? `, fs.existsSync(localPath));

return client.uploadFile(localPath, remotePath)
.then((response) => {
client.close();
resolve();
let ssh = new NodeSSH();
let logger = this.logger;
ssh.connect(sshConfig)
.then(() => {
return ssh.withSFTP((sftp) => {
this.logger.info(`Connected to SFTP server. Attempting file transfer from ${localPath} to ${sshConfig.host}:${remotePath}`);
return new Promise<void>((sftpResolve, sftpReject) => {
sftp.fastPut(localPath, remotePath, (err) => {
if (err) {
logger.error("SFTP failed to put file", err);
sftpReject(err);
} else {
logger.debug("Finished transferring file");
sftpResolve();
}
});
});
})
.catch((error) => {
this.logger.error("Unable to copy file to ssh server due to: ", error);
reject(error);
.then(() => {
this.logger.debug("Finished with SFTP server");
resolve();
})
}).catch((e) => {
this.logger.error(`Unable to connect to ssh host "${sshConfig.host}: `, e);
reject(e);
});
.catch((e) => {
this.logger.error("Issue occurred while connecting to sftp host", e);
reject(e);
});
});
}
});
}
Expand Down Expand Up @@ -364,7 +369,7 @@ export default class RemoteWorker {
* using ssh-agent, the value for the SSH_AUTH_SOCK environment
* variable.
*/
getSSHConfiguration() {
getSSHConfiguration() : Config {
let authSock;
if (!this.privateKey) {
if (process.env.SSH_AUTH_SOCK) {
Expand All @@ -383,8 +388,19 @@ export default class RemoteWorker {
"username": this.user,
"port": this.port,
"privateKey": this.privateKey,
"agent": authSock ? authSock : false
/*"debug": console.log*/
"agent": authSock ? authSock : false,
algorithms: {
serverHostKey: [
'ssh-ed25519',
'ecdsa-sha2-nistp256',
'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp521',
'rsa-sha2-512',
'rsa-sha2-256',
'ssh-rsa',
'ssh-dss'
],
}
};
}

Expand Down

0 comments on commit ceb81fb

Please sign in to comment.