mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-19 08:08:05 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ad912febba | ||
|
f53f7cb352 | ||
|
4180a30117 | ||
|
2520d9e7f7 |
2
.github/workflows/e2e-manual.yml
vendored
2
.github/workflows/e2e-manual.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
ARGS:
|
ARGS:
|
||||||
description: 'ARGS'
|
description: 'ARGS'
|
||||||
required: true
|
required: true
|
||||||
default: '-rlgoDzvc -i --delete --chmod=ugo+rwX --progress'
|
default: '-rltgoDzvO --delete --chmod=ugo+rwX --progress'
|
||||||
EXCLUDE:
|
EXCLUDE:
|
||||||
description: 'EXCLUDE'
|
description: 'EXCLUDE'
|
||||||
required: true
|
required: true
|
||||||
|
81
.github/workflows/e2e.yml
vendored
81
.github/workflows/e2e.yml
vendored
@@ -74,7 +74,7 @@ jobs:
|
|||||||
|
|
||||||
- name: set shared ENV variables for multi target deployment
|
- name: set shared ENV variables for multi target deployment
|
||||||
run: |
|
run: |
|
||||||
echo "ARGS=-rlgoDzvcR -i --delete --chmod=ugo+rwX --progress" >> $GITHUB_ENV
|
echo "ARGS=-rltgoDzvOR --delete --chmod=ugo+rwX --progress" >> $GITHUB_ENV
|
||||||
echo "SSH_CMD_ARGS=-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null" >> $GITHUB_ENV
|
echo "SSH_CMD_ARGS=-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null" >> $GITHUB_ENV
|
||||||
echo "SOURCE=test_project/ test_project2/" >> $GITHUB_ENV
|
echo "SOURCE=test_project/ test_project2/" >> $GITHUB_ENV
|
||||||
echo "EXCLUDE=skip_dir/, /node_modules/" >> $GITHUB_ENV
|
echo "EXCLUDE=skip_dir/, /node_modules/" >> $GITHUB_ENV
|
||||||
@@ -95,85 +95,8 @@ jobs:
|
|||||||
TARGET: /var/www/html/${{ env.TEST_USER }}
|
TARGET: /var/www/html/${{ env.TEST_USER }}
|
||||||
|
|
||||||
- name: e2e Test ssh-deploy action - Target 2
|
- name: e2e Test ssh-deploy action - Target 2
|
||||||
uses: easingthemes/ssh-deploy@main
|
uses: easingthemes/ssh-deploy@feature/main
|
||||||
env:
|
env:
|
||||||
# Shared ENV Vars created in previous steps
|
# Shared ENV Vars created in previous steps
|
||||||
REMOTE_USER: ${{ env.TEST_USER2 }}
|
REMOTE_USER: ${{ env.TEST_USER2 }}
|
||||||
TARGET: /var/www/html/${{ env.TEST_USER2 }}
|
TARGET: /var/www/html/${{ env.TEST_USER2 }}
|
||||||
|
|
||||||
- name: e2e Test ssh-deploy action - Default values
|
|
||||||
uses: easingthemes/ssh-deploy@main
|
|
||||||
env:
|
|
||||||
# Shared ENV Vars created in previous steps
|
|
||||||
REMOTE_USER: ${{ env.TEST_USER }}
|
|
||||||
e2e-v3:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
# : ---------------------------------------------------------------
|
|
||||||
# : START E2E Test Specific - steps
|
|
||||||
# : ----------------------------------------------------------------
|
|
||||||
|
|
||||||
- name: E2E Test Specific - Clean up old test files
|
|
||||||
run: |
|
|
||||||
docker stop ssh-host-container || true && docker rm ssh-host-container || true
|
|
||||||
|
|
||||||
- name: E2E Test Specific - Create ssh keys
|
|
||||||
run: |
|
|
||||||
echo $HOME
|
|
||||||
ls -la $HOME
|
|
||||||
ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N ""
|
|
||||||
eval `ssh-agent -s`
|
|
||||||
ssh-add "$HOME/.ssh/id_rsa"
|
|
||||||
ssh-add -l
|
|
||||||
echo "SSH_PRIVATE_KEY<<EOF" >> $GITHUB_ENV
|
|
||||||
cat $HOME/.ssh/id_rsa >> $GITHUB_ENV
|
|
||||||
echo "EOF" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: E2E Test Specific - Build Host Server Image
|
|
||||||
working-directory: ${{ env.TEST_HOST_DOCKER }}
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
-t ssh-host-image . \
|
|
||||||
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)"
|
|
||||||
docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image
|
|
||||||
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
|
|
||||||
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
|
|
||||||
cat ip.txt >> $GITHUB_ENV
|
|
||||||
echo "EOF" >> $GITHUB_ENV
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: E2E Test Specific - Create project file
|
|
||||||
run: |
|
|
||||||
mkdir test_project2 && cd "$_"
|
|
||||||
truncate -s 5MB info2.txt
|
|
||||||
cd ../
|
|
||||||
mkdir test_project && cd "$_"
|
|
||||||
touch index.html
|
|
||||||
date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html
|
|
||||||
truncate -s 50MB image.svg
|
|
||||||
truncate -s 5MB info.txt
|
|
||||||
truncate -s 500MB big_file.txt
|
|
||||||
mkdir skip_dir && cd "$_"
|
|
||||||
truncate -s 5MB text_in_skip_dir.txt
|
|
||||||
cd ../
|
|
||||||
cat index.html
|
|
||||||
echo "test_project:" && ls -lR
|
|
||||||
echo "skip_dir:" && ls -lR skip_dir
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
# END E2E Test Specific - steps
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
|
|
||||||
- name: e2e Test ssh-deploy action - Target 1
|
|
||||||
uses: easingthemes/ssh-deploy@v3
|
|
||||||
env:
|
|
||||||
# Shared ENV Vars created in previous steps
|
|
||||||
REMOTE_USER: ${{ env.TEST_USER }}
|
|
||||||
TARGET: /var/www/html/${{ env.TEST_USER }}
|
|
||||||
SOURCE: test_project/
|
|
||||||
EXCLUDE: skip_dir/, /node_modules/
|
|
||||||
ARGS: -rlgoDzvcO
|
|
||||||
|
9
.github/workflows/manual-release.yml
vendored
9
.github/workflows/manual-release.yml
vendored
@@ -6,10 +6,11 @@ on:
|
|||||||
description: 'Version'
|
description: 'Version'
|
||||||
type: choice
|
type: choice
|
||||||
required: true
|
required: true
|
||||||
default: fix
|
default: patch
|
||||||
options:
|
options:
|
||||||
- fix
|
- patch
|
||||||
- feat
|
- minor
|
||||||
|
- major
|
||||||
dryRun:
|
dryRun:
|
||||||
description: 'DryRun'
|
description: 'DryRun'
|
||||||
type: boolean
|
type: boolean
|
||||||
@@ -63,7 +64,7 @@ jobs:
|
|||||||
run: npm run build --if-present
|
run: npm run build --if-present
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: npm test --if-present
|
run: npm test --if-present
|
||||||
- name: Create a release - ${{ github.event.inputs.version }}
|
- name: Publish npm package
|
||||||
uses: cycjimmy/semantic-release-action@v3
|
uses: cycjimmy/semantic-release-action@v3
|
||||||
with:
|
with:
|
||||||
dry_run: ${{ github.event.inputs.dryRun == 'true' }}
|
dry_run: ${{ github.event.inputs.dryRun == 'true' }}
|
||||||
|
@@ -41,7 +41,7 @@ eg: myusername
|
|||||||
|
|
||||||
eg: '59184'
|
eg: '59184'
|
||||||
|
|
||||||
##### 5. `ARGS` (optional, default '-rlgoDzvc -i')
|
##### 5. `ARGS` (optional, default '-rltgoDzvO')
|
||||||
|
|
||||||
For any initial/required rsync flags, eg: `-avzr --delete`
|
For any initial/required rsync flags, eg: `-avzr --delete`
|
||||||
|
|
||||||
@@ -62,8 +62,6 @@ path to exclude separated by `,`, ie: `/dist/, /node_modules/`
|
|||||||
|
|
||||||
Script to run on host machine before rsync. Single line or multiline commands.
|
Script to run on host machine before rsync. Single line or multiline commands.
|
||||||
Execution is preformed by storing commands in `.sh` file and executing it via `.bash` over `ssh`
|
Execution is preformed by storing commands in `.sh` file and executing it via `.bash` over `ssh`
|
||||||
If you have issues with `ssh` connection, use this var, eg `SCRIPT_BEFORE: ls`.
|
|
||||||
This will force `known_hosts` update, adding your host via `ssh-keyscan`.
|
|
||||||
|
|
||||||
##### 10. `SCRIPT_AFTER` (optional, default '')
|
##### 10. `SCRIPT_AFTER` (optional, default '')
|
||||||
|
|
||||||
@@ -85,7 +83,7 @@ or use the latest version from a branch, eg: ssh-deploy@main
|
|||||||
uses: easingthemes/ssh-deploy@main
|
uses: easingthemes/ssh-deploy@main
|
||||||
env:
|
env:
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
ARGS: "-rlgoDzvc -i"
|
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 }}
|
||||||
@@ -126,7 +124,7 @@ jobs:
|
|||||||
uses: easingthemes/ssh-deploy@main
|
uses: easingthemes/ssh-deploy@main
|
||||||
env:
|
env:
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
ARGS: "-rlgoDzvc -i --delete"
|
ARGS: "-rltgoDzvO --delete"
|
||||||
SOURCE: "dist/"
|
SOURCE: "dist/"
|
||||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||||
@@ -158,7 +156,6 @@ For complex use cases, use `ARGS` and `SSH_CMD_ARGS` to fully configure `rsync`
|
|||||||
- If you need to use multiple steps, eg multi targets deployment, save shared ENV variables in `>> $GITHUB_ENV`.
|
- If you need to use multiple steps, eg multi targets deployment, save shared ENV variables in `>> $GITHUB_ENV`.
|
||||||
Check .github/workflows/e2e.yml for an example
|
Check .github/workflows/e2e.yml for an example
|
||||||
- For multi sources, use -R ARG to manipulate folders structure.
|
- For multi sources, use -R ARG to manipulate folders structure.
|
||||||
- Great post about `rsync` options specific to usage of this action: https://logansnotes.com/2020/gh-action-site-deploy/
|
|
||||||
|
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
@@ -22,11 +22,11 @@ inputs:
|
|||||||
TARGET:
|
TARGET:
|
||||||
description: "Target directory"
|
description: "Target directory"
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: "/home/REMOTE_USER/"
|
||||||
ARGS:
|
ARGS:
|
||||||
description: "Arguments to pass to rsync"
|
description: "Arguments to pass to rsync"
|
||||||
required: false
|
required: false
|
||||||
default: "-rlgoDzvc -i"
|
default: "-rltgoDzvO"
|
||||||
SSH_CMD_ARGS:
|
SSH_CMD_ARGS:
|
||||||
description: "An array of ssh arguments, they must be prefixed with -o and separated by a comma, for example: -o SomeArgument=no, -o SomeOtherArgument=5 "
|
description: "An array of ssh arguments, they must be prefixed with -o and separated by a comma, for example: -o SomeArgument=no, -o SomeOtherArgument=5 "
|
||||||
required: false
|
required: false
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,91 +1,3 @@
|
|||||||
## [4.1.4](https://github.com/easingthemes/ssh-deploy/compare/v4.1.3...v4.1.4) (2023-02-21)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* [#113](https://github.com/easingthemes/ssh-deploy/issues/113) limit ssh script input ([5894f5e](https://github.com/easingthemes/ssh-deploy/commit/5894f5e29008feccaf42787330ec8f49f3ad50b0))
|
|
||||||
|
|
||||||
## [4.1.3](https://github.com/easingthemes/ssh-deploy/compare/v4.1.2...v4.1.3) (2023-02-21)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* [#113](https://github.com/easingthemes/ssh-deploy/issues/113) limit ssh script output - rebuild ([756a522](https://github.com/easingthemes/ssh-deploy/commit/756a522533d2206203b5d13b5aa11c88b3313784))
|
|
||||||
|
|
||||||
## [4.1.2](https://github.com/easingthemes/ssh-deploy/compare/v4.1.1...v4.1.2) (2023-02-21)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* [#113](https://github.com/easingthemes/ssh-deploy/issues/113) limit ssh script output ([59827af](https://github.com/easingthemes/ssh-deploy/commit/59827af83c934996efda72f9fbd1fcd0bb9ccaac))
|
|
||||||
|
|
||||||
## [4.1.1](https://github.com/easingthemes/ssh-deploy/compare/v4.1.0...v4.1.1) (2023-02-21)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* fix default TARGET ([4d08634](https://github.com/easingthemes/ssh-deploy/commit/4d086346af62ac5d57fa37ee6bb46f8de8ad48c3))
|
|
||||||
|
|
||||||
# [4.1.0](https://github.com/easingthemes/ssh-deploy/compare/v4.0.5...v4.1.0) (2023-02-19)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add ssh port from VARs, fix package-lock ([808b002](https://github.com/easingthemes/ssh-deploy/commit/808b0020d44b7c25ef1c13b3979ffdab4f503236))
|
|
||||||
|
|
||||||
## [4.0.5](https://github.com/easingthemes/ssh-deploy/compare/v4.0.4...v4.0.5) (2023-01-06)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* fix manual release action ([245b7a9](https://github.com/easingthemes/ssh-deploy/commit/245b7a9d2fe5272ee34608f86a612d643694c23b))
|
|
||||||
|
|
||||||
## [4.0.4](https://github.com/easingthemes/ssh-deploy/compare/v4.0.3...v4.0.4) (2023-01-03)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* update sub dependencies ([2a32c8d](https://github.com/easingthemes/ssh-deploy/commit/2a32c8dcde2d64394a3577decdd9c902f37a30f8))
|
|
||||||
|
|
||||||
## [4.0.3](https://github.com/easingthemes/ssh-deploy/compare/v4.0.2...v4.0.3) (2023-01-03)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* update v3 e2e test ([450bf42](https://github.com/easingthemes/ssh-deploy/commit/450bf423f388777bde052ad7b5bc24eca392434d))
|
|
||||||
|
|
||||||
## [4.0.2](https://github.com/easingthemes/ssh-deploy/compare/v4.0.1...v4.0.2) (2023-01-03)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* add githubWorkspace as default source root ([3ef66d0](https://github.com/easingthemes/ssh-deploy/commit/3ef66d0be999ee45434505e8bedea4f8b5b5a909))
|
|
||||||
|
|
||||||
## [4.0.1](https://github.com/easingthemes/ssh-deploy/compare/v4.0.0...v4.0.1) (2023-01-03)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* fix default source if empty ([9f191f4](https://github.com/easingthemes/ssh-deploy/commit/9f191f42633c4a0f66054f0fc229c9e30a08f00c))
|
|
||||||
|
|
||||||
# [4.0.0](https://github.com/easingthemes/ssh-deploy/compare/v3.4.3...v4.0.0) (2023-01-03)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* rebuild ([2169399](https://github.com/easingthemes/ssh-deploy/commit/2169399fef9a60a2fea1ab03cce4ec8c2371e5c2))
|
|
||||||
|
|
||||||
|
|
||||||
### Performance Improvements
|
|
||||||
|
|
||||||
* update default rsync options ([2be7efb](https://github.com/easingthemes/ssh-deploy/commit/2be7efb376866327c1d1209f51eb43f34f07b354))
|
|
||||||
|
|
||||||
|
|
||||||
### BREAKING CHANGES
|
|
||||||
|
|
||||||
* Default rsync options updated to speed up default deployments.
|
|
||||||
from `rltgoDzvO` to `-rlgoDzvc -i`
|
|
||||||
|
|
||||||
## [3.4.3](https://github.com/easingthemes/ssh-deploy/compare/v3.4.2...v3.4.3) (2023-01-03)
|
## [3.4.3](https://github.com/easingthemes/ssh-deploy/compare/v3.4.2...v3.4.3) (2023-01-03)
|
||||||
|
|
||||||
|
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "4.0.5",
|
"version": "3.4.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "4.0.5",
|
"version": "3.4.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"rsyncwrapper": "^3.0.1"
|
"rsyncwrapper": "^3.0.1"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "4.1.4",
|
"version": "3.4.3",
|
||||||
"description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.",
|
"description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
@@ -20,7 +20,7 @@ const run = async () => {
|
|||||||
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
||||||
// Update known hosts if ssh command is present to avoid prompt
|
// Update known hosts if ssh command is present to avoid prompt
|
||||||
if (scriptBefore || scriptAfter) {
|
if (scriptBefore || scriptAfter) {
|
||||||
updateKnownHosts(remoteHost, remotePort);
|
updateKnownHosts(remoteHost);
|
||||||
}
|
}
|
||||||
// Check Script before
|
// Check Script before
|
||||||
if (scriptBefore) {
|
if (scriptBefore) {
|
||||||
|
@@ -7,10 +7,14 @@ const inputNames = [
|
|||||||
'SCRIPT_BEFORE', 'SCRIPT_AFTER'];
|
'SCRIPT_BEFORE', 'SCRIPT_AFTER'];
|
||||||
|
|
||||||
const githubWorkspace = process.env.GITHUB_WORKSPACE;
|
const githubWorkspace = process.env.GITHUB_WORKSPACE;
|
||||||
const remoteUser = process.env.REMOTE_USER || process.env.INPUT_REMOTE_USER;
|
const remoteUser = process.env.REMOTE_USER;
|
||||||
|
|
||||||
const defaultInputs = {
|
const defaultInputs = {
|
||||||
|
source: '',
|
||||||
target: `/home/${remoteUser}/`,
|
target: `/home/${remoteUser}/`,
|
||||||
|
exclude: '',
|
||||||
|
args: '-rltgoDzvO',
|
||||||
|
sshCmdArgs: '-o StrictHostKeyChecking=no',
|
||||||
deployKeyName: `deploy_key_${remoteUser}_${Date.now()}`
|
deployKeyName: `deploy_key_${remoteUser}_${Date.now()}`
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -20,19 +24,20 @@ const inputs = {
|
|||||||
|
|
||||||
inputNames.forEach((input) => {
|
inputNames.forEach((input) => {
|
||||||
const inputName = snakeToCamel(input.toLowerCase());
|
const inputName = snakeToCamel(input.toLowerCase());
|
||||||
const inputVal = process.env[input] || process.env[`INPUT_${input}`] || defaultInputs[inputName];
|
const inputVal = process.env[input] || process.env[`INPUT_${input}`];
|
||||||
let extendedVal = inputVal;
|
const validVal = inputVal === undefined ? defaultInputs[inputName] : inputVal;
|
||||||
|
let extendedVal = validVal;
|
||||||
// eslint-disable-next-line default-case
|
// eslint-disable-next-line default-case
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case 'source':
|
case 'source':
|
||||||
extendedVal = inputVal.split(' ').map((src) => `${githubWorkspace}/${src}`);
|
extendedVal = validVal.split(' ').map((src) => `${githubWorkspace}/${src}`);
|
||||||
break;
|
break;
|
||||||
case 'args':
|
case 'args':
|
||||||
extendedVal = inputVal.split(' ');
|
extendedVal = validVal.split(' ');
|
||||||
break;
|
break;
|
||||||
case 'exclude':
|
case 'exclude':
|
||||||
case 'sshCmdArgs':
|
case 'sshCmdArgs':
|
||||||
extendedVal = inputVal.split(',').map((item) => item.trim());
|
extendedVal = validVal.split(',').map((item) => item.trim());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const { sshServer, githubWorkspace, remotePort } = require('./inputs');
|
const { sshServer, githubWorkspace } = require('./inputs');
|
||||||
const { writeToFile } = require('./helpers');
|
const { writeToFile } = require('./helpers');
|
||||||
|
|
||||||
const handleError = (message, isRequired, callback) => {
|
const handleError = (message, isRequired, callback) => {
|
||||||
@@ -15,20 +15,17 @@ const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Prom
|
|||||||
const filename = `local_ssh_script-${label}.sh`;
|
const filename = `local_ssh_script-${label}.sh`;
|
||||||
try {
|
try {
|
||||||
writeToFile({ dir: githubWorkspace, filename, content });
|
writeToFile({ dir: githubWorkspace, filename, content });
|
||||||
const dataLimit = 10000;
|
|
||||||
const rsyncStdout = process.env.RSYNC_STDOUT.substring(0, dataLimit);
|
|
||||||
console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`);
|
console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`);
|
||||||
exec(
|
exec(
|
||||||
`DEBIAN_FRONTEND=noninteractive ssh -p ${(remotePort || 22)} -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${rsyncStdout}" bash -s' < ${filename}`,
|
`DEBIAN_FRONTEND=noninteractive ssh -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${process.env.RSYNC_STDOUT}" bash -s' < ${filename}`,
|
||||||
(err, data, stderr) => {
|
(err, data, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
const message = `⚠️ [CMD] Remote script failed: ${err.message}`;
|
const message = `⚠️ [CMD] Remote script failed: ${err.message}`;
|
||||||
console.warn(`${message} \n`, data, stderr);
|
console.warn(`${message} \n`, data, stderr);
|
||||||
handleError(message, isRequired, reject);
|
handleError(message, isRequired, reject);
|
||||||
} else {
|
} else {
|
||||||
const limited = data.substring(0, dataLimit);
|
console.log('✅ [CMD] Remote script executed. \n', data, stderr);
|
||||||
console.log('✅ [CMD] Remote script executed. \n', limited, stderr);
|
resolve(data);
|
||||||
resolve(limited);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -19,15 +19,15 @@ const addSshKey = (content, deployKeyName) => {
|
|||||||
const { dir, filename } = getPrivateKeyPath(deployKeyName);
|
const { dir, filename } = getPrivateKeyPath(deployKeyName);
|
||||||
writeToFile({ dir, filename: KNOWN_HOSTS, content: '' });
|
writeToFile({ dir, filename: KNOWN_HOSTS, content: '' });
|
||||||
console.log('✅ [SSH] known_hosts file ensured', dir);
|
console.log('✅ [SSH] known_hosts file ensured', dir);
|
||||||
writeToFile({ dir, filename, content: `${content}\r\n`, isRequired: true, mode: '0400' });
|
writeToFile({ dir, filename, content, isRequired: true, mode: '0400' });
|
||||||
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
|
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateKnownHosts = (host, remotePort) => {
|
const updateKnownHosts = (host) => {
|
||||||
const { knownHostsPath } = getPrivateKeyPath();
|
const { knownHostsPath } = getPrivateKeyPath();
|
||||||
console.log('[SSH] Adding host to `known_hosts` ....', host, knownHostsPath);
|
console.log('[SSH] Adding host to `known_hosts` ....', host, knownHostsPath);
|
||||||
try {
|
try {
|
||||||
execSync(`ssh-keyscan -p ${(remotePort || 22)} -H ${host} >> ${knownHostsPath}`, {
|
execSync(`ssh-keyscan -H ${host} >> ${knownHostsPath}`, {
|
||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Reference in New Issue
Block a user