mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-19 08:08:05 +08:00
Compare commits
56 Commits
v2.0.2
...
v2.1.6-rc.
Author | SHA1 | Date | |
---|---|---|---|
|
a27b8667de | ||
|
2b38f7bf7a | ||
|
cd3b869a28 | ||
|
191986574c | ||
|
d41b136666 | ||
|
1ac1bcb558 | ||
|
c14eb85faf | ||
|
2bc5e10d4d | ||
|
4f928a3efc | ||
|
aac4cbf0db | ||
|
4042d3876f | ||
|
68f9da66f0 | ||
|
073bd0b6f6 | ||
|
14eb503e62 | ||
|
a9e37f3cb5 | ||
|
ff615959b6 | ||
|
5c4b90e3f8 | ||
|
66b3ffb0f7 | ||
|
037d157977 | ||
|
e34308df6c | ||
|
ad838db71f | ||
|
7f1c0e0111 | ||
|
54f2361d27 | ||
|
101b6c13a0 | ||
|
ac4f0895a6 | ||
|
0711330570 | ||
|
62063532be | ||
|
1a29114d7b | ||
|
e23436526e | ||
|
bf3218eb12 | ||
|
7269cb396a | ||
|
460751d7c3 | ||
|
9cdc72374b | ||
|
19689edd76 | ||
|
53c00dce2b | ||
|
140e959df8 | ||
|
00e4d7e856 | ||
|
37e21b5b6b | ||
|
19dbe22d4f | ||
|
733f9fc153 | ||
|
749cc36d5d | ||
|
f09a8d0277 | ||
|
82ccbba7dc | ||
|
ff832e4e77 | ||
|
3f84fa4ae1 | ||
|
c28aa7215e | ||
|
caaa95b651 | ||
|
d86da2b0b7 | ||
|
445db7826b | ||
|
4a2dc47c39 | ||
|
0d77a6681b | ||
|
a3d2df0501 | ||
|
7d63f7f134 | ||
|
5fdc019220 | ||
|
177ffc3a2a | ||
|
b5d54bf446 |
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 120
|
||||||
|
tab_width = 4
|
||||||
|
trim_trailing_whitespace = true
|
25
.eslintrc.js
Normal file
25
.eslintrc.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
commonjs: true,
|
||||||
|
es6: true,
|
||||||
|
node: true
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'airbnb-base'
|
||||||
|
],
|
||||||
|
globals: {
|
||||||
|
Atomics: 'readonly',
|
||||||
|
SharedArrayBuffer: 'readonly'
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2018,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
"comma-dangle": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
|
"no-console": "off",
|
||||||
|
"object-curly-newline": "off"
|
||||||
|
}
|
||||||
|
};
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -17,3 +17,5 @@ node_modules/
|
|||||||
.env
|
.env
|
||||||
.env.test
|
.env.test
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea
|
||||||
|
59
README.md
59
README.md
@@ -1,5 +1,9 @@
|
|||||||
# ssh deployments
|
# ssh deployments
|
||||||
|
|
||||||
|
Deploy code with rsync over ssh, using NodeJS.
|
||||||
|
|
||||||
|
NodeJS version is more than a minute `faster` than simple Docker version.
|
||||||
|
|
||||||
This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh, using NodeJS.
|
This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh, using NodeJS.
|
||||||
|
|
||||||
This action would usually follow a build/test action which leaves deployable code in `GITHUB_WORKSPACE`, eg `dist`;
|
This action would usually follow a build/test action which leaves deployable code in `GITHUB_WORKSPACE`, eg `dist`;
|
||||||
@@ -8,32 +12,62 @@ This action would usually follow a build/test action which leaves deployable cod
|
|||||||
|
|
||||||
Pass configuration with `env` vars
|
Pass configuration with `env` vars
|
||||||
|
|
||||||
1. `SSH_PRIVATE_KEY` [required]
|
##### 1. `SSH_PRIVATE_KEY` [required]
|
||||||
This should be the private key part of an ssh key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment.
|
|
||||||
|
|
||||||
2. `REMOTE_HOST` [required]
|
Private key part of an SSH key pair.
|
||||||
3. `REMOTE_USER` [required]
|
The public key part should be added to the `authorized_keys` file on the server that receives the deployment.
|
||||||
|
|
||||||
|
More info for SSH keys: https://www.ssh.com/ssh/public-key-authentication
|
||||||
|
|
||||||
|
The keys should be generated using the PEM format. You can use this command
|
||||||
|
|
||||||
|
```
|
||||||
|
ssh-keygen -m PEM -t rsa -b 4096
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 2. `REMOTE_HOST` [required]
|
||||||
|
|
||||||
|
eg: mydomain.com
|
||||||
|
|
||||||
|
##### 3. `REMOTE_USER` [required]
|
||||||
|
|
||||||
|
eg: myusername
|
||||||
|
|
||||||
|
##### 4. `REMOTE_PORT` (optional, default '22')
|
||||||
|
|
||||||
|
eg: '59184'
|
||||||
|
|
||||||
|
##### 5. `ARGS` (optional, default '-rltgoDzvO')
|
||||||
|
|
||||||
2. `ARGS` (optional)
|
|
||||||
For any initial/required rsync flags, eg: `-avzr --delete`
|
For any initial/required rsync flags, eg: `-avzr --delete`
|
||||||
|
|
||||||
3. `SOURCE` (optional, default '')
|
##### 6. `SOURCE` (optional, default '')
|
||||||
|
|
||||||
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist/`
|
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist/`
|
||||||
|
|
||||||
4. `TARGET` (optional, default '/home/REMOTE_USER/')
|
##### 7. `TARGET` (optional, default '/home/REMOTE_USER/')
|
||||||
|
|
||||||
The target directory
|
The target directory
|
||||||
|
|
||||||
|
##### 8. `EXCLUDE` (optional, default '')
|
||||||
|
|
||||||
|
path to exclude separated by `,`, ie: `/dist/, /node_modules/`
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
!!! Please use latest version, Readme file is just an example, eg: ssh-deploy@v2.1.5
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: Deploy to Staging server
|
- name: Deploy to Staging server
|
||||||
uses: easingthemes/ssh-deploy@v2.0.2
|
uses: easingthemes/ssh-deploy@v2.1.5
|
||||||
env:
|
env:
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
ARGS: "-rltgoDzvO --delete"
|
ARGS: "-rltgoDzvO"
|
||||||
SOURCE: "dist/"
|
SOURCE: "dist/"
|
||||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||||
|
EXCLUDE: "/dist/, /node_modules/"
|
||||||
```
|
```
|
||||||
|
|
||||||
# Example usage in workflow
|
# Example usage in workflow
|
||||||
@@ -59,7 +93,7 @@ jobs:
|
|||||||
- name: Run build task
|
- name: Run build task
|
||||||
run: npm run build --if-present
|
run: npm run build --if-present
|
||||||
- name: Deploy to Server
|
- name: Deploy to Server
|
||||||
uses: easingthemes/ssh-deploy@v2.0.2
|
uses: easingthemes/ssh-deploy@v2.1.5
|
||||||
env:
|
env:
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
ARGS: "-rltgoDzvO --delete"
|
ARGS: "-rltgoDzvO --delete"
|
||||||
@@ -67,10 +101,9 @@ jobs:
|
|||||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||||
|
EXCLUDE: "/dist/, /node_modules/"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
If you're using GitHub Actions, you'll probably already know that it's still in limited public beta, and GitHub advise against using Actions in production.
|
Check your keys. Check your deployment paths. And use at your own risk.
|
||||||
|
|
||||||
So, check your keys. Check your deployment paths. And use at your own risk.
|
|
||||||
|
45
action.yml
45
action.yml
@@ -1,27 +1,42 @@
|
|||||||
name: 'ssh deploy'
|
name: "ssh deploy"
|
||||||
description: 'For deploying code over ssh'
|
description: "NodeJS action for FAST deployment with rsync/ssh"
|
||||||
|
author: "easingthemes"
|
||||||
inputs:
|
inputs:
|
||||||
SSH_PRIVATE_KEY: # Private Key
|
SSH_PRIVATE_KEY: # Private Key
|
||||||
description: 'Private Key'
|
description: "Private Key"
|
||||||
required: true
|
required: true
|
||||||
REMOTE_HOST:
|
REMOTE_HOST:
|
||||||
description: 'Remote host'
|
description: "Remote host"
|
||||||
required: true
|
required: true
|
||||||
REMOTE_USER:
|
REMOTE_USER:
|
||||||
description: 'Remote user'
|
description: "Remote user"
|
||||||
required: true
|
required: true
|
||||||
|
REMOTE_PORT:
|
||||||
|
description: "Remote port"
|
||||||
|
required: false
|
||||||
|
default: "22"
|
||||||
SOURCE:
|
SOURCE:
|
||||||
description: 'Source directory'
|
description: "Source directory"
|
||||||
default: ''
|
required: false
|
||||||
|
default: ""
|
||||||
TARGET:
|
TARGET:
|
||||||
description: 'Target directory'
|
description: "Target directory"
|
||||||
default: '/home/REMOTE_USER/'
|
required: false
|
||||||
|
default: "/home/REMOTE_USER/"
|
||||||
|
ARGS:
|
||||||
|
description: "Arguments to pass to rsync"
|
||||||
|
required: false
|
||||||
|
default: "-rltgoDzvO"
|
||||||
|
EXCLUDE:
|
||||||
|
description: "An array of folder to exclude"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
outputs:
|
outputs:
|
||||||
status:
|
status:
|
||||||
description: 'Status'
|
description: "Status"
|
||||||
runs:
|
runs:
|
||||||
using: 'node10'
|
using: "node12"
|
||||||
main: 'dist/index.js'
|
main: "dist/index.js"
|
||||||
branding:
|
branding:
|
||||||
color: 'green'
|
color: "green"
|
||||||
icon: 'truck'
|
icon: "truck"
|
||||||
|
364
dist/index.js
vendored
364
dist/index.js
vendored
@@ -49,6 +49,51 @@ module.exports =
|
|||||||
|
|
||||||
module.exports = require("child_process");
|
module.exports = require("child_process");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 197:
|
||||||
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
|
const { existsSync, mkdirSync, writeFileSync } = __webpack_require__(747);
|
||||||
|
|
||||||
|
const {
|
||||||
|
GITHUB_WORKSPACE
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
|
const validateDir = (dir) => {
|
||||||
|
if (!existsSync(dir)) {
|
||||||
|
console.log(`[SSH] Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
||||||
|
mkdirSync(dir);
|
||||||
|
console.log('✅ [SSH] dir created.');
|
||||||
|
} else {
|
||||||
|
console.log(`[SSH] ${dir} dir exist`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateFile = (filePath) => {
|
||||||
|
if (!existsSync(filePath)) {
|
||||||
|
console.log(`[SSH] Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
||||||
|
try {
|
||||||
|
writeFileSync(filePath, '', {
|
||||||
|
encoding: 'utf8',
|
||||||
|
mode: 0o600
|
||||||
|
});
|
||||||
|
console.log('✅ [SSH] file created.');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('⚠️ [SSH] writeFileSync error', filePath, e.message);
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`[SSH] ${filePath} file exist`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validateDir,
|
||||||
|
validateFile
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 243:
|
/***/ 243:
|
||||||
@@ -455,6 +500,50 @@ function getString(command,callback){
|
|||||||
module.exports=commandline;
|
module.exports=commandline;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 613:
|
||||||
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
|
const { writeFileSync } = __webpack_require__(747);
|
||||||
|
const { join } = __webpack_require__(622);
|
||||||
|
|
||||||
|
const {
|
||||||
|
validateDir,
|
||||||
|
validateFile
|
||||||
|
} = __webpack_require__(197);
|
||||||
|
|
||||||
|
const {
|
||||||
|
HOME
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
|
const addSshKey = (key, name) => {
|
||||||
|
const sshDir = join(HOME || __dirname, '.ssh');
|
||||||
|
const filePath = join(sshDir, name);
|
||||||
|
|
||||||
|
validateDir(sshDir);
|
||||||
|
validateFile(`${sshDir}/known_hosts`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
writeFileSync(filePath, key, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
mode: 0o600
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('⚠️ writeFileSync error', filePath, e.message);
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
addSshKey
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 622:
|
/***/ 622:
|
||||||
@@ -462,6 +551,24 @@ module.exports=commandline;
|
|||||||
|
|
||||||
module.exports = require("path");
|
module.exports = require("path");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 659:
|
||||||
|
/***/ (function(module) {
|
||||||
|
|
||||||
|
const inputNames = ['REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME', 'SOURCE', 'TARGET', 'ARGS', 'EXCLUDE'];
|
||||||
|
|
||||||
|
const inputs = {
|
||||||
|
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE
|
||||||
|
};
|
||||||
|
// Get inputs from ENV or WITH workflow settings
|
||||||
|
inputNames.forEach((input) => {
|
||||||
|
inputs[input] = process.env[input] || process.env[`INPUT_${input}`];
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = inputs;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 669:
|
/***/ 669:
|
||||||
@@ -474,158 +581,84 @@ module.exports = require("util");
|
|||||||
/***/ 676:
|
/***/ 676:
|
||||||
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
|
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
const fs = __webpack_require__(747);
|
|
||||||
const path = __webpack_require__(622);
|
|
||||||
const commandExists = __webpack_require__(677);
|
|
||||||
const nodeCmd = __webpack_require__(428);
|
|
||||||
const nodeRsync = __webpack_require__(250);
|
const nodeRsync = __webpack_require__(250);
|
||||||
|
|
||||||
const { REMOTE_HOST, REMOTE_USER, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env;
|
const { validateRsync, validateInputs } = __webpack_require__(735);
|
||||||
console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE);
|
const { addSshKey } = __webpack_require__(613);
|
||||||
|
|
||||||
const sshDeploy = (() => {
|
const {
|
||||||
const rsync = ({ privateKey, src, dest, args }) => {
|
REMOTE_HOST, REMOTE_USER,
|
||||||
console.log(`Starting Rsync Action: ${src} to ${dest}`);
|
REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME,
|
||||||
|
SOURCE, TARGET, ARGS, EXCLUDE,
|
||||||
|
GITHUB_WORKSPACE
|
||||||
|
} = __webpack_require__(659);
|
||||||
|
|
||||||
try {
|
const defaultOptions = {
|
||||||
// RSYNC COMMAND
|
ssh: true,
|
||||||
nodeRsync({ src, dest, args, privateKey, ssh: true, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => {
|
sshCmdArgs: ['-o StrictHostKeyChecking=no'],
|
||||||
if (error) {
|
recursive: true
|
||||||
console.error('⚠️ Rsync error', error.message);
|
|
||||||
process.abort();
|
|
||||||
} else {
|
|
||||||
console.log("✅ Rsync finished.", stdout);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`⚠️ An error happened:(.`, err.message, err.stack);
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const init = ({
|
|
||||||
src,
|
|
||||||
dest,
|
|
||||||
args,
|
|
||||||
host = 'localhost',
|
|
||||||
username,
|
|
||||||
privateKeyContent
|
|
||||||
}) => {
|
|
||||||
validateRsync(() => {
|
|
||||||
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key');
|
|
||||||
|
|
||||||
const remoteDest = username + '@' + host + ':' + dest;
|
|
||||||
|
|
||||||
rsync({ privateKey, src, dest: remoteDest, args });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateDir = (dir) => {
|
|
||||||
if (!fs.existsSync(dir)){
|
|
||||||
console.log(`Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
|
||||||
fs.mkdirSync(dir);
|
|
||||||
} else {
|
|
||||||
console.log(`${dir} dir exist`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateFile = (filePath) => {
|
|
||||||
if (!fs.existsSync(filePath)){
|
|
||||||
console.log(`Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(filePath, '', {
|
|
||||||
encoding: 'utf8',
|
|
||||||
mode: 0o600
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(`${filePath} file exist`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const addSshKey = (key, name) => {
|
|
||||||
const sshDir = path.join(HOME || __dirname, '.ssh');
|
|
||||||
const filePath = path.join(sshDir, name);
|
|
||||||
|
|
||||||
validateDir(sshDir);
|
|
||||||
validateFile(sshDir + '/known_hosts');
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(filePath, key, {
|
|
||||||
encoding: 'utf8',
|
|
||||||
mode: 0o600
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
|
||||||
|
|
||||||
return filePath;
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateRsync = (callback = () => {}) => {
|
|
||||||
const rsyncCli = commandExists.sync('rsync');
|
|
||||||
|
|
||||||
if (!rsyncCli) {
|
|
||||||
nodeCmd.get(
|
|
||||||
'sudo apt-get --no-install-recommends install rsync',
|
|
||||||
function(err, data, stderr){
|
|
||||||
if (err) {
|
|
||||||
console.log('⚠️ Rsync installation failed ', err.message);
|
|
||||||
process.abort();
|
|
||||||
} else {
|
|
||||||
console.log('✅ Rsync installed. \n', data, stderr);
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
init
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
const validateInputs = (inputs) => {
|
|
||||||
const validInputs = inputs.filter(input => {
|
|
||||||
if (!input) {
|
|
||||||
console.error(`⚠️ ${input} is mandatory`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return input;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (validInputs.length !== inputs.length) {
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const run = () => {
|
console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE);
|
||||||
validateInputs([SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER]);
|
|
||||||
|
|
||||||
sshDeploy.init({
|
const sshDeploy = (() => {
|
||||||
src: GITHUB_WORKSPACE + '/' + SOURCE || '',
|
const rsync = ({ privateKey, port, src, dest, args, exclude }) => {
|
||||||
dest: TARGET || '/home/' + REMOTE_USER + '/',
|
console.log(`[Rsync] Starting Rsync Action: ${src} to ${dest}`);
|
||||||
args: [ARGS] || false,
|
if (exclude) console.log(`[Rsync] exluding folders ${exclude}`);
|
||||||
host: REMOTE_HOST,
|
|
||||||
username: REMOTE_USER,
|
try {
|
||||||
privateKeyContent: SSH_PRIVATE_KEY,
|
// RSYNC COMMAND
|
||||||
|
nodeRsync({
|
||||||
|
src, dest, args, privateKey, port, exclude, ...defaultOptions
|
||||||
|
}, (error, stdout, stderr, cmd) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('⚠️ [Rsync] error: ', error.message);
|
||||||
|
console.log('⚠️ [Rsync] stderr: ', stderr);
|
||||||
|
console.log('⚠️ [Rsync] stdout: ', stdout);
|
||||||
|
console.log('⚠️ [Rsync] cmd: ', cmd);
|
||||||
|
process.abort();
|
||||||
|
} else {
|
||||||
|
console.log('✅ [Rsync] finished.', stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('⚠️ [Rsync] command error: ', err.message, err.stack);
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = ({ src, dest, args, host = 'localhost', port, username, privateKeyContent, exclude = [] }) => {
|
||||||
|
validateRsync(() => {
|
||||||
|
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME || 'deploy_key');
|
||||||
|
const remoteDest = `${username}@${host}:${dest}`;
|
||||||
|
|
||||||
|
rsync({ privateKey, port, src, dest: remoteDest, args, exclude });
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
init
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
const run = () => {
|
||||||
|
validateInputs({ SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER });
|
||||||
|
|
||||||
|
sshDeploy.init({
|
||||||
|
src: `${GITHUB_WORKSPACE}/${SOURCE || ''}`,
|
||||||
|
dest: TARGET || `/home/${REMOTE_USER}/`,
|
||||||
|
args: ARGS ? [ARGS] : ['-rltgoDzvO'],
|
||||||
|
host: REMOTE_HOST,
|
||||||
|
port: REMOTE_PORT || '22',
|
||||||
|
username: REMOTE_USER,
|
||||||
|
privateKeyContent: SSH_PRIVATE_KEY,
|
||||||
|
exclude: (EXCLUDE || '').split(',').map((item) => item.trim()) // split by comma and trim whitespace
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 677:
|
/***/ 677:
|
||||||
@@ -634,6 +667,59 @@ run();
|
|||||||
module.exports = __webpack_require__(243);
|
module.exports = __webpack_require__(243);
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 735:
|
||||||
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
|
const { sync: commandExists } = __webpack_require__(677);
|
||||||
|
const { get: nodeCmd } = __webpack_require__(428);
|
||||||
|
|
||||||
|
const validateRsync = (callback = () => {}) => {
|
||||||
|
const rsyncCli = commandExists('rsync');
|
||||||
|
|
||||||
|
if (!rsyncCli) {
|
||||||
|
nodeCmd(
|
||||||
|
'sudo apt-get --no-install-recommends install rsync',
|
||||||
|
(err, data, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message);
|
||||||
|
process.abort();
|
||||||
|
} else {
|
||||||
|
console.log('✅ [CLI] Rsync installed. \n', data, stderr);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateInputs = (inputs) => {
|
||||||
|
const inputKeys = Object.keys(inputs);
|
||||||
|
const validInputs = inputKeys.filter((inputKey) => {
|
||||||
|
const inputValue = inputs[inputKey];
|
||||||
|
|
||||||
|
if (!inputValue) {
|
||||||
|
console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validInputs.length !== inputKeys.length) {
|
||||||
|
console.error('⚠️ [INPUTS] Inputs not valid, aborting ...');
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validateRsync,
|
||||||
|
validateInputs
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 747:
|
/***/ 747:
|
||||||
|
3722
package-lock.json
generated
3722
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ssh-deploy",
|
"name": "ssh-deploy",
|
||||||
"version": "2.0.2",
|
"version": "2.1.5",
|
||||||
"description": "This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh.",
|
"description": "This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh.",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -9,10 +9,15 @@
|
|||||||
"rsyncwrapper": "3.0.1"
|
"rsyncwrapper": "3.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@zeit/ncc": "^0.20.5"
|
"@zeit/ncc": "^0.20.5",
|
||||||
|
"eslint": "^6.8.0",
|
||||||
|
"eslint-config-airbnb-base": "^14.1.0",
|
||||||
|
"eslint-plugin-import": "^2.20.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build ./src/index.js -o dist"
|
"build": "npm run lint && ncc build ./src/index.js -o dist",
|
||||||
|
"lint": "eslint ./src/index.js",
|
||||||
|
"lint:fix": "eslint ./src/index.js --fix"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
38
src/helpers.js
Normal file
38
src/helpers.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const { existsSync, mkdirSync, writeFileSync } = require('fs');
|
||||||
|
|
||||||
|
const {
|
||||||
|
GITHUB_WORKSPACE
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
|
const validateDir = (dir) => {
|
||||||
|
if (!existsSync(dir)) {
|
||||||
|
console.log(`[SSH] Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
||||||
|
mkdirSync(dir);
|
||||||
|
console.log('✅ [SSH] dir created.');
|
||||||
|
} else {
|
||||||
|
console.log(`[SSH] ${dir} dir exist`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateFile = (filePath) => {
|
||||||
|
if (!existsSync(filePath)) {
|
||||||
|
console.log(`[SSH] Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
||||||
|
try {
|
||||||
|
writeFileSync(filePath, '', {
|
||||||
|
encoding: 'utf8',
|
||||||
|
mode: 0o600
|
||||||
|
});
|
||||||
|
console.log('✅ [SSH] file created.');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('⚠️ [SSH] writeFileSync error', filePath, e.message);
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`[SSH] ${filePath} file exist`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validateDir,
|
||||||
|
validateFile
|
||||||
|
};
|
204
src/index.js
204
src/index.js
@@ -1,151 +1,77 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const commandExists = require('command-exists');
|
|
||||||
const nodeCmd = require('node-cmd');
|
|
||||||
const nodeRsync = require('rsyncwrapper');
|
const nodeRsync = require('rsyncwrapper');
|
||||||
|
|
||||||
const { REMOTE_HOST, REMOTE_USER, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env;
|
const { validateRsync, validateInputs } = require('./rsyncCli');
|
||||||
console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE);
|
const { addSshKey } = require('./sshKey');
|
||||||
|
|
||||||
const sshDeploy = (() => {
|
const {
|
||||||
const rsync = ({ privateKey, src, dest, args }) => {
|
REMOTE_HOST, REMOTE_USER,
|
||||||
console.log(`Starting Rsync Action: ${src} to ${dest}`);
|
REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME,
|
||||||
|
SOURCE, TARGET, ARGS, EXCLUDE,
|
||||||
|
GITHUB_WORKSPACE
|
||||||
|
} = require('./inputs');
|
||||||
|
|
||||||
try {
|
const defaultOptions = {
|
||||||
// RSYNC COMMAND
|
ssh: true,
|
||||||
nodeRsync({ src, dest, args, privateKey, ssh: true, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => {
|
sshCmdArgs: ['-o StrictHostKeyChecking=no'],
|
||||||
if (error) {
|
recursive: true
|
||||||
console.error('⚠️ Rsync error', error.message);
|
|
||||||
process.abort();
|
|
||||||
} else {
|
|
||||||
console.log("✅ Rsync finished.", stdout);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`⚠️ An error happened:(.`, err.message, err.stack);
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const init = ({
|
|
||||||
src,
|
|
||||||
dest,
|
|
||||||
args,
|
|
||||||
host = 'localhost',
|
|
||||||
username,
|
|
||||||
privateKeyContent
|
|
||||||
}) => {
|
|
||||||
validateRsync(() => {
|
|
||||||
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key');
|
|
||||||
|
|
||||||
const remoteDest = username + '@' + host + ':' + dest;
|
|
||||||
|
|
||||||
rsync({ privateKey, src, dest: remoteDest, args });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateDir = (dir) => {
|
|
||||||
if (!fs.existsSync(dir)){
|
|
||||||
console.log(`Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
|
||||||
fs.mkdirSync(dir);
|
|
||||||
} else {
|
|
||||||
console.log(`${dir} dir exist`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateFile = (filePath) => {
|
|
||||||
if (!fs.existsSync(filePath)){
|
|
||||||
console.log(`Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(filePath, '', {
|
|
||||||
encoding: 'utf8',
|
|
||||||
mode: 0o600
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(`${filePath} file exist`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const addSshKey = (key, name) => {
|
|
||||||
const sshDir = path.join(HOME || __dirname, '.ssh');
|
|
||||||
const filePath = path.join(sshDir, name);
|
|
||||||
|
|
||||||
validateDir(sshDir);
|
|
||||||
validateFile(sshDir + '/known_hosts');
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(filePath, key, {
|
|
||||||
encoding: 'utf8',
|
|
||||||
mode: 0o600
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
|
||||||
|
|
||||||
return filePath;
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateRsync = (callback = () => {}) => {
|
|
||||||
const rsyncCli = commandExists.sync('rsync');
|
|
||||||
|
|
||||||
if (!rsyncCli) {
|
|
||||||
nodeCmd.get(
|
|
||||||
'sudo apt-get --no-install-recommends install rsync',
|
|
||||||
function(err, data, stderr){
|
|
||||||
if (err) {
|
|
||||||
console.log('⚠️ Rsync installation failed ', err.message);
|
|
||||||
process.abort();
|
|
||||||
} else {
|
|
||||||
console.log('✅ Rsync installed. \n', data, stderr);
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
init
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
const validateInputs = (inputs) => {
|
|
||||||
const validInputs = inputs.filter(input => {
|
|
||||||
if (!input) {
|
|
||||||
console.error(`⚠️ ${input} is mandatory`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return input;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (validInputs.length !== inputs.length) {
|
|
||||||
process.abort();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const run = () => {
|
console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE);
|
||||||
validateInputs([SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER]);
|
|
||||||
|
|
||||||
sshDeploy.init({
|
const sshDeploy = (() => {
|
||||||
src: GITHUB_WORKSPACE + '/' + SOURCE || '',
|
const rsync = ({ privateKey, port, src, dest, args, exclude }) => {
|
||||||
dest: TARGET || '/home/' + REMOTE_USER + '/',
|
console.log(`[Rsync] Starting Rsync Action: ${src} to ${dest}`);
|
||||||
args: [ARGS] || ['-rltgoDzvO'],
|
if (exclude) console.log(`[Rsync] exluding folders ${exclude}`);
|
||||||
host: REMOTE_HOST,
|
|
||||||
username: REMOTE_USER,
|
try {
|
||||||
privateKeyContent: SSH_PRIVATE_KEY,
|
// RSYNC COMMAND
|
||||||
|
nodeRsync({
|
||||||
|
src, dest, args, privateKey, port, exclude, ...defaultOptions
|
||||||
|
}, (error, stdout, stderr, cmd) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('⚠️ [Rsync] error: ', error.message);
|
||||||
|
console.log('⚠️ [Rsync] stderr: ', stderr);
|
||||||
|
console.log('⚠️ [Rsync] stdout: ', stdout);
|
||||||
|
console.log('⚠️ [Rsync] cmd: ', cmd);
|
||||||
|
process.abort();
|
||||||
|
} else {
|
||||||
|
console.log('✅ [Rsync] finished.', stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('⚠️ [Rsync] command error: ', err.message, err.stack);
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = ({ src, dest, args, host = 'localhost', port, username, privateKeyContent, exclude = [] }) => {
|
||||||
|
validateRsync(() => {
|
||||||
|
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME || 'deploy_key');
|
||||||
|
const remoteDest = `${username}@${host}:${dest}`;
|
||||||
|
|
||||||
|
rsync({ privateKey, port, src, dest: remoteDest, args, exclude });
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
init
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
const run = () => {
|
||||||
|
validateInputs({ SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER });
|
||||||
|
|
||||||
|
sshDeploy.init({
|
||||||
|
src: `${GITHUB_WORKSPACE}/${SOURCE || ''}`,
|
||||||
|
dest: TARGET || `/home/${REMOTE_USER}/`,
|
||||||
|
args: ARGS ? [ARGS] : ['-rltgoDzvO'],
|
||||||
|
host: REMOTE_HOST,
|
||||||
|
port: REMOTE_PORT || '22',
|
||||||
|
username: REMOTE_USER,
|
||||||
|
privateKeyContent: SSH_PRIVATE_KEY,
|
||||||
|
exclude: (EXCLUDE || '').split(',').map((item) => item.trim()) // split by comma and trim whitespace
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
||||||
|
11
src/inputs.js
Normal file
11
src/inputs.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const inputNames = ['REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME', 'SOURCE', 'TARGET', 'ARGS', 'EXCLUDE'];
|
||||||
|
|
||||||
|
const inputs = {
|
||||||
|
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE
|
||||||
|
};
|
||||||
|
// Get inputs from ENV or WITH workflow settings
|
||||||
|
inputNames.forEach((input) => {
|
||||||
|
inputs[input] = process.env[input] || process.env[`INPUT_${input}`];
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = inputs;
|
46
src/rsyncCli.js
Normal file
46
src/rsyncCli.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
const { sync: commandExists } = require('command-exists');
|
||||||
|
const { get: nodeCmd } = require('node-cmd');
|
||||||
|
|
||||||
|
const validateRsync = (callback = () => {}) => {
|
||||||
|
const rsyncCli = commandExists('rsync');
|
||||||
|
|
||||||
|
if (!rsyncCli) {
|
||||||
|
nodeCmd(
|
||||||
|
'sudo apt-get --no-install-recommends install rsync',
|
||||||
|
(err, data, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message);
|
||||||
|
process.abort();
|
||||||
|
} else {
|
||||||
|
console.log('✅ [CLI] Rsync installed. \n', data, stderr);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateInputs = (inputs) => {
|
||||||
|
const inputKeys = Object.keys(inputs);
|
||||||
|
const validInputs = inputKeys.filter((inputKey) => {
|
||||||
|
const inputValue = inputs[inputKey];
|
||||||
|
|
||||||
|
if (!inputValue) {
|
||||||
|
console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validInputs.length !== inputKeys.length) {
|
||||||
|
console.error('⚠️ [INPUTS] Inputs not valid, aborting ...');
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validateRsync,
|
||||||
|
validateInputs
|
||||||
|
};
|
37
src/sshKey.js
Normal file
37
src/sshKey.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
const { writeFileSync } = require('fs');
|
||||||
|
const { join } = require('path');
|
||||||
|
|
||||||
|
const {
|
||||||
|
validateDir,
|
||||||
|
validateFile
|
||||||
|
} = require('./helpers');
|
||||||
|
|
||||||
|
const {
|
||||||
|
HOME
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
|
const addSshKey = (key, name) => {
|
||||||
|
const sshDir = join(HOME || __dirname, '.ssh');
|
||||||
|
const filePath = join(sshDir, name);
|
||||||
|
|
||||||
|
validateDir(sshDir);
|
||||||
|
validateFile(`${sshDir}/known_hosts`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
writeFileSync(filePath, key, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
mode: 0o600
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('⚠️ writeFileSync error', filePath, e.message);
|
||||||
|
process.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
addSshKey
|
||||||
|
}
|
Reference in New Issue
Block a user