mirror of
https://gitee.com/jiulinxiri/ssh-scp-deploy.git
synced 2025-09-10 02:15:25 +08:00
Initial commit
This commit is contained in:
23
.github/workflows/main.yml
vendored
Normal file
23
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: underscore69/ssh-scp-deploy@main
|
||||
with:
|
||||
local: "./"
|
||||
remote: "~/"
|
||||
host: ${{secrets.HOST}}
|
||||
user: ${{secrets.USER}}
|
||||
key: ${{secrets.KEY}}
|
||||
pre_upload: echo "pre_upload 👈"
|
||||
post_upload: echo "post_upload 👉"
|
9
CHANGELOG.md
Normal file
9
CHANGELOG.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# [Unreleased]
|
||||
|
||||
## [v1.0.0] - 2020-12-18
|
||||
|
||||
### Added
|
||||
- First definition of the action.
|
||||
|
||||
|
||||
[v1.0.0]: https://github.com/underscore69/ssh-scp-deploy/tree/v1.0.0
|
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk update && \
|
||||
apk add --no-cache ca-certificates \
|
||||
openssh-client \
|
||||
sshpass \
|
||||
bash
|
||||
|
||||
COPY LICENSE README.md /
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
22
LICENSE
Normal file
22
LICENSE
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Marco Dalla Santa and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
30
README.md
Normal file
30
README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# ssh-scp-deploy
|
||||
|
||||
[](https://docs.github.com/en/actions/creating-actions/about-actions#types-of-actions)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](./)
|
||||
|
||||
This action provide an easy and higly customizable way to upload files via scp and execute a set of command via ssh before or/and after.
|
||||
|
||||
## Supported runners
|
||||
[](https://docs.github.com/en/actions/creating-actions/about-actions#docker-container-actions)
|
||||
|
||||
## Usage
|
||||
```yaml
|
||||
- uses: underscore69/ssh-scp-deploy@v1.0.0
|
||||
with:
|
||||
local: './' # Local file path - REQUIRED false - DEFAULT ./
|
||||
remote: '~/' # Remote file path - REQUIRED false - DEFAULT ~/
|
||||
host: ${{secrets.HOST}} # Remote server address - REQUIRED true
|
||||
port: ${{secrets.PORT}} # Remote server port - REQUIRED false - DEFAULT 22
|
||||
user: ${{secrets.USER}} # Remote server user - REQUIRED true
|
||||
password: ${{secrets.PASSWORD}} # User password - REQUIRED at least one of "password" or "key"
|
||||
key: ${{secrets.KEY}} # Remote server private key - REQUIRED at least one of "password" or "key"
|
||||
pre_upload: echo "This will be executed before the upload!" # Command to run via ssh before scp upload - REQUIRED false
|
||||
post_upload: echo "This will be executed after the upload!" # Command to run via ssh after scp upload - REQUIRED false
|
||||
ssh_options: -o StrictHostKeyChecking=no # A set of ssh_option separated by -o - REQUIRED false - DEFAULT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
|
||||
scp_options: -v # Flags to use during scp - REQUIRED false - DEFAULT ''
|
||||
```
|
||||
|
||||
## License
|
||||
The source code, scripts and documentation in this project are released under the [MIT License](LICENSE)
|
61
action.yml
Normal file
61
action.yml
Normal file
@@ -0,0 +1,61 @@
|
||||
name: 'ssh-scp-deploy'
|
||||
description: 'A GitHub Action that upload the artifact via scp and runs commands before or/and after.'
|
||||
author: 'Marco Dalla Santa'
|
||||
|
||||
inputs:
|
||||
local:
|
||||
description: 'Local file path'
|
||||
required: false
|
||||
default: './'
|
||||
|
||||
remote:
|
||||
description: 'Remote file path'
|
||||
required: false
|
||||
default: '~/'
|
||||
|
||||
host:
|
||||
description: 'Remote server address'
|
||||
required: true
|
||||
|
||||
port:
|
||||
description: 'Remote server port (default 22)'
|
||||
required: false
|
||||
default: 22
|
||||
|
||||
user:
|
||||
description: 'Remote server user'
|
||||
required: true
|
||||
|
||||
password:
|
||||
description: 'User password'
|
||||
required: false
|
||||
|
||||
key:
|
||||
description: 'Remote server private key'
|
||||
required: false
|
||||
|
||||
pre_upload:
|
||||
description: 'Command to run via ssh before scp upload'
|
||||
required: false
|
||||
|
||||
post_upload:
|
||||
description: 'Command to run via ssh after scp upload'
|
||||
required: false
|
||||
|
||||
ssh_options:
|
||||
description: 'A set of ssh_option separated by -o'
|
||||
required: false
|
||||
default: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
|
||||
|
||||
scp_options:
|
||||
description: 'Flags to use during scp'
|
||||
required: false
|
||||
default:
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
branding:
|
||||
icon: 'upload-cloud'
|
||||
color: 'green'
|
15
entrypoint.sh
Executable file
15
entrypoint.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
PASSWORD=${INPUT_PASSWORD}
|
||||
KEY=${INPUT_KEY}
|
||||
if [ -z "$PRE_UPLOAD" and "$PASSWORD"]; then
|
||||
echo "🔑 Please provide at least a key or a password...";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ ! -z "$KEY" ]]; then
|
||||
echo "🔑 Using key file...";
|
||||
. with_key.sh;
|
||||
else
|
||||
echo "🔑 Using password...";
|
||||
. with_pass.sh;
|
||||
fi
|
24
with_key.sh
Normal file
24
with_key.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
echo "🔑 Adding ssh key..." &&
|
||||
eval $(ssh-agent -s) &&
|
||||
ssh-add <(echo "${INPUT_KEY}") &&
|
||||
echo "🔐 Added ssh key";
|
||||
|
||||
PRE_UPLOAD=${INPUT_PRE_UPLOAD}
|
||||
if [ ! -z "$PRE_UPLOAD" ]; then
|
||||
echo "👌 Executing pre-upload script..." &&
|
||||
ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$INPUT_PRE_UPLOAD && exit" &&
|
||||
echo "✅ Executed pre-upload script";
|
||||
fi
|
||||
|
||||
echo "🚚 Uploading via scp..." &&
|
||||
scp ${INPUT_SSH_OPTIONS} ${INPUT_SCP_OPTIONS} -P "${INPUT_PORT}" -r ${INPUT_LOCAL} ubuntu@${INPUT_HOST}:"${INPUT_REMOTE}" &&
|
||||
echo "🙌 Uploaded via scp";
|
||||
|
||||
POST_UPLOAD=${INPUT_POST_UPLOAD}
|
||||
if [ ! -z "$POST_UPLOAD" ]; then
|
||||
echo "👌 Executing post-upload script..." &&
|
||||
ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$POST_UPLOAD && exit" &&
|
||||
echo "✅ Executed post-upload script";
|
||||
fi
|
||||
|
||||
echo "🎉 Done";
|
19
with_pass.sh
Normal file
19
with_pass.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
PRE_UPLOAD=${INPUT_PRE_UPLOAD}
|
||||
if [ ! -z "$PRE_UPLOAD" ]; then
|
||||
echo "👌 Executing pre-upload script..." &&
|
||||
sshpass -p ${PASSWORD} ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$INPUT_PRE_UPLOAD && exit" &&
|
||||
echo "✅ Executed pre-upload script";
|
||||
fi
|
||||
|
||||
echo "🚚 Uploading via scp..." &&
|
||||
sshpass -p ${PASSWORD} scp ${INPUT_SSH_OPTIONS} ${INPUT_SCP_OPTIONS} -P "${INPUT_PORT}" -r ${INPUT_LOCAL} ubuntu@${INPUT_HOST}:"${INPUT_REMOTE}" &&
|
||||
echo "🙌 Uploaded via scp";
|
||||
|
||||
POST_UPLOAD=${INPUT_POST_UPLOAD}
|
||||
if [ ! -z "$POST_UPLOAD" ]; then
|
||||
echo "👌 Executing post-upload script..." &&
|
||||
sshpass -p ${PASSWORD} ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$POST_UPLOAD && exit" &&
|
||||
echo "✅ Executed post-upload script";
|
||||
fi
|
||||
|
||||
echo "🎉 Done";
|
Reference in New Issue
Block a user