mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-19 08:08:05 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c28aa7215e | ||
|
caaa95b651 | ||
|
d86da2b0b7 | ||
|
445db7826b | ||
|
4a2dc47c39 | ||
|
0d77a6681b | ||
|
a3d2df0501 | ||
|
7d63f7f134 | ||
|
5fdc019220 | ||
|
177ffc3a2a |
26
README.md
26
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`;
|
||||||
@@ -9,27 +13,41 @@ 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.
|
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]
|
2. `REMOTE_HOST` [required]
|
||||||
|
|
||||||
|
eg: mydomain.com
|
||||||
|
|
||||||
3. `REMOTE_USER` [required]
|
3. `REMOTE_USER` [required]
|
||||||
|
|
||||||
2. `ARGS` (optional)
|
eg: myusername
|
||||||
|
|
||||||
|
3. `REMOTE_PORT` (optional, default '22')
|
||||||
|
|
||||||
|
eg: '59184'
|
||||||
|
|
||||||
|
2. `ARGS` (optional, default '-rltgoDzvO')
|
||||||
|
|
||||||
For any initial/required rsync flags, eg: `-avzr --delete`
|
For any initial/required rsync flags, eg: `-avzr --delete`
|
||||||
|
|
||||||
3. `SOURCE` (optional, default '')
|
3. `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/')
|
4. `TARGET` (optional, default '/home/REMOTE_USER/')
|
||||||
|
|
||||||
The target directory
|
The target directory
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: Deploy to Staging server
|
- name: Deploy to Staging server
|
||||||
uses: easingthemes/ssh-deploy@v2.0.2
|
uses: easingthemes/ssh-deploy@v2.0.7
|
||||||
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 }}
|
||||||
@@ -59,7 +77,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.0.7
|
||||||
env:
|
env:
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
ARGS: "-rltgoDzvO --delete"
|
ARGS: "-rltgoDzvO --delete"
|
||||||
|
32
action.yml
32
action.yml
@@ -1,27 +1,31 @@
|
|||||||
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"
|
||||||
|
default: "22"
|
||||||
SOURCE:
|
SOURCE:
|
||||||
description: 'Source directory'
|
description: "Source directory"
|
||||||
default: ''
|
default: ""
|
||||||
TARGET:
|
TARGET:
|
||||||
description: 'Target directory'
|
description: "Target directory"
|
||||||
default: '/home/REMOTE_USER/'
|
default: "/home/REMOTE_USER/"
|
||||||
outputs:
|
outputs:
|
||||||
status:
|
status:
|
||||||
description: 'Status'
|
description: "Status"
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: "node12"
|
||||||
main: 'dist/index.js'
|
main: "dist/index.js"
|
||||||
branding:
|
branding:
|
||||||
color: 'green'
|
color: "green"
|
||||||
icon: 'truck'
|
icon: "truck"
|
||||||
|
12
dist/index.js
vendored
12
dist/index.js
vendored
@@ -480,16 +480,16 @@ const commandExists = __webpack_require__(677);
|
|||||||
const nodeCmd = __webpack_require__(428);
|
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 { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env;
|
||||||
console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE);
|
console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE);
|
||||||
|
|
||||||
const sshDeploy = (() => {
|
const sshDeploy = (() => {
|
||||||
const rsync = ({ privateKey, src, dest, args }) => {
|
const rsync = ({ privateKey, port, src, dest, args }) => {
|
||||||
console.log(`Starting Rsync Action: ${src} to ${dest}`);
|
console.log(`Starting Rsync Action: ${src} to ${dest}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// RSYNC COMMAND
|
// RSYNC COMMAND
|
||||||
nodeRsync({ src, dest, args, privateKey, ssh: true, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => {
|
nodeRsync({ src, dest, args, privateKey, ssh: true, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('⚠️ Rsync error', error.message);
|
console.error('⚠️ Rsync error', error.message);
|
||||||
process.abort();
|
process.abort();
|
||||||
@@ -509,14 +509,15 @@ const sshDeploy = (() => {
|
|||||||
args,
|
args,
|
||||||
host = 'localhost',
|
host = 'localhost',
|
||||||
username,
|
username,
|
||||||
privateKeyContent
|
privateKeyContent,
|
||||||
|
port
|
||||||
}) => {
|
}) => {
|
||||||
validateRsync(() => {
|
validateRsync(() => {
|
||||||
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key');
|
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key');
|
||||||
|
|
||||||
const remoteDest = username + '@' + host + ':' + dest;
|
const remoteDest = username + '@' + host + ':' + dest;
|
||||||
|
|
||||||
rsync({ privateKey, src, dest: remoteDest, args });
|
rsync({ privateKey, port, src, dest: remoteDest, args });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -616,6 +617,7 @@ const run = () => {
|
|||||||
dest: TARGET || '/home/' + REMOTE_USER + '/',
|
dest: TARGET || '/home/' + REMOTE_USER + '/',
|
||||||
args: [ARGS] || false,
|
args: [ARGS] || false,
|
||||||
host: REMOTE_HOST,
|
host: REMOTE_HOST,
|
||||||
|
port: REMOTE_PORT || '22',
|
||||||
username: REMOTE_USER,
|
username: REMOTE_USER,
|
||||||
privateKeyContent: SSH_PRIVATE_KEY,
|
privateKeyContent: SSH_PRIVATE_KEY,
|
||||||
});
|
});
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ssh-deploy",
|
"name": "ssh-deploy",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ssh-deploy",
|
"name": "ssh-deploy",
|
||||||
"version": "2.0.3",
|
"version": "2.1.0",
|
||||||
"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": {
|
||||||
|
14
src/index.js
14
src/index.js
@@ -5,16 +5,16 @@ const commandExists = require('command-exists');
|
|||||||
const nodeCmd = require('node-cmd');
|
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 { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env;
|
||||||
console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE);
|
console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE);
|
||||||
|
|
||||||
const sshDeploy = (() => {
|
const sshDeploy = (() => {
|
||||||
const rsync = ({ privateKey, src, dest, args }) => {
|
const rsync = ({ privateKey, port, src, dest, args }) => {
|
||||||
console.log(`Starting Rsync Action: ${src} to ${dest}`);
|
console.log(`Starting Rsync Action: ${src} to ${dest}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// RSYNC COMMAND
|
// RSYNC COMMAND
|
||||||
nodeRsync({ src, dest, args, privateKey, ssh: true, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => {
|
nodeRsync({ src, dest, args, privateKey, ssh: true, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('⚠️ Rsync error', error.message);
|
console.error('⚠️ Rsync error', error.message);
|
||||||
process.abort();
|
process.abort();
|
||||||
@@ -34,14 +34,15 @@ const sshDeploy = (() => {
|
|||||||
args,
|
args,
|
||||||
host = 'localhost',
|
host = 'localhost',
|
||||||
username,
|
username,
|
||||||
privateKeyContent
|
privateKeyContent,
|
||||||
|
port
|
||||||
}) => {
|
}) => {
|
||||||
validateRsync(() => {
|
validateRsync(() => {
|
||||||
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key');
|
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key');
|
||||||
|
|
||||||
const remoteDest = username + '@' + host + ':' + dest;
|
const remoteDest = username + '@' + host + ':' + dest;
|
||||||
|
|
||||||
rsync({ privateKey, src, dest: remoteDest, args });
|
rsync({ privateKey, port, src, dest: remoteDest, args });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,8 +140,9 @@ const run = () => {
|
|||||||
sshDeploy.init({
|
sshDeploy.init({
|
||||||
src: GITHUB_WORKSPACE + '/' + SOURCE || '',
|
src: GITHUB_WORKSPACE + '/' + SOURCE || '',
|
||||||
dest: TARGET || '/home/' + REMOTE_USER + '/',
|
dest: TARGET || '/home/' + REMOTE_USER + '/',
|
||||||
args: [ARGS] || ['-rltgoDzvO'],
|
args: ARGS ? [ARGS] : ['-rltgoDzvO'],
|
||||||
host: REMOTE_HOST,
|
host: REMOTE_HOST,
|
||||||
|
port: REMOTE_PORT || '22',
|
||||||
username: REMOTE_USER,
|
username: REMOTE_USER,
|
||||||
privateKeyContent: SSH_PRIVATE_KEY,
|
privateKeyContent: SSH_PRIVATE_KEY,
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user