Compare commits

...

18 Commits

Author SHA1 Message Date
Michael de Wit
ea6b079c59 Merge pull request #33 from mortbauer/master
add option log_level
2022-07-11 12:39:48 +02:00
Martin Ortbauer
d199cb4ecd add option log_level 2022-07-11 12:28:21 +02:00
Michael de Wit
b311cd7457 Update docs for Drone v1, remove docs for older versions, update base image to Alpine 3.13 2021-02-08 12:47:38 +01:00
Michael de Wit
21497cd5b8 Merge pull request #26 from tungquach/master
Update 1-DOCS.md
2020-04-23 12:18:44 +02:00
Tung Quach
c8707befb6 Update 1-DOCS.md
Fix the wrong config name for list of commands to execute on remote machines after rsync occurs
2020-04-22 21:02:10 +07:00
Michael de Wit
098162e766 Merge pull request #21 from jessequinn/master
Pre and Post Script
2019-12-01 14:38:15 +01:00
Jesse Quinn
d389abaac3 updated DOCs 2019-11-29 10:15:02 -03:00
Michael de Wit
cb1a3e5609 Revert "removed not working ssh key type detection"
This reverts commit 1723444289.
2019-11-29 10:53:23 +01:00
Michael de Wit
c1d7056ba3 Merge pull request #20 from imolein/patch2
removed not working ssh key type detection
2019-11-29 09:24:30 +01:00
Michael de Wit
40993ada24 Merge pull request #19 from imolein/patch1
raised alpine version
2019-11-29 09:18:51 +01:00
Jesse Quinn
9f746c264d updated README 2019-11-28 07:18:58 -03:00
Jesse Quinn
be77164f55 updated for PR concerns 2019-11-28 07:16:46 -03:00
Jesse Quinn
9e935426bd updated code to new maintainer
and using latest alpine
2019-11-27 17:22:48 -03:00
Jesse Quinn
8acd960634 updated DOCs 2019-11-27 09:59:20 -03:00
Jesse Quinn
453b74ab9c updated gitignore 2019-11-27 09:56:53 -03:00
Jesse Quinn
7f45331dd3 added gitignore and pre and post script possibilities 2019-11-27 09:32:11 -03:00
Sebastian Huebner
1723444289 removed not working ssh key type detection 2019-10-01 14:43:24 +02:00
Sebastian Huebner
3a19d88d79 Dockerfile: raised alpine version 2019-10-01 14:31:56 +02:00
5 changed files with 45 additions and 129 deletions

100
0-DOCS.md
View File

@@ -1,100 +0,0 @@
Use the Rsync plugin to synchronize files to remote hosts, and execute arbitrary commands on those hosts.
## Config
The following parameters are used to configure the plugin:
- **user** - user to log in as on the remote machines, defaults to `root`
- **key** - private SSH key for the remote machines
- **hosts** - hostnames or ip-addresses of the remote machines
- **port** - port to connect to on the remote machines, defaults to `22`
- **source** - source folder to synchronize from, defaults to `./`
- **target** - target folder on remote machines to synchronize to
- **include** - rsync include filter
- **exclude** - rsync exclude filter
- **recursive** - recursively synchronize, defaults to `false`
- **delete** - delete target folder contents, defaults to `false`
- **script** - list of commands to execute on remote machines
## Secrets
The following secrets can be used to secure the sensitive parts of your configuration:
- **rsync_key** - private SSH key for the remote machines
- **rsync_user** - user to log in as on the remote machines
It is highly recommended to put your private key into a secret (`rsync_key`) so it is not exposed to users. This can be done using the drone-cli:
```sh
drone secret add \
--repository your/repo \
--name rsync_key \
--value @./id_rsa \
--image drillster/drone-rsync
```
Add the secret to your `.drone.yml`:
```yaml
pipeline:
rsync:
image: drillster/drone-rsync
user: some-user
hosts:
- remote1
source: ./dist
target: ~/packages
secrets: [ rsync_key ]
```
See the [Secret Guide](http://docs.drone.io/manage-secrets/) for additional information on secrets.
## Examples
```yaml
pipeline:
rsync:
image: drillster/drone-rsync
hosts:
- remote1
- remote2
source: ./dist
target: ~/packages
include:
- "app.tar.gz"
- "app.tar.gz.md5"
exclude:
- "**.*"
script:
- cd ~/packages
- md5sum -c app.tar.gz.md5
- tar -xf app.tar.gz -C ~/app
secrets: [ rsync_user, rsync_key ]
```
The example above illustrates a situation where an app package (`app.tar.gz`) will be deployed to 2 remote hosts (`remote1` and `remote2`). An md5 checksum will be deployed as well. After deploying, the md5 checksum is used to check the deployed package. If successful the package is extracted.
## Important
The script passed to **script** will be executed on remote machines directly after rsync completes to deploy the files. It will be executed step by step until a command returns a non-zero exit-code. If this happens, the entire plugin will exit and fail the build.
## Secrets in Drone 0.5
Secret injection has changed for Drone 0.6 and up. To use this plugin with Drone 0.5, use:
```sh
drone secret add octocat/hello-world RSYNC_KEY @path/to/.ssh/id_rsa
```
to add the secret. Then add the secret to your `.drone.yml`:
```yaml
pipeline:
rsync:
image: drillster/drone-rsync
user: some-user
key: ${RSYNC_KEY}
hosts:
- remote1
source: ./dist
target: ~/packages
```
and then sign your configuration using:
```sh
drone sign octocat/hello-world
```

View File

@@ -12,12 +12,10 @@ The following parameters are used to configure the plugin:
- **exclude** - rsync exclude filter
- **recursive** - recursively synchronize, defaults to `false`
- **delete** - delete target folder contents, defaults to `false`
- **script** - list of commands to execute on remote machines
## Secrets
The following secrets can be used to secure the sensitive parts of your configuration:
- **rsync_key** - private SSH key for the remote machines
- **rsync_user** - user to log in as on the remote machines
- **args** - instruct plugin to use these additional rsync CLI arguments, example: `"--blocking-io"`
- **prescript** - list of commands to execute on remote machines before rsync occurs
- **script** - list of commands to execute on remote machines after rsync occurs
- **log_level** - ssh log level, defaults to quiet
It is highly recommended to put your private key into a secret (`rsync_key`) so it is not exposed to users. This can be done using the drone-cli:
@@ -25,7 +23,7 @@ It is highly recommended to put your private key into a secret (`rsync_key`) so
drone secret add \
--repository your/repo \
--name rsync_key \
--value @./id_rsa \
--data @./id_rsa \
```
Add the secret to your `.drone.yml`:
@@ -35,11 +33,10 @@ kind: pipeline
steps:
- name: rsync
image: drillster/drone-rsync
environment:
RSYNC_KEY:
from_secret: rsync_key
settings:
user: some-user
key:
from_secret: rsync_key
hosts:
- remote1
source: ./dist
@@ -57,15 +54,14 @@ name: default
steps:
- name: rsync
image: drillster/drone-rsync
environment:
RSYNC_KEY:
from_secret: rsync_key
RSYNC_USER:
from_secret: rsync_user
settings:
hosts:
- remote1
- remote2
user:
from_secret: rsync_user
key:
from_secret: rsync_key
source: ./dist
target: ~/packages
include:
@@ -73,7 +69,11 @@ steps:
- "app.tar.gz.md5"
exclude:
- "**.*"
script:
prescript:
- cd ~/packages
- md5sum -c app.tar.gz.md5
- tar -xf app.tar.gz -C ~/app
script:
- cd ~/packages
- md5sum -c app.tar.gz.md5
- tar -xf app.tar.gz -C ~/app

View File

@@ -1,7 +1,6 @@
FROM alpine:3.4
MAINTAINER Michael de Wit <michael@drillster.com>
FROM alpine:3.13
RUN apk add --no-cache ca-certificates bash openssh-client rsync
RUN apk add --no-cache --update ca-certificates bash openssh-client rsync
COPY upload.sh /usr/local/
ENTRYPOINT ["/usr/local/upload.sh"]

View File

@@ -3,10 +3,7 @@
This is a pure Bash [Drone](https://github.com/drone/drone) >= 0.5 plugin to sync files to remote hosts.
For more information on how to use the plugin, please take a look at the docs:
- For Drone CI versions `< 1` : https://github.com/Drillster/drone-rsync/blob/master/0-DOCS.md
- For Drone CI versions `>= 1` : https://github.com/Drillster/drone-rsync/blob/master/1-DOCS.md
For more information on how to use the plugin, please take a look at [the docs](https://github.com/Drillster/drone-rsync/blob/master/DOCS.md).
## Docker
Build the docker image by running:
@@ -24,7 +21,8 @@ docker run --rm \
-e PLUGIN_HOSTS="127.0.0.1, 127.0.0.2, 127.0.0.3" \
-e PLUGIN_PORTS="22, 23, 24" \
-e PLUGIN_TARGET="./" \
-e PLUGIN_SCRIPT="echo \"Done!\"" \
-e PLUGIN_PRESCRIPT="echo \"Prescript Done!\"" \
-e PLUGIN_SCRIPT="echo \"Postscript Done!\"" \
-e PLUGIN_ARGS="--blocking-io" \
-v $(pwd):$(pwd) \
-w $(pwd) \

View File

@@ -8,6 +8,7 @@ if [ -z "$PLUGIN_TARGET" ]; then
echo "Specify a target!"
exit 1
fi
DEFAULT_PORT=$PLUGIN_PORT
if [ -z "$PLUGIN_PORT" ]; then
echo "Port not specified, using default port 22!"
@@ -45,6 +46,12 @@ else
ARGS=$PLUGIN_ARGS
fi
if [ -z "$PLUGIN_LOG_LEVEL" ]; then
LOG_LEVEL=quiet
else
LOG_LEVEL=$PLUGIN_LOG_LEVEL
fi
# Building rsync command
expr="rsync -az $ARGS"
@@ -56,7 +63,7 @@ if [[ -n "$PLUGIN_DELETE" && "$PLUGIN_DELETE" == "true" ]]; then
expr="$expr --del"
fi
expr="$expr -e 'ssh -p %s -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o StrictHostKeyChecking=no'"
expr="$expr -e 'ssh -p %s -o UserKnownHostsFile=/dev/null -o LogLevel=$LOG_LEVEL -o StrictHostKeyChecking=no'"
# Include
IFS=','; read -ra INCLUDE <<< "$PLUGIN_INCLUDE"
@@ -100,10 +107,14 @@ fi
echo "$SSH_KEY" > $keyfile
chmod 0600 $keyfile
# Parse SSH commands
function join_with { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
# Parse SSH precommands
IFS=','; read -ra COMMANDS <<< "$PLUGIN_PRESCRIPT"
prescript=$(join_with ' && ' "${COMMANDS[@]}")
# Parse SSH postcommands
IFS=','; read -ra COMMANDS <<< "$PLUGIN_SCRIPT"
script=$(join_with ' && ' "${COMMANDS[@]}")
postscript=$(join_with ' && ' "${COMMANDS[@]}")
# Run rsync
IFS=','; read -ra HOSTS <<< "$PLUGIN_HOSTS"
@@ -119,13 +130,21 @@ do
PORT=$DEFAULT_PORT
fi
echo $(printf "%s" "$ $(printf "$expr" "$PORT") $USER@$HOST:$PLUGIN_TARGET ...")
if [ -n "$PLUGIN_PRESCRIPT" ]; then
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST ...")
echo $(printf "%s" " > $prescript ...")
eval "ssh -p $PORT $USER@$HOST '$prescript'"
result=$(($result+$?))
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST result: $?")
if [ "$result" -gt "0" ]; then exit $result; fi
fi
eval "$(printf "$expr" "$PORT") $USER@$HOST:$PLUGIN_TARGET"
result=$(($result+$?))
if [ "$result" -gt "0" ]; then exit $result; fi
if [ -n "$PLUGIN_SCRIPT" ]; then
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST ...")
echo $(printf "%s" " > $script ...")
eval "ssh -p $PORT $USER@$HOST '$script'"
echo $(printf "%s" " > $postscript ...")
eval "ssh -p $PORT $USER@$HOST '$postscript'"
result=$(($result+$?))
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST result: $?")
if [ "$result" -gt "0" ]; then exit $result; fi