mirror of
https://gitee.com/jack_whh/ssh-scp-ssh-pipelines.git
synced 2026-03-09 22:42:55 +08:00
update action
This commit is contained in:
10
.github/workflows/deploy.yml
vendored
10
.github/workflows/deploy.yml
vendored
@@ -4,6 +4,9 @@ on:
|
||||
branches:
|
||||
- latest
|
||||
|
||||
env:
|
||||
TARGET_DIR: /home/github/test
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
@@ -32,7 +35,7 @@ jobs:
|
||||
mkdir -p /home/github/test/test2 &&
|
||||
scp: |-
|
||||
'./test/*' => /home/github/test/
|
||||
./test/test1* => /home/github/test/test1/
|
||||
./test/test1* => $TARGET_DIR/test1/
|
||||
./test/test*.csv => "/home/github/test/test2/"
|
||||
last_ssh: |-
|
||||
echo $LASTSSH &&
|
||||
@@ -49,7 +52,7 @@ jobs:
|
||||
pass: ${{ secrets.DC_PASS }}
|
||||
scp: |-
|
||||
./test/test1* => /home/github/test/test1/
|
||||
./test/test*.csv => "/home/github/test/test2/"
|
||||
"." => "$TARGET_DIR/test3/"
|
||||
last_ssh: |-
|
||||
echo $LASTSSH
|
||||
ls -la
|
||||
@@ -58,9 +61,10 @@ jobs:
|
||||
uses: cross-the-world/ssh-scp-ssh-pipelines@latest
|
||||
env:
|
||||
WELCOME: "scp pipelines"
|
||||
TO_DIR: /home/github/test/test4
|
||||
with:
|
||||
host: ${{ secrets.DC_HOST }}
|
||||
user: ${{ secrets.DC_USER }}
|
||||
pass: ${{ secrets.DC_PASS }}
|
||||
scp: |-
|
||||
'./test/*' => /home/github/test/
|
||||
'.' => $TO_DIR
|
||||
@@ -2,7 +2,7 @@ FROM python:3.8.3-slim-buster
|
||||
|
||||
LABEL "maintainer"="Scott Ng <thuongnht@gmail.com>"
|
||||
LABEL "repository"="https://github.com/cross-the-world/ssh-scp-ssh-pipelines"
|
||||
LABEL "version"="latest"
|
||||
LABEL "version"="v1.1.0"
|
||||
|
||||
LABEL "com.github.actions.name"="ssh-scp-ssh-pipelines"
|
||||
LABEL "com.github.actions.description"="Pipeline: ssh -> scp -> ssh"
|
||||
@@ -16,7 +16,6 @@ COPY requirements.txt /requirements.txt
|
||||
RUN pip3 install -r /requirements.txt
|
||||
|
||||
RUN mkdir -p /opt/tools
|
||||
WORKDIR /opt/tools
|
||||
|
||||
COPY entrypoint.sh /opt/tools/entrypoint.sh
|
||||
RUN chmod +x /opt/tools/entrypoint.sh
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
[Github actions](https://help.github.com/en/actions/creating-actions/creating-a-docker-container-action)
|
||||
|
||||
Credit to [SSH SCP Action of Ali Najafizadeh](https://github.com/alinz/ssh-scp-action)
|
||||
[SSH action](https://github.com/cross-the-world/ssh-pipeline)
|
||||
|
||||
[SCP action](https://github.com/cross-the-world/scp-pipeline)
|
||||
|
||||
This action allows doing in order
|
||||
1. ssh if defined
|
||||
|
||||
21
app.py
21
app.py
@@ -37,12 +37,12 @@ def convert_to_seconds(s):
|
||||
strips = [" ", "\"", " ", "'", " "]
|
||||
|
||||
|
||||
def strip_path(p):
|
||||
def strip_and_parse_envs(p):
|
||||
if not p:
|
||||
return None
|
||||
for c in strips:
|
||||
p = p.strip(c)
|
||||
return p
|
||||
return path.expandvars(p)
|
||||
|
||||
|
||||
def connect(callback=None):
|
||||
@@ -79,16 +79,19 @@ def ssh_process(ssh, input_ssh):
|
||||
|
||||
stdin, stdout, stderr = ssh.exec_command(command_str)
|
||||
|
||||
err = "".join(stderr.readlines())
|
||||
err = err.strip() if err is not None else None
|
||||
if err:
|
||||
print(f"Error: \n{err}")
|
||||
|
||||
out = "".join(stdout.readlines())
|
||||
out = out.strip() if out is not None else None
|
||||
if out:
|
||||
print(f"Success: \n{out}")
|
||||
|
||||
err = "".join(stderr.readlines())
|
||||
err = err.strip() if err is not None else None
|
||||
if err:
|
||||
if out is None:
|
||||
raise Exception(err)
|
||||
else:
|
||||
print(f"Error: \n{err}")
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -99,8 +102,8 @@ def scp_process(ssh, input_scp):
|
||||
continue
|
||||
l2r = c.split("=>")
|
||||
if len(l2r) == 2:
|
||||
local = strip_path(l2r[0])
|
||||
remote = strip_path(l2r[1])
|
||||
local = strip_and_parse_envs(l2r[0])
|
||||
remote = strip_and_parse_envs(l2r[1])
|
||||
if local and remote:
|
||||
copy_list.append({"l": local, "r": remote})
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user