Switch to password based authentication

pull/15/head
Julian Groß 2021-05-20 13:52:36 +02:00
parent 28d6168ebf
commit 1151d5f266
4 changed files with 46 additions and 56 deletions

View File

@ -1,15 +1,14 @@
# 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
#Make sure to make you entrypoint.sh file executable:
RUN chmod 777 entrypoint.sh
RUN chmod +x entrypoint.sh
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`)
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -1,36 +1,34 @@
# 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`部署你的项目到服务器上,`仅支持密钥对连接`
> [使用Github Action 部署项目到云服务器](https://zhuanlan.zhihu.com/p/107545396)
Based on SFTP-Deploy-Action https://github.com/wlixcc/SFTP-Deploy-Action
## Inputs
### `username`
**Required** sftp username.
**Required** SSH username.
### `server`
**Required** sftp server address.
**Required** SSH server address.
### `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
![](./resource/secret.jpg)
### `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`
**Required** remote_path
@ -39,7 +37,7 @@ sftp srever port , default `22`
args of sftp cmd, E.g.`-o ConnectTimeout=5`
## Action Example
## Action Example
on: [push]
@ -56,7 +54,7 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
with:
username: 'root'
server: 'your server ip'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
local_path: './static/*'
remote_path: '/var/www/app'
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
on: [push]
jobs:
deploy_job:
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
- 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.0
with:
@ -90,14 +88,14 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
local_path: './build/*'
remote_path: '/var/www/react-app'
args: '-o ConnectTimeout=5'
![](./resource/reactExample.jpg)
## 2.Deploy Umi App Example (Ant Design Pro)
name: continuous deployment
on: [push]
jobs:
deploy_job:
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
- name: Checkout
uses: actions/checkout@v2
- name: Install umi
run: yarn global add 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.0
with:
@ -125,8 +123,8 @@ args of sftp cmd, E.g.`-o ConnectTimeout=5`
remote_path: '/var/www/umiapp'
args: '-o ConnectTimeout=5'
![](./resource/umiExample.jpg)

View File

@ -1,26 +1,26 @@
# action.yml
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:
username:
description: 'username'
required: true
server:
description: 'your sftp server'
server:
description: 'your SSH server'
required: true
port:
description: 'your sftp server port, default to 22'
port:
description: 'your SSH server port, defaults to 22'
required: true
default: "22"
ssh_private_key:
description: 'you can copy private_key from your *.pem file, keep format'
ssh_password:
description: 'you SSH password'
required: true
local_path:
description: 'will put all file under this path'
description: 'will transfer all files from this path'
required: true
default: ./*
remote_path:
description: 'files will copy to under remote_path'
description: 'files will be transferred to this path'
required: true
default: /
@ -36,11 +36,11 @@ runs:
- ${{ inputs.username }}
- ${{ inputs.server }}
- ${{ inputs.port }}
- ${{ inputs.ssh_private_key }}
- ${{ inputs.ssh_password }}
- ${{ inputs.local_path }}
- ${{ inputs.remote_path }}
- ${{ inputs.args }}
branding:
icon: 'upload-cloud'
icon: 'upload-cloud'
color: 'purple'

View File

@ -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 -eu
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'
echo 'Connecting to SSH server and creating directory..'
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
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
#-o StrictHostKeyChecking=no to avoid "Host key verification failed".
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