Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c51573a06a | ||
|
d068cd7f84 | ||
|
8ba3cfe760 | ||
|
1a6b426141 | ||
|
8b3eebcc8d | ||
|
861f2e0e7b | ||
|
6971270956 | ||
|
bac6c9e026 | ||
|
b04405242e | ||
|
5cb36bda99 | ||
|
6c5771fab8 | ||
|
193fd4eaa9 | ||
|
a5de8af6d5 | ||
|
671c934c80 | ||
|
8da6e3d335 | ||
|
196ea3f88f | ||
|
034b0ad00c | ||
|
95e250284b | ||
|
a593d18cb8 | ||
|
2e28e2ddc9 | ||
|
f8189f0fbf | ||
|
722ddfc32b | ||
|
e506e72e83 | ||
|
bd7b71696a | ||
|
b1b9ed628c | ||
|
72fe6fa2ca | ||
|
f1b7ce641c | ||
|
722d935a90 | ||
|
6fd371aeaf | ||
|
5138976c70 | ||
|
d322577e98 | ||
|
c0a815a115 | ||
|
afd2e26f9f | ||
|
2ef3f5e459 | ||
|
f0de4fea6f | ||
|
03e93ae863 | ||
|
bffdab6759 | ||
|
e22c039905 | ||
|
44284b60e4 | ||
|
b154adaf5c | ||
|
a6224ab4f0 | ||
|
1a31789cbc | ||
|
74e3e1df58 |
65
.github/main.workflow
vendored
65
.github/main.workflow
vendored
@@ -1,65 +0,0 @@
|
||||
workflow "Copy File Via SSH" {
|
||||
on = "push"
|
||||
resolves = [
|
||||
"Copy file via ssh password",
|
||||
"Copy file via ssh key",
|
||||
"Add source in args",
|
||||
"Add secret in args",
|
||||
]
|
||||
}
|
||||
|
||||
action "Copy file via ssh password" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
SOURCE = "tests/a.txt,tests/b.txt"
|
||||
TARGET = "/home/actions/test"
|
||||
}
|
||||
secrets = [
|
||||
"HOST",
|
||||
"USERNAME",
|
||||
"PASSWORD",
|
||||
]
|
||||
}
|
||||
|
||||
action "Copy file via ssh key" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
SOURCE = "tests/a.txt,tests/b.txt"
|
||||
TARGET = "/home/actions/test"
|
||||
}
|
||||
secrets = [
|
||||
"HOST",
|
||||
"USERNAME",
|
||||
"KEY",
|
||||
]
|
||||
}
|
||||
|
||||
action "Add source in args" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
TARGET = "/home/actions/test1234"
|
||||
}
|
||||
secrets = [
|
||||
"HOST",
|
||||
"USERNAME",
|
||||
"KEY",
|
||||
]
|
||||
args = ["--source", "tests/a.txt", "--source", "tests/b.txt"]
|
||||
}
|
||||
|
||||
action "Add secret in args" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
TARGET = "/home/actions/test1234"
|
||||
}
|
||||
secrets = [
|
||||
"HOST",
|
||||
"TEST_USERNAME",
|
||||
"KEY",
|
||||
]
|
||||
args = [
|
||||
"--username", "$TEST_USERNAME",
|
||||
"--source", "tests/a.txt",
|
||||
"--source", "tests/b.txt",
|
||||
]
|
||||
}
|
52
.github/workflows/ci.yml
vendored
Normal file
52
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
name: scp files
|
||||
on: [push]
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: copy file via ssh password
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
|
||||
- name: copy file via ssh key
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
|
||||
- name: remove the specified number of leading path elements
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "foobar"
|
||||
strip_components: 1
|
||||
|
||||
- name: ssh key with passphrase
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.SSH2 }}
|
||||
passphrase: ${{ secrets.PASSPHRASE }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
13
Dockerfile
13
Dockerfile
@@ -1,15 +1,4 @@
|
||||
FROM appleboy/drone-scp:1.5.1-linux-amd64
|
||||
|
||||
# Github labels
|
||||
LABEL "com.github.actions.name"="SCP Files"
|
||||
LABEL "com.github.actions.description"="Copy files and artifacts via SSH"
|
||||
LABEL "com.github.actions.icon"="copy"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
|
||||
LABEL "repository"="https://github.com/appleboy/scp-action"
|
||||
LABEL "homepage"="https://github.com/appleboy"
|
||||
LABEL "maintainer"="Bo-Yi Wu <appleboy.tw@gmail.com>"
|
||||
LABEL "version"="0.0.1"
|
||||
FROM appleboy/drone-scp:1.5.8-linux-amd64
|
||||
|
||||
ADD entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
211
README.md
211
README.md
@@ -1,97 +1,168 @@
|
||||
# 🚀 SCP for GitHub Actions
|
||||
|
||||
[GitHub Action](https://developer.github.com/actions/) for copying files and artifacts via SSH.
|
||||
[GitHub Action](https://github.com/features/actions) for copying files and artifacts via SSH.
|
||||
|
||||
<img src="./images/copy-multiple-file.png">
|
||||

|
||||
|
||||
[](https://github.com/appleboy/scp-action/actions)
|
||||
|
||||
## Usage
|
||||
|
||||
copy files and artifacts via SSH as blow.
|
||||
|
||||
```
|
||||
action "Copy multiple file" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
HOST = "example.com"
|
||||
USERNAME = "foo"
|
||||
PASSWORD = "bar"
|
||||
PORT = "22"
|
||||
SOURCE = "tests/a.txt,tests/b.txt"
|
||||
TARGET = "/home/foo/test"
|
||||
}
|
||||
secrets = [
|
||||
"PASSWORD",
|
||||
]
|
||||
}
|
||||
```yaml
|
||||
name: scp files
|
||||
on: [push]
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: copy file via ssh password
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
```
|
||||
|
||||
## Environment variables
|
||||
## Input variables
|
||||
|
||||
* HOST - ssh server host
|
||||
* PORT - ssh server port
|
||||
* USERNAME - ssh server username
|
||||
* PASSWORD - ssh server password
|
||||
* KEY - ssh server private key
|
||||
* TARGET - target folder
|
||||
* SOURCE - scp file list
|
||||
see the [action.yml](./action.yml) file for more detail imformation.
|
||||
|
||||
* host - scp remote host
|
||||
* port - scp remote port, default is `22`
|
||||
* username - scp username
|
||||
* password - scp password
|
||||
* passphrase - the passphrase is usually to encrypt the private key
|
||||
* timeout - timeout for ssh to remote host, default is `30s`
|
||||
* command_timeout - timeout for scp command, default is `10m`
|
||||
* key - content of ssh private key. ex raw content of ~/.ssh/id_rsa
|
||||
* key_path - path of ssh private key
|
||||
* target - target path on the server
|
||||
* source - scp file list
|
||||
* rm - remove target folder before upload data, default is `false`
|
||||
* strip_components - remove the specified number of leading path elements.
|
||||
* overwrite - use `--overwrite` flag with tar
|
||||
* tar_tmp_path - temporary path for tar file on the dest host
|
||||
|
||||
SSH Proxy Setting:
|
||||
|
||||
* proxy_host - proxy host
|
||||
* proxy_port - proxy port, default is `22`
|
||||
* proxy_username - proxy username
|
||||
* proxy_password - proxy password
|
||||
* proxy_passphrase - the passphrase is usually to encrypt the private key
|
||||
* proxy_timeout - timeout for ssh to proxy host, default is `30s`
|
||||
* proxy_key - content of ssh proxy private key.
|
||||
* proxy_key_path - path of ssh proxy private key
|
||||
|
||||
### Example
|
||||
|
||||
Copy file via ssh password
|
||||
|
||||
```
|
||||
action "Copy multiple file" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
HOST = "example.com"
|
||||
USERNAME = "foo"
|
||||
PORT = "22"
|
||||
SOURCE = "tests/a.txt,tests/b.txt"
|
||||
TARGET = "/home/foo/test"
|
||||
}
|
||||
secrets = [
|
||||
"PASSWORD",
|
||||
]
|
||||
}
|
||||
```yaml
|
||||
- name: copy file via ssh password
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: example.com
|
||||
username: foo
|
||||
password: bar
|
||||
port: 22
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
```
|
||||
|
||||
Copy file via ssh key
|
||||
|
||||
```
|
||||
action "Copy file via ssh key" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
HOST = "example.com"
|
||||
USERNAME = "foo"
|
||||
PORT = "22"
|
||||
SOURCE = "tests/c.txt,tests/d.txt"
|
||||
TARGET = "/home/actions/test"
|
||||
}
|
||||
secrets = [
|
||||
"KEY",
|
||||
]
|
||||
}
|
||||
```yaml
|
||||
- name: copy file via ssh key
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
port: ${{ secrets.PORT }}
|
||||
key: ${{ secrets.KEY }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
```
|
||||
|
||||
Example configuration for ignore list:
|
||||
|
||||
```
|
||||
action "reqular expression list" {
|
||||
uses = "appleboy/scp-action@master"
|
||||
env = {
|
||||
HOST = "example.com"
|
||||
USERNAME = "foo"
|
||||
PORT = "22"
|
||||
SOURCE = "tests/*.txt,!tests/a.txt"
|
||||
TARGET = "/home/actions/test"
|
||||
}
|
||||
secrets = [
|
||||
"KEY",
|
||||
]
|
||||
}
|
||||
```yaml
|
||||
- name: copy file via ssh key
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
port: ${{ secrets.PORT }}
|
||||
key: ${{ secrets.KEY }}
|
||||
source: "tests/*.txt,!tests/a.txt"
|
||||
target: "test"
|
||||
```
|
||||
|
||||
## Secrets
|
||||
Example configuration for multiple server
|
||||
|
||||
* `PASSWORD` - ssh server password
|
||||
* `KEY` - ssh server private key
|
||||
```diff
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
- host: "example.com"
|
||||
+ host: "foo.com,bar.com"
|
||||
username: foo
|
||||
password: bar
|
||||
port: 22
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
```
|
||||
|
||||
remove the specified number of leading path elements
|
||||
|
||||
```yaml
|
||||
- name: remove the specified number of leading path elements
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "foobar"
|
||||
strip_components: 1
|
||||
```
|
||||
|
||||
old target structure:
|
||||
|
||||
```sh
|
||||
foobar
|
||||
└── tests
|
||||
├── a.txt
|
||||
└── b.txt
|
||||
```
|
||||
|
||||
new target structure:
|
||||
|
||||
```sh
|
||||
foobar
|
||||
├── a.txt
|
||||
└── b.txt
|
||||
```
|
||||
|
||||
Protecting a Private Key. The purpose of the passphrase is usually to encrypt the private key. This makes the key file by itself useless to an attacker. It is not uncommon for files to leak from backups or decommissioned hardware, and hackers commonly exfiltrate files from compromised systems.
|
||||
|
||||
```diff
|
||||
- name: ssh key with passphrase
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.SSH2 }}
|
||||
+ passphrase: ${{ secrets.PASSPHRASE }}
|
||||
port: ${{ secrets.PORT }}
|
||||
source: "tests/a.txt,tests/b.txt"
|
||||
target: "test"
|
||||
```
|
||||
|
65
action.yml
Normal file
65
action.yml
Normal file
@@ -0,0 +1,65 @@
|
||||
name: 'SCP Command to Transfer Files'
|
||||
description: 'How to Use SCP Command to Transfer Files/Folders in Linux'
|
||||
author: 'Bo-Yi Wu'
|
||||
inputs:
|
||||
host:
|
||||
description: 'scp remote host'
|
||||
port:
|
||||
description: 'scp remote port'
|
||||
default: 22
|
||||
username:
|
||||
description: 'scp username'
|
||||
password:
|
||||
description: 'scp password'
|
||||
timeout:
|
||||
description: 'timeout for ssh to remote host'
|
||||
default: "30s"
|
||||
command_timeout:
|
||||
description: 'timeout for scp command'
|
||||
default: "10m"
|
||||
key:
|
||||
description: 'content of ssh private key. ex raw content of ~/.ssh/id_rsa'
|
||||
key_path:
|
||||
description: 'path of ssh private key'
|
||||
passphrase:
|
||||
description: 'ssh key passphrase'
|
||||
target:
|
||||
description: 'target path on the server'
|
||||
source:
|
||||
description: 'scp file list'
|
||||
rm:
|
||||
description: 'remove target folder before upload data'
|
||||
default: false
|
||||
strip_components:
|
||||
description: 'remove the specified number of leading path elements'
|
||||
default: 0
|
||||
overwrite:
|
||||
description: 'use `--overwrite` flag with tar'
|
||||
default: false
|
||||
tar_tmp_path:
|
||||
description: 'temporary path for tar file on the dest host'
|
||||
proxy_host:
|
||||
description: 'ssh proxy remote host'
|
||||
proxy_port:
|
||||
description: 'ssh proxy remote port'
|
||||
default: 22
|
||||
proxy_username:
|
||||
description: 'ssh proxy username'
|
||||
proxy_password:
|
||||
description: 'ssh proxy password'
|
||||
proxy_passphrase:
|
||||
description: 'ssh proxy key passphrase'
|
||||
proxy_timeout:
|
||||
description: 'timeout for ssh to proxy host'
|
||||
default: "30s"
|
||||
proxy_key:
|
||||
description: 'content of ssh proxy private key. ex raw content of ~/.ssh/id_rsa'
|
||||
proxy_key_path:
|
||||
description: 'path of ssh proxy private key'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
branding:
|
||||
icon: 'copy'
|
||||
color: 'gray-dark'
|
@@ -4,4 +4,6 @@ set -eu
|
||||
|
||||
export GITHUB="true"
|
||||
|
||||
[ -n "$INPUT_STRIP_COMPONENTS" ] && export INPUT_STRIP_COMPONENTS=$((INPUT_STRIP_COMPONENTS + 0))
|
||||
|
||||
sh -c "/bin/drone-scp $*"
|
||||
|
Reference in New Issue
Block a user