initial commit of actions
This commit is contained in:
commit
949ece5785
44660 changed files with 12034344 additions and 0 deletions
18
up9cloud/action-rsync-v1/.github/workflows/main.yml
vendored
Normal file
18
up9cloud/action-rsync-v1/.github/workflows/main.yml
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
on: [push]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: A job for testing
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Sync
|
||||
id: rsync
|
||||
uses: up9cloud/action-rsync@master
|
||||
env:
|
||||
HOST: ${{secrets.DEPLOY_HOST}}
|
||||
KEY: ${{secrets.DEPLOY_SSH_KEY}}
|
||||
TARGET: /tmp/action-rsync/
|
||||
VERBOSE: true
|
||||
PRE_SCRIPT: "echo I ❤️ this action!\ndate -u --rfc-3339=ns"
|
||||
POST_SCRIPT: "ls -al /tmp/action-rsync && date -u --rfc-3339=ns"
|
||||
5
up9cloud/action-rsync-v1/Dockerfile
Normal file
5
up9cloud/action-rsync-v1/Dockerfile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
FROM sstc/rsync
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
21
up9cloud/action-rsync-v1/LICENSE
Normal file
21
up9cloud/action-rsync-v1/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 up9cloud
|
||||
|
||||
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.
|
||||
67
up9cloud/action-rsync-v1/README.md
Normal file
67
up9cloud/action-rsync-v1/README.md
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# action-rsync
|
||||
|
||||
- Alpine based image with installed rsync.
|
||||
- Basic pre and post scripts support.
|
||||
- Pure docker container, no github format things.
|
||||
|
||||
## Inputs, Outputs, ...
|
||||
|
||||
None and Pure 😊
|
||||
|
||||
## Usage
|
||||
|
||||
```yml
|
||||
on: [push]
|
||||
jobs:
|
||||
rsync:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Must checkout first, otherwise would get empty folder, see https://github.com/actions/checkout
|
||||
- uses: actions/checkout@v2
|
||||
- name: Deploy to my ❤️
|
||||
uses: up9cloud/action-rsync@v1
|
||||
env:
|
||||
# Required
|
||||
HOST: example.com
|
||||
KEY: ${{secrets.DEPLOY_SSH_KEY}} # ssh private key
|
||||
TARGET: /target/dir/ # target folder or file
|
||||
|
||||
# Optional (with `default` values)
|
||||
VERBOSE: false # set it true if you want some tips
|
||||
USER: root # target server ssh user
|
||||
PORT: 22 # target server ssh port
|
||||
ARGS: -avz --delete --exclude=/.git/ --exclude=/.github/ # rsync arguments
|
||||
SSH_ARGS: '-p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet' # ssh arguments, if you set this, the PORT would be ignored.
|
||||
SOURCE: ./ # source folder or file
|
||||
PRE_SCRIPT: "" # pre script runs on target server, target server must support `mktemp` command
|
||||
POST_SCRIPT: "" # post script runs on target server, target server must support `mktemp` command
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```yml
|
||||
on: [push]
|
||||
jobs:
|
||||
rsync:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Deploy to my ❤️
|
||||
uses: up9cloud/action-rsync@v1
|
||||
env:
|
||||
HOST: example.com
|
||||
KEY: ${{secrets.DEPLOY_SSH_KEY}}
|
||||
TARGET: /app/hello-service/
|
||||
|
||||
VERBOSE: true
|
||||
USER: ubuntu
|
||||
# PORT: 2222 # no need to set this, because of $SSH_ARGS
|
||||
ARGS: -az --exclude=/.git/
|
||||
SSH_ARGS: '-p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
||||
SOURCE: ./public/
|
||||
|
||||
PRE_SCRIPT: "echo start at: \n date -u --rfc-3339=ns"
|
||||
POST_SCRIPT: "echo done at: && date -u --rfc-3339=ns"
|
||||
```
|
||||
|
||||
> See 1 more example: https://github.com/up9cloud/action-rsync/blob/master/.github/workflows/main.yml
|
||||
9
up9cloud/action-rsync-v1/action.yml
Normal file
9
up9cloud/action-rsync-v1/action.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# action.yml
|
||||
name: 'Action - rsync'
|
||||
description: 'Alpine based image with installed rsync, basic pre and post scripts support. Pure docker, minimize github things.'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
branding:
|
||||
icon: 'star'
|
||||
color: 'yellow'
|
||||
101
up9cloud/action-rsync-v1/entrypoint.sh
Executable file
101
up9cloud/action-rsync-v1/entrypoint.sh
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
function log() {
|
||||
if [ "$VERBOSE" == "true" ]; then
|
||||
echo [action-rsync] "$@"
|
||||
fi
|
||||
}
|
||||
function die() {
|
||||
echo [action-rsync] "$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -z "$VERBOSE" ]; then
|
||||
VERBOSE=false
|
||||
fi
|
||||
|
||||
if [ -z "$HOST" ]; then
|
||||
die "Must specify \$HOST! (target host)"
|
||||
fi
|
||||
|
||||
if [ -z "$TARGET" ]; then
|
||||
die "Must specify \$TARGET! (target folder)"
|
||||
fi
|
||||
|
||||
if [ -z "$KEY" ]; then
|
||||
die "Must provide \$KEY! (ssh private key)"
|
||||
fi
|
||||
|
||||
if [ -z "$USER" ]; then
|
||||
USER="root"
|
||||
log "\$USER not specified, using default user '$USER'."
|
||||
fi
|
||||
|
||||
if [ -z "$PORT" ]; then
|
||||
PORT="22"
|
||||
log "\$PORT not specified, using default port $PORT."
|
||||
fi
|
||||
|
||||
if [ -z "$SOURCE" ]; then
|
||||
SOURCE="./"
|
||||
log "\$SOURCE not specified, using default source folder '$SOURCE'."
|
||||
fi
|
||||
|
||||
if [ -z "$ARGS" ]; then
|
||||
ARGS="-azv --delete --exclude=/.git/ --exclude=/.github/"
|
||||
log "\$ARGS not specified, using default rsync arguments '$ARGS'."
|
||||
fi
|
||||
|
||||
if [ -z "$SSH_ARGS" ]; then
|
||||
SSH_ARGS="-p $PORT -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet"
|
||||
log "\$SSH_ARGS not specified, using default ssh arguments '$SSH_ARGS'."
|
||||
else
|
||||
log "You spcified \$SSH_ARGS, so \$PORT will be ignored."
|
||||
fi
|
||||
|
||||
# Prepare
|
||||
mkdir -p "$HOME/.ssh"
|
||||
echo "$KEY" > "$HOME/.ssh/key"
|
||||
chmod 600 "$HOME/.ssh/key"
|
||||
|
||||
if [ -n "$GITHUB_WORKSPACE" ]; then
|
||||
cd $GITHUB_WORKSPACE
|
||||
fi
|
||||
|
||||
# Execute
|
||||
cmd_ssh=$(printf "ssh -i %s %s" "$HOME/.ssh/key" "$SSH_ARGS")
|
||||
cmd_rsync=$(printf "rsync %s -e '%s'" "$ARGS" "$cmd_ssh")
|
||||
if [ -n "$PRE_SCRIPT" ]; then
|
||||
log ========== Pre script starting ==========
|
||||
eval "$cmd_ssh" $USER@$HOST 'mktemp' > /tmp/target_mktemp_output
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Using \$PRE_SCRIPT, target server must support 'mktemp' command"
|
||||
fi
|
||||
target_pre_file_path=`cat /tmp/target_mktemp_output`
|
||||
local_pre_file_path=`mktemp`
|
||||
echo -e "$PRE_SCRIPT" > $local_pre_file_path
|
||||
eval "$cmd_rsync" $local_pre_file_path $USER@$HOST:$target_pre_file_path
|
||||
log ========== Pre script sent ==========
|
||||
eval "$cmd_ssh" $USER@$HOST "sh $target_pre_file_path"
|
||||
log ========== Pre script executed ==========
|
||||
eval "$cmd_ssh" $USER@$HOST "rm $target_pre_file_path"
|
||||
log ========== Pre script removed ==========
|
||||
fi
|
||||
eval "$cmd_rsync" $SOURCE $USER@$HOST:$TARGET
|
||||
if [ -n "$POST_SCRIPT" ]; then
|
||||
log ========== Post script starting ==========
|
||||
eval "$cmd_ssh" $USER@$HOST 'mktemp' > /tmp/target_mktemp_output
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Using \$POST_SCRIPT, target server must support 'mktemp' command"
|
||||
fi
|
||||
target_post_file_path=`cat /tmp/target_mktemp_output`
|
||||
local_post_file_path=`mktemp`
|
||||
echo -e "$POST_SCRIPT" > $local_post_file_path
|
||||
eval "$cmd_rsync" $local_post_file_path $USER@$HOST:$target_post_file_path
|
||||
log ========== Post script sent ==========
|
||||
eval "$cmd_ssh" $USER@$HOST "sh $target_post_file_path"
|
||||
log ========== Post script executed ==========
|
||||
eval "$cmd_ssh" $USER@$HOST "rm $target_post_file_path"
|
||||
log ========== Post script removed ==========
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue