mirror of
https://gitee.com/jack_whh/SFTP-Deploy-Action.git
synced 2026-03-13 00:12:56 +08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33436f92f1 | ||
|
|
3586e619fa | ||
|
|
8392b571c7 | ||
|
|
c6e4d76ad9 | ||
|
|
3a6bd36ae1 | ||
|
|
00c712f732 | ||
|
|
28d6168ebf | ||
|
|
f19d10cf6b | ||
|
|
cf8d9e5b50 | ||
|
|
6ff9f12bc8 | ||
|
|
b2206dcb19 | ||
|
|
19ad014b34 | ||
|
|
1f1ab26f78 | ||
|
|
564673d595 | ||
|
|
7fd32bff94 | ||
|
|
610ec6e1c9 | ||
|
|
f1b3556b75 | ||
|
|
6b5c2a4271 |
21
.github/workflows/main.yml
vendored
Normal file
21
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Continuous Deploy #action名称
|
||||
on: [push] #在推送的时候运行此action
|
||||
|
||||
jobs:
|
||||
deploy_job:
|
||||
runs-on: ubuntu-latest #运行环境
|
||||
name: sftp
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# 利用action把build好的文件上传到服务器/var/www/react-app路径下,需要确认此目录已在服务端创建
|
||||
- name: deploy file to server
|
||||
uses: ./ # Uses an action in the root directory
|
||||
with:
|
||||
username: 'root' #ssh user name
|
||||
server: '${{ secrets.SERVER_IP }}'
|
||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
local_path: './action.yml' # 对应我们项目build的文件夹路径
|
||||
remote_path: '/var/www/react-app/'
|
||||
# delete_remote_files: true
|
||||
@@ -1,5 +1,5 @@
|
||||
# Container image that runs your code
|
||||
FROM alpine:3.10
|
||||
FROM alpine:3.13
|
||||
|
||||
# Copies your code file from your action repository to the filesystem path `/` of the container
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
@@ -12,4 +12,4 @@ RUN apk add --no-cache openssh
|
||||
|
||||
|
||||
# Code file to execute when the docker container starts up (`entrypoint.sh`)
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
119
README.md
119
README.md
@@ -3,38 +3,23 @@
|
||||
> Use this action to deploy your files to server using `SSH Private Key`
|
||||
|
||||
> 使用此`action`部署你的项目到服务器上,`仅支持密钥对连接`
|
||||
中文介绍链接:[使用Github Action 部署项目到云服务器](https://zhuanlan.zhihu.com/p/107545396)
|
||||
|
||||
## 1. Inputs
|
||||
|
||||
## Inputs
|
||||
| Name | Required | Default | Description |
|
||||
|------------------------|----------------------|---------|-----------------------------------------------|
|
||||
`username` | yes| | SSH username
|
||||
`server` | yes| | Remote host
|
||||
`port`| yes | 22 | Remote host port
|
||||
`ssh_private_key`| yes| | You can copy private key from your `ssh_private_key.pem` file, and save to`repo/settings/secrets`
|
||||
`local_path`| yes| ./* | `local_path` of you project, if you want put single file:use path like `./myfile`, if you want put directory: use path like `./static/*`, it will put all files under `static` directory. Default to `./*`(will put all files in your repo).
|
||||
`remote_path`|yes|| Remote path
|
||||
`sftp_only`| no| | If your port only accepts the sftp protocol, set this option to `true`. However, please note that when this option is set to `true`, the remote folder will not be created automatically.
|
||||
`args` | no| | other args yor want to use of sftp, E.g.`-o ConnectTimeout=5`
|
||||
`delete_remote_files` | no | false | Set `true` will delete all files in the remote path before upload. Please be `careful` set this to true
|
||||
|
||||
### `username`
|
||||
|
||||
> **Required** sftp username.
|
||||
|
||||
### `server`
|
||||
|
||||
> **Required** sftp server address.
|
||||
|
||||
### `port`
|
||||
|
||||
> sftp srever port , default `22`.
|
||||
|
||||
### `ssh_private_key`
|
||||
|
||||
> **Required** you can copy private_key from your `ssh_private_key.pem file`, keep format, and save at`repo/settings/secrets`
|
||||
|
||||
### `local_path`
|
||||
|
||||
> **Required** `local_path` of you project, if you want put single file:use path like `./myfile`, if you want put directory: use path like `./static/*`, it will put all files under `static` directory. Default to `./*`(will put all files in your repo).
|
||||
|
||||
### `remote_path`
|
||||
> **Required** remote_path
|
||||
|
||||
### `args`
|
||||
> args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||
|
||||
|
||||
## Example usage
|
||||
## Action Example
|
||||
|
||||
|
||||
on: [push]
|
||||
@@ -47,11 +32,81 @@
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: deploy file
|
||||
uses: ./ # Uses an action in the root directory
|
||||
uses: wlixcc/SFTP-Deploy-Action@v1.2.3
|
||||
with:
|
||||
username: 'root'
|
||||
server: 'your server ip'
|
||||
private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
local_path: './static/*'
|
||||
remote_path: '/var/www/app' #make sure dir exist
|
||||
remote_path: '/var/www/app'
|
||||
args: '-o ConnectTimeout=5'
|
||||
|
||||
## 1. [Deploy React App Example](https://github.com/wlixcc/React-Deploy)
|
||||
|
||||
> If you use nginx, all you need to do is upload the static files to the server after the project is built
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
deploy_job:
|
||||
runs-on: ubuntu-latest
|
||||
name: build&deploy
|
||||
steps:
|
||||
# To use this repository's private action, you must check out the repository
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
- name: Build
|
||||
run: yarn build
|
||||
|
||||
- name: deploy file to server
|
||||
uses: wlixcc/SFTP-Deploy-Action@v1.2.3
|
||||
with:
|
||||
username: 'root'
|
||||
server: '${{ secrets.SERVER_IP }}'
|
||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
local_path: './build/*'
|
||||
remote_path: '/var/www/react-app'
|
||||
args: '-o ConnectTimeout=5'
|
||||
|
||||

|
||||
|
||||
## 2.Deploy Umi App Example (Ant Design Pro)
|
||||
|
||||
name: continuous deployment
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
deploy_job:
|
||||
runs-on: ubuntu-latest
|
||||
name: build&deploy
|
||||
steps:
|
||||
# To use this repository's private action, you must check out the repository
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install umi
|
||||
run: yarn global add umi
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
- name: Build
|
||||
run: yarn build
|
||||
|
||||
- name: deploy file to server
|
||||
uses: wlixcc/SFTP-Deploy-Action@v1.2.3
|
||||
with:
|
||||
username: 'root'
|
||||
server: '${{ secrets.SERVER_IP }}'
|
||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
local_path: './dist/*'
|
||||
remote_path: '/var/www/umiapp'
|
||||
args: '-o ConnectTimeout=5'
|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
12
action.yml
12
action.yml
@@ -22,11 +22,17 @@ inputs:
|
||||
remote_path:
|
||||
description: 'files will copy to under remote_path'
|
||||
required: true
|
||||
default: /
|
||||
|
||||
sftp_only:
|
||||
description: 'connection via sftp protocol only'
|
||||
required: false
|
||||
default: false
|
||||
args:
|
||||
description: 'sftp args'
|
||||
required: false
|
||||
delete_remote_files:
|
||||
description: 'This operation will delete all files in the remote path before upload. Please be careful set this to true'
|
||||
required: false
|
||||
default: false
|
||||
|
||||
|
||||
runs:
|
||||
@@ -39,7 +45,9 @@ runs:
|
||||
- ${{ inputs.ssh_private_key }}
|
||||
- ${{ inputs.local_path }}
|
||||
- ${{ inputs.remote_path }}
|
||||
- ${{ inputs.sftp_only }}
|
||||
- ${{ inputs.args }}
|
||||
- ${{ inputs.delete_remote_files }}
|
||||
|
||||
branding:
|
||||
icon: 'upload-cloud'
|
||||
|
||||
@@ -7,18 +7,34 @@ set -eu
|
||||
TEMP_SSH_PRIVATE_KEY_FILE='../private_key.pem'
|
||||
TEMP_SFTP_FILE='../sftp'
|
||||
|
||||
if [ -z "$6" ]; then
|
||||
echo 'remote_path is empty'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# keep string format
|
||||
printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE
|
||||
# avoid Permissions too open
|
||||
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE
|
||||
|
||||
echo 'sftp start'
|
||||
if test $9 == "true";then
|
||||
echo 'Start delete remote files'
|
||||
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 rm -rf $6
|
||||
fi
|
||||
|
||||
if test $7 = "true"; then
|
||||
echo "Connection via sftp protocol only, skip the command to create a directory"
|
||||
else
|
||||
echo 'SSH Start'
|
||||
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
|
||||
fi
|
||||
|
||||
echo 'SFTP Start'
|
||||
# create a temporary file containing sftp commands
|
||||
printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE
|
||||
#-o StrictHostKeyChecking=no avoid Host key verification failed.
|
||||
sftp -b $TEMP_SFTP_FILE -P $3 $7 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2
|
||||
sftp -b $TEMP_SFTP_FILE -P $3 $8 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2
|
||||
|
||||
echo 'deploy success'
|
||||
echo 'Deploy Success'
|
||||
exit 0
|
||||
|
||||
|
||||
BIN
resource/reactExample.jpg
Normal file
BIN
resource/reactExample.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
BIN
resource/secret.jpg
Normal file
BIN
resource/secret.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 176 KiB |
BIN
resource/umiExample.jpg
Normal file
BIN
resource/umiExample.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
Reference in New Issue
Block a user