Switch to password based authentication
parent
28d6168ebf
commit
1151d5f266
|
|
@ -1,15 +1,14 @@
|
||||||
# Container image that runs your code
|
# 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
|
# Copies your code file from your action repository to the filesystem path `/` of the container
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
#Make sure to make you entrypoint.sh file executable:
|
#Make sure to make you entrypoint.sh file executable:
|
||||||
RUN chmod 777 entrypoint.sh
|
RUN chmod +x entrypoint.sh
|
||||||
|
|
||||||
RUN apk update
|
RUN apk update
|
||||||
RUN apk add --no-cache openssh
|
RUN apk add --no-cache sshpass openssh-client
|
||||||
|
|
||||||
|
|
||||||
# Code file to execute when the docker container starts up (`entrypoint.sh`)
|
# Code file to execute when the docker container starts up (`entrypoint.sh`)
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
|
||||||
50
README.md
50
README.md
|
|
@ -1,36 +1,34 @@
|
||||||
# SFTP Deploy action
|
# SFTP Deploy action
|
||||||
|
|
||||||
> Use this action to deploy your files to server using `SSH Private Key`
|
Use this action to deploy your files to an SSH server using password authentication.
|
||||||
|
|
||||||
> 使用此`action`部署你的项目到服务器上,`仅支持密钥对连接`
|
Based on SFTP-Deploy-Action https://github.com/wlixcc/SFTP-Deploy-Action
|
||||||
|
|
||||||
> [使用Github Action 部署项目到云服务器](https://zhuanlan.zhihu.com/p/107545396)
|
|
||||||
|
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
### `username`
|
### `username`
|
||||||
|
|
||||||
**Required** sftp username.
|
**Required** SSH username.
|
||||||
|
|
||||||
### `server`
|
### `server`
|
||||||
|
|
||||||
**Required** sftp server address.
|
**Required** SSH server address.
|
||||||
|
|
||||||
### `port`
|
### `port`
|
||||||
|
|
||||||
sftp srever port , default `22`
|
SSH server port , default `22`
|
||||||
|
|
||||||
### `ssh_private_key`
|
### `ssh_password`
|
||||||
|
|
||||||
**Required** you can copy private_key from your `ssh_private_key.pem file`, keep format, and save at`repo/settings/secrets`
|
**Required** SSH password
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### `local_path`
|
### `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).
|
**Required** `local_path` of your project, if you want transfer a single file:use a path like `./myfile`, if you want transfer a directory: use a path like `./static/*`, it will transfer all files under the `static` directory. Defaults to `./*`(will transfer all files in your repo).
|
||||||
|
|
||||||
### `remote_path`
|
### `remote_path`
|
||||||
**Required** remote_path
|
**Required** remote_path
|
||||||
|
|
@ -39,7 +37,7 @@ sftp srever port , default `22`
|
||||||
args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
|
|
||||||
|
|
||||||
## Action Example
|
## Action Example
|
||||||
|
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
@ -56,7 +54,7 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
with:
|
with:
|
||||||
username: 'root'
|
username: 'root'
|
||||||
server: 'your server ip'
|
server: 'your server ip'
|
||||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
local_path: './static/*'
|
local_path: './static/*'
|
||||||
remote_path: '/var/www/app'
|
remote_path: '/var/www/app'
|
||||||
args: '-o ConnectTimeout=5'
|
args: '-o ConnectTimeout=5'
|
||||||
|
|
@ -66,7 +64,7 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
> If you use nginx, all you need to do is upload the static files to the server after the project is built
|
> If you use nginx, all you need to do is upload the static files to the server after the project is built
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy_job:
|
deploy_job:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -75,12 +73,12 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
# To use this repository's private action, you must check out the repository
|
# To use this repository's private action, you must check out the repository
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
- name: Build
|
- name: Build
|
||||||
run: yarn build
|
run: yarn build
|
||||||
|
|
||||||
- name: deploy file to server
|
- name: deploy file to server
|
||||||
uses: wlixcc/SFTP-Deploy-Action@v1.0
|
uses: wlixcc/SFTP-Deploy-Action@v1.0
|
||||||
with:
|
with:
|
||||||
|
|
@ -90,14 +88,14 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
local_path: './build/*'
|
local_path: './build/*'
|
||||||
remote_path: '/var/www/react-app'
|
remote_path: '/var/www/react-app'
|
||||||
args: '-o ConnectTimeout=5'
|
args: '-o ConnectTimeout=5'
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 2.Deploy Umi App Example (Ant Design Pro)
|
## 2.Deploy Umi App Example (Ant Design Pro)
|
||||||
|
|
||||||
name: continuous deployment
|
name: continuous deployment
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy_job:
|
deploy_job:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -106,15 +104,15 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
# To use this repository's private action, you must check out the repository
|
# To use this repository's private action, you must check out the repository
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install umi
|
- name: Install umi
|
||||||
run: yarn global add umi
|
run: yarn global add umi
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
- name: Build
|
- name: Build
|
||||||
run: yarn build
|
run: yarn build
|
||||||
|
|
||||||
- name: deploy file to server
|
- name: deploy file to server
|
||||||
uses: wlixcc/SFTP-Deploy-Action@v1.0
|
uses: wlixcc/SFTP-Deploy-Action@v1.0
|
||||||
with:
|
with:
|
||||||
|
|
@ -125,8 +123,8 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
|
||||||
remote_path: '/var/www/umiapp'
|
remote_path: '/var/www/umiapp'
|
||||||
args: '-o ConnectTimeout=5'
|
args: '-o ConnectTimeout=5'
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
22
action.yml
22
action.yml
|
|
@ -1,26 +1,26 @@
|
||||||
# action.yml
|
# action.yml
|
||||||
name: 'SFTP Deploy'
|
name: 'SFTP Deploy'
|
||||||
description: 'Deploy file to your server use sftp & ssh private key'
|
description: 'Deploy files to your server with SFTP and password authenticated SSH'
|
||||||
inputs:
|
inputs:
|
||||||
username:
|
username:
|
||||||
description: 'username'
|
description: 'username'
|
||||||
required: true
|
required: true
|
||||||
server:
|
server:
|
||||||
description: 'your sftp server'
|
description: 'your SSH server'
|
||||||
required: true
|
required: true
|
||||||
port:
|
port:
|
||||||
description: 'your sftp server port, default to 22'
|
description: 'your SSH server port, defaults to 22'
|
||||||
required: true
|
required: true
|
||||||
default: "22"
|
default: "22"
|
||||||
ssh_private_key:
|
ssh_password:
|
||||||
description: 'you can copy private_key from your *.pem file, keep format'
|
description: 'you SSH password'
|
||||||
required: true
|
required: true
|
||||||
local_path:
|
local_path:
|
||||||
description: 'will put all file under this path'
|
description: 'will transfer all files from this path'
|
||||||
required: true
|
required: true
|
||||||
default: ./*
|
default: ./*
|
||||||
remote_path:
|
remote_path:
|
||||||
description: 'files will copy to under remote_path'
|
description: 'files will be transferred to this path'
|
||||||
required: true
|
required: true
|
||||||
default: /
|
default: /
|
||||||
|
|
||||||
|
|
@ -36,11 +36,11 @@ runs:
|
||||||
- ${{ inputs.username }}
|
- ${{ inputs.username }}
|
||||||
- ${{ inputs.server }}
|
- ${{ inputs.server }}
|
||||||
- ${{ inputs.port }}
|
- ${{ inputs.port }}
|
||||||
- ${{ inputs.ssh_private_key }}
|
- ${{ inputs.ssh_password }}
|
||||||
- ${{ inputs.local_path }}
|
- ${{ inputs.local_path }}
|
||||||
- ${{ inputs.remote_path }}
|
- ${{ inputs.remote_path }}
|
||||||
- ${{ inputs.args }}
|
- ${{ inputs.args }}
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'upload-cloud'
|
icon: 'upload-cloud'
|
||||||
color: 'purple'
|
color: 'purple'
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,18 @@
|
||||||
#set -e at the top of your script will make the script exit with an error whenever an error occurs (and is not explicitly handled)
|
#set -e at the top of your script will make the script exit with an error whenever an error occurs (and is not explicitly handled)
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
echo 'Connecting to SSH server and creating directory..'
|
||||||
TEMP_SSH_PRIVATE_KEY_FILE='../private_key.pem'
|
|
||||||
TEMP_SFTP_FILE='../sftp'
|
|
||||||
|
|
||||||
# keep string format
|
|
||||||
printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE
|
|
||||||
# avoid Permissions too open
|
|
||||||
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE
|
|
||||||
|
|
||||||
echo 'ssh start'
|
|
||||||
|
|
||||||
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
|
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
|
||||||
|
|
||||||
echo 'sftp start'
|
echo 'Connection to SSH server and directory creation finished successfully!'
|
||||||
|
|
||||||
|
echo 'Starting file transfer..'
|
||||||
# create a temporary file containing sftp commands
|
# create a temporary file containing sftp commands
|
||||||
printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE
|
printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE
|
||||||
#-o StrictHostKeyChecking=no avoid Host key verification failed.
|
#-o StrictHostKeyChecking=no to avoid "Host key verification failed".
|
||||||
sftp -b $TEMP_SFTP_FILE -P $3 $7 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2
|
sshpass -p $4 sftp -b $TEMP_SFTP_FILE -P $3 $7 -o StrictHostKeyChecking=no $1@$2
|
||||||
|
|
||||||
echo 'deploy success'
|
echo 'File transfer finished successfully!'
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue