From 309c68b401e449fb09286e8eca8449aee420d7a6 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 29 Mar 2019 21:47:37 +0100 Subject: [PATCH 1/5] add docs for drone 1 --- DOCS.md => 0-DOCS.md | 0 1-DOCS.md | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) rename DOCS.md => 0-DOCS.md (100%) create mode 100644 1-DOCS.md diff --git a/DOCS.md b/0-DOCS.md similarity index 100% rename from DOCS.md rename to 0-DOCS.md diff --git a/1-DOCS.md b/1-DOCS.md new file mode 100644 index 0000000..a04dc82 --- /dev/null +++ b/1-DOCS.md @@ -0,0 +1,77 @@ +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 \ +``` + +Add the secret to your `.drone.yml`: +```yaml +kind: pipeline + +- name: rsync + image: drillster/drone-rsync + settings: + user: some-user + hosts: + - remote1 + source: ./dist + target: ~/packages + secrets: [ rsync_key ] +``` + +See the [secret guides](https://docs.drone.io/user-guide/secrets/pre-repository/) for additional information on secrets. + +## Examples +```yaml +kind: pipeline +name: default + +- name: rsync + image: drillster/drone-rsync + settings: + 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. + From b15f814c66cd1550e8a8c9882e00020a80ebc536 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 29 Mar 2019 21:54:52 +0100 Subject: [PATCH 2/5] update readme to point users of different versions to the right docs --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e30477..c296860 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,10 @@ 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](https://github.com/Drillster/drone-rsync/blob/master/DOCS.md). +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 ## Docker Build the docker image by running: From 01d606cc9f48a9014eecd3b0fb20b2122a9068bc Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 29 Mar 2019 21:58:18 +0100 Subject: [PATCH 3/5] add steps: --- 1-DOCS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/1-DOCS.md b/1-DOCS.md index a04dc82..5f2d7cf 100644 --- a/1-DOCS.md +++ b/1-DOCS.md @@ -32,6 +32,7 @@ Add the secret to your `.drone.yml`: ```yaml kind: pipeline +steps: - name: rsync image: drillster/drone-rsync settings: @@ -50,6 +51,7 @@ See the [secret guides](https://docs.drone.io/user-guide/secrets/pre-repository/ kind: pipeline name: default +steps: - name: rsync image: drillster/drone-rsync settings: From 24b116006bd235a9e36b2ea33ff0b20182bacf33 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 29 Mar 2019 23:36:54 +0100 Subject: [PATCH 4/5] show how to read rsync_key secret value --- 1-DOCS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/1-DOCS.md b/1-DOCS.md index 5f2d7cf..d0891ce 100644 --- a/1-DOCS.md +++ b/1-DOCS.md @@ -35,6 +35,9 @@ kind: pipeline steps: - name: rsync image: drillster/drone-rsync + environment: + RSYNC_KEY: + from_secret: rsync_key settings: user: some-user hosts: @@ -54,6 +57,9 @@ name: default steps: - name: rsync image: drillster/drone-rsync + environment: + RSYNC_KEY: + from_secret: rsync_key settings: hosts: - remote1 From 4326e0e4704cce4cffd54dca9c99d02722c6dc06 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 30 Mar 2019 00:04:02 +0100 Subject: [PATCH 5/5] add RSYNC_USER to env --- 1-DOCS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/1-DOCS.md b/1-DOCS.md index d0891ce..e0530c8 100644 --- a/1-DOCS.md +++ b/1-DOCS.md @@ -60,6 +60,8 @@ steps: environment: RSYNC_KEY: from_secret: rsync_key + RSYNC_USER: + from_secret: rsync_user settings: hosts: - remote1 @@ -75,7 +77,6 @@ steps: - 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.