Compare commits
18 Commits
d54b54d36d
...
ea6b079c59
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea6b079c59 | ||
|
|
d199cb4ecd | ||
|
|
b311cd7457 | ||
|
|
21497cd5b8 | ||
|
|
c8707befb6 | ||
|
|
098162e766 | ||
|
|
d389abaac3 | ||
|
|
cb1a3e5609 | ||
|
|
c1d7056ba3 | ||
|
|
40993ada24 | ||
|
|
9f746c264d | ||
|
|
be77164f55 | ||
|
|
9e935426bd | ||
|
|
8acd960634 | ||
|
|
453b74ab9c | ||
|
|
7f45331dd3 | ||
|
|
1723444289 | ||
|
|
3a19d88d79 |
100
0-DOCS.md
100
0-DOCS.md
@@ -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
|
|
||||||
```
|
|
||||||
@@ -12,12 +12,10 @@ The following parameters are used to configure the plugin:
|
|||||||
- **exclude** - rsync exclude filter
|
- **exclude** - rsync exclude filter
|
||||||
- **recursive** - recursively synchronize, defaults to `false`
|
- **recursive** - recursively synchronize, defaults to `false`
|
||||||
- **delete** - delete target folder contents, defaults to `false`
|
- **delete** - delete target folder contents, defaults to `false`
|
||||||
- **script** - list of commands to execute on 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
|
||||||
## Secrets
|
- **script** - list of commands to execute on remote machines after rsync occurs
|
||||||
The following secrets can be used to secure the sensitive parts of your configuration:
|
- **log_level** - ssh log level, defaults to quiet
|
||||||
- **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:
|
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 \
|
drone secret add \
|
||||||
--repository your/repo \
|
--repository your/repo \
|
||||||
--name rsync_key \
|
--name rsync_key \
|
||||||
--value @./id_rsa \
|
--data @./id_rsa \
|
||||||
```
|
```
|
||||||
|
|
||||||
Add the secret to your `.drone.yml`:
|
Add the secret to your `.drone.yml`:
|
||||||
@@ -35,11 +33,10 @@ kind: pipeline
|
|||||||
steps:
|
steps:
|
||||||
- name: rsync
|
- name: rsync
|
||||||
image: drillster/drone-rsync
|
image: drillster/drone-rsync
|
||||||
environment:
|
|
||||||
RSYNC_KEY:
|
|
||||||
from_secret: rsync_key
|
|
||||||
settings:
|
settings:
|
||||||
user: some-user
|
user: some-user
|
||||||
|
key:
|
||||||
|
from_secret: rsync_key
|
||||||
hosts:
|
hosts:
|
||||||
- remote1
|
- remote1
|
||||||
source: ./dist
|
source: ./dist
|
||||||
@@ -57,15 +54,14 @@ name: default
|
|||||||
steps:
|
steps:
|
||||||
- name: rsync
|
- name: rsync
|
||||||
image: drillster/drone-rsync
|
image: drillster/drone-rsync
|
||||||
environment:
|
|
||||||
RSYNC_KEY:
|
|
||||||
from_secret: rsync_key
|
|
||||||
RSYNC_USER:
|
|
||||||
from_secret: rsync_user
|
|
||||||
settings:
|
settings:
|
||||||
hosts:
|
hosts:
|
||||||
- remote1
|
- remote1
|
||||||
- remote2
|
- remote2
|
||||||
|
user:
|
||||||
|
from_secret: rsync_user
|
||||||
|
key:
|
||||||
|
from_secret: rsync_key
|
||||||
source: ./dist
|
source: ./dist
|
||||||
target: ~/packages
|
target: ~/packages
|
||||||
include:
|
include:
|
||||||
@@ -73,7 +69,11 @@ steps:
|
|||||||
- "app.tar.gz.md5"
|
- "app.tar.gz.md5"
|
||||||
exclude:
|
exclude:
|
||||||
- "**.*"
|
- "**.*"
|
||||||
script:
|
prescript:
|
||||||
|
- cd ~/packages
|
||||||
|
- md5sum -c app.tar.gz.md5
|
||||||
|
- tar -xf app.tar.gz -C ~/app
|
||||||
|
script:
|
||||||
- cd ~/packages
|
- cd ~/packages
|
||||||
- md5sum -c app.tar.gz.md5
|
- md5sum -c app.tar.gz.md5
|
||||||
- tar -xf app.tar.gz -C ~/app
|
- tar -xf app.tar.gz -C ~/app
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
FROM alpine:3.4
|
FROM alpine:3.13
|
||||||
MAINTAINER Michael de Wit <michael@drillster.com>
|
|
||||||
|
|
||||||
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/
|
COPY upload.sh /usr/local/
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/upload.sh"]
|
ENTRYPOINT ["/usr/local/upload.sh"]
|
||||||
|
|||||||
@@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
This is a pure Bash [Drone](https://github.com/drone/drone) >= 0.5 plugin to sync files to remote hosts.
|
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 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).
|
||||||
|
|
||||||
- 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
|
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
Build the docker image by running:
|
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_HOSTS="127.0.0.1, 127.0.0.2, 127.0.0.3" \
|
||||||
-e PLUGIN_PORTS="22, 23, 24" \
|
-e PLUGIN_PORTS="22, 23, 24" \
|
||||||
-e PLUGIN_TARGET="./" \
|
-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" \
|
-e PLUGIN_ARGS="--blocking-io" \
|
||||||
-v $(pwd):$(pwd) \
|
-v $(pwd):$(pwd) \
|
||||||
-w $(pwd) \
|
-w $(pwd) \
|
||||||
|
|||||||
29
upload.sh
29
upload.sh
@@ -8,6 +8,7 @@ if [ -z "$PLUGIN_TARGET" ]; then
|
|||||||
echo "Specify a target!"
|
echo "Specify a target!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEFAULT_PORT=$PLUGIN_PORT
|
DEFAULT_PORT=$PLUGIN_PORT
|
||||||
if [ -z "$PLUGIN_PORT" ]; then
|
if [ -z "$PLUGIN_PORT" ]; then
|
||||||
echo "Port not specified, using default port 22!"
|
echo "Port not specified, using default port 22!"
|
||||||
@@ -45,6 +46,12 @@ else
|
|||||||
ARGS=$PLUGIN_ARGS
|
ARGS=$PLUGIN_ARGS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$PLUGIN_LOG_LEVEL" ]; then
|
||||||
|
LOG_LEVEL=quiet
|
||||||
|
else
|
||||||
|
LOG_LEVEL=$PLUGIN_LOG_LEVEL
|
||||||
|
fi
|
||||||
|
|
||||||
# Building rsync command
|
# Building rsync command
|
||||||
expr="rsync -az $ARGS"
|
expr="rsync -az $ARGS"
|
||||||
|
|
||||||
@@ -56,7 +63,7 @@ if [[ -n "$PLUGIN_DELETE" && "$PLUGIN_DELETE" == "true" ]]; then
|
|||||||
expr="$expr --del"
|
expr="$expr --del"
|
||||||
fi
|
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
|
# Include
|
||||||
IFS=','; read -ra INCLUDE <<< "$PLUGIN_INCLUDE"
|
IFS=','; read -ra INCLUDE <<< "$PLUGIN_INCLUDE"
|
||||||
@@ -100,10 +107,14 @@ fi
|
|||||||
echo "$SSH_KEY" > $keyfile
|
echo "$SSH_KEY" > $keyfile
|
||||||
chmod 0600 $keyfile
|
chmod 0600 $keyfile
|
||||||
|
|
||||||
# Parse SSH commands
|
|
||||||
function join_with { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
|
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"
|
IFS=','; read -ra COMMANDS <<< "$PLUGIN_SCRIPT"
|
||||||
script=$(join_with ' && ' "${COMMANDS[@]}")
|
postscript=$(join_with ' && ' "${COMMANDS[@]}")
|
||||||
|
|
||||||
# Run rsync
|
# Run rsync
|
||||||
IFS=','; read -ra HOSTS <<< "$PLUGIN_HOSTS"
|
IFS=','; read -ra HOSTS <<< "$PLUGIN_HOSTS"
|
||||||
@@ -119,13 +130,21 @@ do
|
|||||||
PORT=$DEFAULT_PORT
|
PORT=$DEFAULT_PORT
|
||||||
fi
|
fi
|
||||||
echo $(printf "%s" "$ $(printf "$expr" "$PORT") $USER@$HOST:$PLUGIN_TARGET ...")
|
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"
|
eval "$(printf "$expr" "$PORT") $USER@$HOST:$PLUGIN_TARGET"
|
||||||
result=$(($result+$?))
|
result=$(($result+$?))
|
||||||
if [ "$result" -gt "0" ]; then exit $result; fi
|
if [ "$result" -gt "0" ]; then exit $result; fi
|
||||||
if [ -n "$PLUGIN_SCRIPT" ]; then
|
if [ -n "$PLUGIN_SCRIPT" ]; then
|
||||||
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST ...")
|
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST ...")
|
||||||
echo $(printf "%s" " > $script ...")
|
echo $(printf "%s" " > $postscript ...")
|
||||||
eval "ssh -p $PORT $USER@$HOST '$script'"
|
eval "ssh -p $PORT $USER@$HOST '$postscript'"
|
||||||
result=$(($result+$?))
|
result=$(($result+$?))
|
||||||
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST result: $?")
|
echo $(printf "%s" "$ ssh -p $PORT $USER@$HOST result: $?")
|
||||||
if [ "$result" -gt "0" ]; then exit $result; fi
|
if [ "$result" -gt "0" ]; then exit $result; fi
|
||||||
|
|||||||
Reference in New Issue
Block a user