Compare commits

...

90 Commits

Author SHA1 Message Date
Bo-Yi Wu 15bd1a11e4 chore: change command timeout flag (#92)
* chore: change command timeout flag

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* docs: update setting

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* doc: update readme.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-07 13:56:40 +08:00
Bo-Yi Wu be0d85245a update go module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-07 11:15:54 +08:00
Bo-Yi Wu 9cc27c6724 refactor: err check
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-06 11:05:15 +08:00
Bo-Yi Wu b36ffb0d5d fix: add empty line 2019-03-04 21:46:05 +08:00
Bo-Yi Wu ca7485443c chore(docker): replace ADD with COPY 2019-03-04 21:43:11 +08:00
Bo-Yi Wu f8a64791a4 chore: add lint check
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-04 16:11:12 +08:00
Bo-Yi Wu fe8e5e3483 fix: remove check username exist. (#91) 2019-03-03 07:16:57 +08:00
Bo-Yi Wu 2344618287 docs: update badge 2019-03-03 00:28:21 +08:00
Bo-Yi Wu 24926998c1 fix: binary name 2019-03-03 00:09:58 +08:00
Bo-Yi Wu a82a76903c fix: ssh config 2019-03-03 00:07:55 +08:00
Bo-Yi Wu 8e1c446a58 chore: update testing. 2019-03-02 23:53:27 +08:00
Bo-Yi Wu a2e6a07e44 feat: switch from govender to module. 2019-03-02 23:52:35 +08:00
Bo-Yi Wu bc7d0d7a7a docs: update 2019-01-27 11:34:27 +08:00
Bo-Yi Wu 26223d7b71 docs: Example ignore list configuration 2019-01-18 23:17:23 +08:00
Bo-Yi Wu b3f09b7592 refactor(lint): replace tool 2019-01-18 22:58:17 +08:00
Bo-Yi Wu 75d2ee1e10 fix missing exclude files (#88)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-01-18 16:40:50 +08:00
Bo-Yi Wu 699675c8fa add debug command. (#87)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-01-18 16:06:22 +08:00
Bo-Yi Wu d921289474 feat(ignore): support ignore list (#86)
fix #85
2019-01-18 15:12:36 +08:00
Bo-Yi Wu 4f7d31bd86 fix: missing tar config (#83) 2018-11-05 15:22:19 +08:00
natlibfi-arlehiko d798a8cc75 Add TarExec parameter (#82)
Add TarExec parameter to provide an alternative tar-command (E.g. On old non-Linux systems it may be necessary to use gtar).
2018-11-05 15:11:00 +08:00
Bo-Yi Wu 147005589b support user key. 2018-11-05 09:05:34 +08:00
Bo-Yi Wu 7fa57c038a add error action preference
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2018-06-27 14:18:19 +08:00
Bo-Yi Wu e6e048f198 fix: Provide a password using STDIN 2018-06-27 14:16:43 +08:00
Bo-Yi Wu 8096419bd2 chore: upgrade to 1.10 golang version. 2018-04-06 10:18:08 +08:00
Bo-Yi Wu 985badff42 mark arm and arm64 docker
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-22 13:51:15 +08:00
Bo-Yi Wu f68e09cf01 fix: arm32 image 2017-12-22 13:47:14 +08:00
Bo-Yi Wu 9150f669c9 fix: missing binary 2017-12-22 13:42:29 +08:00
Bo-Yi Wu ceb2b47958 feat(docker): suport arm arm64 image 2017-12-22 12:43:46 +08:00
Bo-Yi Wu acc220475c fix: Add build number. 2017-12-22 11:41:04 +08:00
Bo-Yi Wu 43d4f0d781 fix(error): show error log. 2017-12-22 11:38:13 +08:00
Bo-Yi Wu 357e2db0ff fix: update example. 2017-12-22 11:30:53 +08:00
Bo-Yi Wu 7764e754fe feat(docker): support windows build 2017-12-22 11:26:07 +08:00
Bo-Yi Wu 5bf5231d41 remove arm alpine arm64 i386 image.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-22 11:24:11 +08:00
Bo-Yi Wu 0261361be4 fix: stat /tmp: no such file or directory 2017-12-22 11:09:29 +08:00
Bo-Yi Wu f410f5e6ca chore(git): add release folder to ignore list. 2017-12-22 10:58:32 +08:00
Bo-Yi Wu e8f0048a45 refactor(notify): change fb to discord. 2017-12-22 10:55:01 +08:00
Bo-Yi Wu 41ace25862 feat(docker): suport arm arm64 alpine i386 image (#77) 2017-12-22 10:52:42 +08:00
Bo-Yi Wu 9c958f8637 docs(drone): add secret section 2017-12-18 09:45:38 +08:00
Bo-Yi Wu 9352413b30 add maintainer label.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-10-05 11:35:16 +08:00
Bo-Yi Wu f22cd46f46 Add some ssh env (#73) 2017-07-28 09:03:38 +08:00
Bo-Yi Wu 2cc69e2c03 update notify condition.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-24 22:55:10 +08:00
Bo-Yi Wu 637dcaaccc update drone ci website link.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-10 11:16:22 +08:00
Bo-Yi Wu 7c9b1d8b79 refactor: update gofmt check command. (#71) 2017-05-22 11:09:42 +08:00
Bo-Yi Wu 7a88a784b2 refactor: hide domain info if only single domain in drone setting. (#70) 2017-05-15 17:16:21 +08:00
Bo-Yi Wu 13e681cc3b refactor: wait group 2017-05-15 17:08:19 +08:00
Bo-Yi Wu a363fa22bf upgrade easyssh-proxy (#69)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-14 18:28:13 +08:00
Bo-Yi Wu 2ee4b54624 upgrade drone config. (#68)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-14 18:22:06 +08:00
Bo-Yi Wu a2708638cf [ci skip] update docs.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-01 08:55:15 +08:00
Bo-Yi Wu 35c2f7a14c feat: support strip components flag for tar command (#65)
Remove the specified number of leading path elements.
2017-04-30 23:18:22 +08:00
Bo-Yi Wu 8dba1e8e32 fix: quick fix. (#63) 2017-04-21 19:34:32 +08:00
Bo-Yi Wu 049263e847 refactor: show errors if set password and key at the same time (#62) 2017-04-21 16:38:43 +08:00
Bo-Yi Wu 88f5a95f3e add scp error message (#60)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-04-20 14:59:09 +08:00
Bo-Yi Wu 7bdc9fc05e refactor: HostKeyCallback is the function type used for verifying server (#59)
* refactor: HostKeyCallback is the function type used for verifying server

* update ssh package.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-04-15 20:45:16 +08:00
Bo-Yi Wu 3b2dbe955b remove drone sig file. (#57)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-04-14 09:19:05 +08:00
Bo-Yi Wu 464f0edc7e feat: add fmt check command. (#56) 2017-04-02 19:59:50 +08:00
Bo-Yi Wu 6aa6653378 update testing for remove single dest file. (#55)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-03-25 23:05:13 +08:00
Bo-Yi Wu d326bfe5a4 feat: update easyssh-proxy to 1.1.1 (#54) 2017-03-25 22:46:03 +08:00
Bo-Yi Wu 2ebb608269 feat: add color (#53) 2017-03-25 20:35:10 +08:00
Bo-Yi Wu f223505d46 add copy error handle. (#52) 2017-03-25 20:19:07 +08:00
Bo-Yi Wu b1ca6d49a2 feat: remove temp file if encounter errors. (#51) 2017-03-25 17:23:03 +08:00
Bo-Yi Wu c612c8c5c0 [ci skip] add proxy config docs
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-03-23 13:48:14 +08:00
Bo-Yi Wu e8dfaea058 Update README.md 2017-03-10 17:11:22 +08:00
Bo-Yi Wu 3121cb2aaa [ci skip] docs: add ProxyCommand docs. (#49)
* docs: add ProxyCommand docs.
2017-03-07 11:12:49 +08:00
Bo-Yi Wu 72c123f390 feat: Support scp files from proxy command. (#47)
* feat: Support scp files from proxy command.
2017-03-06 14:43:52 +08:00
Bo-Yi Wu 04c639cfa8 feat: upgrade to easyssh-proxy package. (#45)
* feat: upgrade to easyssh-proxy package.

* add command timeout flag
* upgrade easyssh to easyssh-proxy
2017-03-06 12:35:57 +08:00
Bo-Yi Wu ef521d1e98 refactor: hash is a much faster shell-builtin alternative to which. (#43) 2017-02-27 22:08:26 +08:00
Bo-Yi Wu 496e23a7e9 feat: improve coverage for easyssh (#42)
* feat: improve coverage for easyssh
2017-02-14 15:23:41 +08:00
Bo-Yi Wu 3e7ff1f928 refactor: remove travis 2017-02-14 12:34:53 +08:00
Bo-Yi Wu 6179afcde8 test: improve code coverage for easyssh. (#39)
* test: improve code coverage.

* feat: test password
2017-02-14 12:33:19 +08:00
Bo-Yi Wu 4f2e0c2096 refactor: remove travis (#41) 2017-02-14 12:30:51 +08:00
Bo-Yi Wu e2b890d217 remove glide config.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-02-14 09:49:48 +08:00
Bo-Yi Wu cdfa646abf docs: fix diff format. 2017-02-13 12:00:35 +08:00
Bo-Yi Wu ed37a75097 docs: [ci skip] update docs 2017-02-13 11:17:05 +08:00
Bo-Yi Wu baa413d348 feat: support wildcard file list. (#37)
* feat: support wildcard file list.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-02-13 11:09:14 +08:00
Bo-Yi Wu 79f352a5fa refactor: remove glide from drone config (#36)
* refactor: remove glide from drone config
2017-02-13 10:29:42 +08:00
Bo-Yi Wu 9787fcfb60 refactor: add vendor folder. (#34)
* refactor: add vendor folder.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-02-12 17:51:17 +08:00
Bo-Yi Wu ae6b001406 docs: [ci skip] add drone plugin document link. 2017-02-08 10:28:21 +08:00
Bo-Yi Wu 0d84586fb1 test: add easyssh scp and ssh command testing. (#29) 2017-02-04 20:50:51 +08:00
Bo-Yi Wu d673dc3a68 fix: [ci skip] drone link. 2017-02-04 18:39:22 +08:00
Bo-Yi Wu 1f05c75ba3 docs: [ci skip] update doc 2017-02-04 18:38:42 +08:00
Bo-Yi Wu 6472931282 refactor: add ssh-server command. (#28) 2017-02-04 17:35:31 +08:00
Bo-Yi Wu bb6e686f9a feat: initial easyssh testing. (#27) 2017-02-04 17:21:42 +08:00
Bo-Yi Wu 3911edcd30 docs: [ci skip] add timeout description 2017-01-31 21:17:09 +08:00
Bo-Yi Wu 212aa456c6 fix: duplicate of -t flag 2017-01-30 16:31:38 +08:00
Bo-Yi Wu 87fcf060aa refactor: update ssh host using JoinHostPort 2017-01-30 00:46:53 +08:00
Bo-Yi Wu 57d83dcfe0 feat: Add timeout flag. (#26) 2017-01-29 13:56:23 +08:00
Bo-Yi Wu e5ead0fb9c feat: Add unconvert command 2017-01-28 11:41:52 +08:00
Bo-Yi Wu 4e0a131533 docs: [ci skip] remove secret section. 2017-01-20 15:03:14 +08:00
Bo-Yi Wu 2704d9d275 fix: Enforce custom LDFLAGS within makefile 2017-01-17 10:37:41 +08:00
Bo-Yi Wu e9832010f8 fix: Clone tags within drone for proper version generation 2017-01-15 12:06:47 +08:00
30 changed files with 1692 additions and 619 deletions
+16
View File
@@ -0,0 +1,16 @@
local pipeline = import 'pipeline.libsonnet';
local name = 'drone-scp';
[
pipeline.test,
pipeline.build(name, 'linux', 'amd64'),
pipeline.build(name, 'linux', 'arm64'),
pipeline.build(name, 'linux', 'arm'),
pipeline.release,
pipeline.notifications(depends_on=[
'linux-amd64',
'linux-arm64',
'linux-arm',
'release-binary',
]),
]
+380 -76
View File
@@ -1,84 +1,388 @@
workspace:
base: /srv/app
path: src/github.com/appleboy/drone-scp
---
kind: pipeline
name: testing
pipeline:
# restore the cache from an sftp server
restore_cache:
image: appleboy/drone-sftp-cache
restore: true
mount: [ .glide, vendor ]
ignore_branch: true
platform:
os: linux
arch: amd64
test:
image: appleboy/golang-testing
pull: true
environment:
TAGS: netgo
GOPATH: /srv/app
commands:
- adduser -h /home/drone-scp -s /bin/bash -D -S drone-scp
- passwd -d drone-scp
- mkdir -p /home/drone-scp/.ssh
- chmod 700 /home/drone-scp/.ssh
- cp tests/.ssh/id_rsa.pub /home/drone-scp/.ssh/authorized_keys
- chown -R drone-scp /home/drone-scp/.ssh
# install ssh and start server
- apk update && apk add openssh openrc
- rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
- ./tests/entrypoint.sh /usr/sbin/sshd -D &
- make dep_install
- make vet
- make lint
- make test
- make coverage
- make build
# build binary for docker image
- make static_build
when:
event: [ push, tag, pull_request ]
steps:
- name: vet
pull: always
image: golang:1.12
commands:
- make vet
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
release:
image: appleboy/golang-testing
pull: true
environment:
TAGS: netgo
GOPATH: /srv/app
commands:
- make release
when:
event: [ tag ]
branch: [ refs/tags/* ]
- name: lint
pull: always
image: golang:1.12
commands:
- make lint
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
docker:
image: plugins/docker
repo: ${DRONE_REPO}
tags: [ '${DRONE_TAG}' ]
when:
event: [ tag ]
branch: [ refs/tags/* ]
- name: misspell
pull: always
image: golang:1.12
commands:
- make misspell-check
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
docker:
image: plugins/docker
repo: ${DRONE_REPO}
tags: [ 'latest' ]
when:
event: [ push ]
branch: [ master ]
- name: test
pull: always
image: golang:1.12-alpine
commands:
- apk add git make curl perl bash build-base zlib-dev ucl-dev
- make ssh-server
- make test
- make coverage
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
github:
image: plugins/github-release
- name: codecov
pull: always
image: robertstettner/drone-codecov
settings:
token:
from_secret: codecov_token
volumes:
- name: gopath
temp: {}
---
kind: pipeline
name: linux-amd64
platform:
os: linux
arch: amd64
steps:
- name: build-push
pull: always
image: golang:1.12
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.12
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.12
commands:
- ./release/linux/amd64/drone-scp --help
- name: dryrun
pull: always
image: plugins/docker:linux-amd64
settings:
cache_from: appleboy/drone-scp
dockerfile: docker/Dockerfile.linux.amd64
dry_run: true
repo: appleboy/drone-scp
tags: linux-amd64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-amd64
settings:
auto_tag: true
auto_tag_suffix: linux-amd64
cache_from: appleboy/drone-scp
daemon_off: false
dockerfile: docker/Dockerfile.linux.amd64
password:
from_secret: docker_password
repo: appleboy/drone-scp
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
depends_on:
- testing
---
kind: pipeline
name: linux-arm64
platform:
os: linux
arch: arm64
steps:
- name: build-push
pull: always
image: golang:1.12
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.12
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.12
commands:
- ./release/linux/arm64/drone-scp --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm64
settings:
cache_from: appleboy/drone-scp
dockerfile: docker/Dockerfile.linux.arm64
dry_run: true
repo: appleboy/drone-scp
tags: linux-arm64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm64
settings:
auto_tag: true
auto_tag_suffix: linux-arm64
cache_from: appleboy/drone-scp
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm64
password:
from_secret: docker_password
repo: appleboy/drone-scp
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
depends_on:
- testing
---
kind: pipeline
name: linux-arm
platform:
os: linux
arch: arm
steps:
- name: build-push
pull: always
image: golang:1.12
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.12
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.12
commands:
- ./release/linux/arm/drone-scp --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm
settings:
cache_from: appleboy/drone-scp
dockerfile: docker/Dockerfile.linux.arm
dry_run: true
repo: appleboy/drone-scp
tags: linux-arm
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm
settings:
auto_tag: true
auto_tag_suffix: linux-arm
cache_from: appleboy/drone-scp
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm
password:
from_secret: docker_password
repo: appleboy/drone-scp
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
depends_on:
- testing
---
kind: pipeline
name: release-binary
platform:
os: linux
arch: amd64
steps:
- name: build-all-binary
pull: always
image: golang:1.12
commands:
- make release
environment:
GO111MODULE: on
when:
event:
- tag
- name: deploy-all-binary
pull: always
image: plugins/github-release
settings:
api_key:
from_secret: github_release_api_key
files:
- dist/release/*
when:
event: [ tag ]
branch: [ refs/tags/* ]
- "dist/release/*"
when:
event:
- tag
# rebuild the cache on the sftp server
rebuild_cache:
image: appleboy/drone-sftp-cache
rebuild: true
mount: [ .glide, vendor ]
ignore_branch: true
when:
branch: master
trigger:
ref:
- "refs/tags/**"
depends_on:
- testing
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: manifest
pull: always
image: plugins/manifest
settings:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/manifest.tmpl
username:
from_secret: docker_username
- name: microbadger
pull: always
image: plugins/webhook:1
settings:
url:
from_secret: microbadger_url
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
depends_on:
- linux-amd64
- linux-arm64
- linux-arm
- release-binary
...
-1
View File
@@ -1 +0,0 @@
eyJhbGciOiJIUzI1NiJ9.d29ya3NwYWNlOgogIGJhc2U6IC9zcnYvYXBwCiAgcGF0aDogc3JjL2dpdGh1Yi5jb20vYXBwbGVib3kvZHJvbmUtc2NwCgpwaXBlbGluZToKICAjIHJlc3RvcmUgdGhlIGNhY2hlIGZyb20gYW4gc2Z0cCBzZXJ2ZXIKICByZXN0b3JlX2NhY2hlOgogICAgaW1hZ2U6IGFwcGxlYm95L2Ryb25lLXNmdHAtY2FjaGUKICAgIHJlc3RvcmU6IHRydWUKICAgIG1vdW50OiBbIC5nbGlkZSwgdmVuZG9yIF0KICAgIGlnbm9yZV9icmFuY2g6IHRydWUKCiAgdGVzdDoKICAgIGltYWdlOiBhcHBsZWJveS9nb2xhbmctdGVzdGluZwogICAgcHVsbDogdHJ1ZQogICAgZW52aXJvbm1lbnQ6CiAgICAgIFRBR1M6IG5ldGdvCiAgICAgIEdPUEFUSDogL3Nydi9hcHAKICAgIGNvbW1hbmRzOgogICAgICAtIGFkZHVzZXIgLWggL2hvbWUvZHJvbmUtc2NwIC1zIC9iaW4vYmFzaCAtRCAtUyBkcm9uZS1zY3AKICAgICAgLSBwYXNzd2QgLWQgZHJvbmUtc2NwCiAgICAgIC0gbWtkaXIgLXAgL2hvbWUvZHJvbmUtc2NwLy5zc2gKICAgICAgLSBjaG1vZCA3MDAgL2hvbWUvZHJvbmUtc2NwLy5zc2gKICAgICAgLSBjcCB0ZXN0cy8uc3NoL2lkX3JzYS5wdWIgL2hvbWUvZHJvbmUtc2NwLy5zc2gvYXV0aG9yaXplZF9rZXlzCiAgICAgIC0gY2hvd24gLVIgZHJvbmUtc2NwIC9ob21lL2Ryb25lLXNjcC8uc3NoCiAgICAgICMgaW5zdGFsbCBzc2ggYW5kIHN0YXJ0IHNlcnZlcgogICAgICAtIGFwayB1cGRhdGUgJiYgYXBrIGFkZCBvcGVuc3NoIG9wZW5yYwogICAgICAtIHJtIC1yZiAvZXRjL3NzaC9zc2hfaG9zdF9yc2Ffa2V5IC9ldGMvc3NoL3NzaF9ob3N0X2RzYV9rZXkKICAgICAgLSAuL3Rlc3RzL2VudHJ5cG9pbnQuc2ggL3Vzci9zYmluL3NzaGQgLUQgJgogICAgICAtIG1ha2UgZGVwX2luc3RhbGwKICAgICAgLSBtYWtlIHZldAogICAgICAtIG1ha2UgbGludAogICAgICAtIG1ha2UgdGVzdAogICAgICAtIG1ha2UgY292ZXJhZ2UKICAgICAgLSBtYWtlIGJ1aWxkCiAgICAgICMgYnVpbGQgYmluYXJ5IGZvciBkb2NrZXIgaW1hZ2UKICAgICAgLSBtYWtlIHN0YXRpY19idWlsZAogICAgd2hlbjoKICAgICAgZXZlbnQ6IFsgcHVzaCwgdGFnLCBwdWxsX3JlcXVlc3QgXQoKICByZWxlYXNlOgogICAgaW1hZ2U6IGFwcGxlYm95L2dvbGFuZy10ZXN0aW5nCiAgICBwdWxsOiB0cnVlCiAgICBlbnZpcm9ubWVudDoKICAgICAgVEFHUzogbmV0Z28KICAgICAgR09QQVRIOiAvc3J2L2FwcAogICAgY29tbWFuZHM6CiAgICAgIC0gbWFrZSByZWxlYXNlCiAgICB3aGVuOgogICAgICBldmVudDogWyB0YWcgXQogICAgICBicmFuY2g6IFsgcmVmcy90YWdzLyogXQoKICBkb2NrZXI6CiAgICBpbWFnZTogcGx1Z2lucy9kb2NrZXIKICAgIHJlcG86ICR7RFJPTkVfUkVQT30KICAgIHRhZ3M6IFsgJyR7RFJPTkVfVEFHfScgXQogICAgd2hlbjoKICAgICAgZXZlbnQ6IFsgdGFnIF0KICAgICAgYnJhbmNoOiBbIHJlZnMvdGFncy8qIF0KCiAgZG9ja2VyOgogICAgaW1hZ2U6IHBsdWdpbnMvZG9ja2VyCiAgICByZXBvOiAke0RST05FX1JFUE99CiAgICB0YWdzOiBbICdsYXRlc3QnIF0KICAgIHdoZW46CiAgICAgIGV2ZW50OiBbIHB1c2ggXQogICAgICBicmFuY2g6IFsgbWFzdGVyIF0KCiAgZ2l0aHViOgogICAgaW1hZ2U6IHBsdWdpbnMvZ2l0aHViLXJlbGVhc2UKICAgIGZpbGVzOgogICAgICAtIGRpc3QvcmVsZWFzZS8qCiAgICB3aGVuOgogICAgICBldmVudDogWyB0YWcgXQogICAgICBicmFuY2g6IFsgcmVmcy90YWdzLyogXQoKICAjIHJlYnVpbGQgdGhlIGNhY2hlIG9uIHRoZSBzZnRwIHNlcnZlcgogIHJlYnVpbGRfY2FjaGU6CiAgICBpbWFnZTogYXBwbGVib3kvZHJvbmUtc2Z0cC1jYWNoZQogICAgcmVidWlsZDogdHJ1ZQogICAgbW91bnQ6IFsgLmdsaWRlLCB2ZW5kb3IgXQogICAgaWdub3JlX2JyYW5jaDogdHJ1ZQogICAgd2hlbjoKICAgICAgYnJhbmNoOiBtYXN0ZXIK.iJq2DIBtHk-IH2ioZdNEkFcxDj-5mtNikSX66Jdt_pM
+2 -1
View File
@@ -22,8 +22,9 @@ _testmain.go
*.exe
*.test
*.prof
vendor
drone-scp
coverage.txt
.env
dist
.cover
release
+25
View File
@@ -0,0 +1,25 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 1
warningCode = 1
[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
-30
View File
@@ -1,30 +0,0 @@
sudo: required
language: go
go:
- 1.6.x
- 1.7.x
- tip
cache:
directories:
- vendor
- ${HOME}/.glide
before_install:
- mkdir -p $GOPATH/bin
- curl https://glide.sh/get | sh
- sudo useradd -m -d /home/drone-scp -s /bin/bash drone-scp
- sudo mkdir -p /home/drone-scp/.ssh
- sudo chmod 700 /home/drone-scp/.ssh
- sudo cp tests/.ssh/id_rsa.pub /home/drone-scp/.ssh/authorized_keys
- sudo chown -R drone-scp /home/drone-scp/.ssh
install:
- make dep_install
script:
- make vet
- make lint
- make test
- make build
+126 -57
View File
@@ -3,8 +3,8 @@ date: 2017-01-06T00:00:00+00:00
title: SCP
author: appleboy
tags: [ publish, ssh, scp ]
repo: appleboy/drone-scp
logo: term.svg
repo: appleboy/drone-scp
image: appleboy/drone-scp
---
@@ -14,9 +14,10 @@ The SCP plugin copy files and artifacts to target host machine via SSH. The belo
pipeline:
scp:
image: appleboy/drone-scp
host: example.com
target: /home/deploy/web
source: release.tar.gz
settings:
host: example.com
target: /home/deploy/web
source: release.tar.gz
```
Example configuration with custom username, password and port:
@@ -25,12 +26,13 @@ Example configuration with custom username, password and port:
pipeline:
scp:
image: appleboy/drone-scp
host: example.com
+ username: appleboy
+ password: 12345678
+ port: 4430
target: /home/deploy/web
source: release.tar.gz
settings:
host: example.com
+ username: appleboy
+ password: 12345678
+ port: 4430
target: /home/deploy/web
source: release.tar.gz
```
Example configuration with multiple source and target folder:
@@ -39,13 +41,14 @@ Example configuration with multiple source and target folder:
pipeline:
scp:
image: appleboy/drone-scp
host: example.com
target:
+ - /home/deploy/web1
+ - /home/deploy/web2
source:
+ - release_1.tar.gz
+ - release_2.tar.gz
settings:
host: example.com
target:
+ - /home/deploy/web1
+ - /home/deploy/web2
source:
+ - release_1.tar.gz
+ - release_2.tar.gz
```
Example configuration with multiple host:
@@ -54,12 +57,30 @@ Example configuration with multiple host:
pipeline:
scp:
image: appleboy/drone-scp
- host: example.com
+ host:
+ - example1.com
+ - example2.com
target: /home/deploy/web
source: release.tar.gz
settings:
- host: example.com
+ host:
+ - example1.com
+ - example2.com
target: /home/deploy/web
source: release.tar.gz
```
Example configuration with wildcard pattern of source list:
```diff
pipeline:
scp:
image: appleboy/drone-scp
settings:
host:
- example1.com
- example2.com
target: /home/deploy/web
source:
- - release/backend.tar.gz
- - release/images.tar.gz
+ - release/*.tar.gz
```
Remove target folder before copy files and artifacts to target:
@@ -68,62 +89,83 @@ Remove target folder before copy files and artifacts to target:
scp:
image: appleboy/drone-scp
host: example.com
target: /home/deploy/web
source: release.tar.gz
+ rm: true
settings:
target: /home/deploy/web
source: release.tar.gz
+ rm: true
```
Example configuration for success build:
Example for remove the specified number of leading path elements:
```diff
scp:
image: appleboy/drone-scp
settings:
host: example.com
target: /home/deploy/web
source: dist/release.tar.gz
+ strip_components: 1
```
Example configuration using SSHProxyCommand:
```diff
pipeline:
scp:
image: appleboy/drone-scp
host: example.com
target: /home/deploy/web
source: release.tar.gz
+ when:
+ status: success
settings:
host:
- example1.com
- example2.com
target: /home/deploy/web
source:
- release/*.tar.gz
+ proxy_host: 10.130.33.145
+ proxy_user: ubuntu
+ proxy_port: 22
+ proxy_password: 1234
```
Example configuration for tag event:
Example configuration using password from secrets:
```diff
pipeline:
scp:
image: appleboy/drone-scp
host: example.com
target: /home/deploy/web
source: release.tar.gz
+ when:
+ status: success
+ event: tag
settings:
host:
- example1.com
- example2.com
user: ubuntu
port: 22
- password: 1234
+ password:
from_secret: ssh_password
target: /home/deploy/web
source:
- release/*.tar.gz
```
# Secrets
The SCP plugin supports reading credentials from the Drone secret store. This is strongly recommended instead of storing credentials in the pipeline configuration in plain text.
Example configuration using command timeout:
```diff
pipeline:
scp:
image: appleboy/drone-scp
host: example.com
username: appleboy
- password: 12345678
port: 4430
target: /home/deploy/web
source: release.tar.gz
settings:
host:
- example1.com
- example2.com
user: ubuntu
port: 22
- command_timeout: 120
+ command_timeout: 2m
from_secret: ssh_password
target: /home/deploy/web
source:
- release/*.tar.gz
```
The `password` or `key` attributes can be replaced with the below secret environment variables. Please see the Drone documentation to learn more about secrets.
SCP_PASSWORD
: password of target host user
SCP_KEY
: plain text of user private key
# Parameter Reference
host
@@ -150,6 +192,33 @@ source
rm
: remove target folder before copy files and artifacts
timeout
: timeout is the maximum amount of time for the TCP connection to establish
command_timeout
: timeout is the maximum amount of time for execute command
strip_components
: remove the specified number of leading path elements
proxy_host
: proxy hostname or IP
proxy_port
: ssh port of proxy host
proxy_username
: account for proxy host user
proxy_password
: password for proxy host user
proxy_key
: plain text of proxy private key
proxy_key_path
: key path of proxy private key
# Template Reference
repo.owner
@@ -183,4 +252,4 @@ build.author
: git author for current commit
build.link
: link the the build results in drone
: link the the build results in drone
-9
View File
@@ -1,9 +0,0 @@
FROM alpine:3.4
RUN apk update && \
apk add ca-certificates && \
rm -rf /var/cache/apk/*
ADD drone-scp /
ENTRYPOINT ["/drone-scp"]
-8
View File
@@ -1,8 +0,0 @@
FROM armhfbuild/alpine:3.4
RUN apk update && \
apk add ca-certificates && \
rm -rf /var/cache/apk/*
ADD drone-scp /bin/
ENTRYPOINT ["/bin/drone-scp"]
+62 -36
View File
@@ -1,17 +1,17 @@
.PHONY: test drone-scp build fmt vet errcheck lint install update release-dirs release-build release-copy release-check release coverage
DIST := dist
EXECUTABLE := drone-scp
GOFMT ?= gofmt "-s"
GO ?= go
# for dockerhub
DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
TARGETS ?= linux darwin windows
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
PACKAGES ?= $(shell $(GO) list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS += -X 'main.Version=$(VERSION)'
LDFLAGS ?= -X 'main.Version=$(VERSION)'
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
@@ -28,42 +28,50 @@ endif
all: build
fmt:
find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
$(GOFMT) -w $(SOURCES)
vet:
go vet $(PACKAGES)
errcheck:
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \
fi
errcheck $(PACKAGES)
$(GO) vet $(PACKAGES)
lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/golang/lint/golint; \
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
revive -config .revive.toml ./... || exit 1
test:
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error $(SOURCES)
html:
go tool cover -html=coverage.txt
.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w $(SOURCES)
dep_install:
glide install
.PHONY: fmt-check
fmt-check:
@diff=$$($(GOFMT) -d $(SOURCES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
dep_update:
glide up
test: fmt-check
@$(GO) test -v -cover -coverprofile coverage.txt $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
release: release-dirs release-build release-copy release-check
@@ -72,9 +80,9 @@ release-dirs:
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/mitchellh/gox; \
$(GO) get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -arch="amd64 386" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
gox -os="$(TARGETS)" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
@@ -82,14 +90,22 @@ release-copy:
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
# for docker.
static_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $(DEPLOY_IMAGE)
build_linux_amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
build_linux_i386:
CGO_ENABLED=0 GOOS=linux GOARCH=386 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
build_linux_arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
build_linux_arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
docker_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
docker: static_build docker_image
docker: docker_image
docker_deploy:
ifeq ($(tag),)
@@ -100,15 +116,25 @@ endif
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
ssh-server:
adduser -h /home/drone-scp -s /bin/bash -D -S drone-scp
echo drone-scp:1234 | chpasswd
mkdir -p /home/drone-scp/.ssh
chmod 700 /home/drone-scp/.ssh
cp tests/.ssh/id_rsa.pub /home/drone-scp/.ssh/authorized_keys
chown -R drone-scp /home/drone-scp/.ssh
# install ssh and start server
apk add --update openssh openrc
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
./tests/entrypoint.sh /usr/sbin/sshd -D &
coverage:
sed -i '/main.go/d' coverage.txt
curl -s https://codecov.io/bash > .codecov && \
chmod +x .codecov && \
./.codecov -f coverage.txt
clean:
go clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST) vendor
$(GO) clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
version:
@echo $(VERSION)
+89 -49
View File
@@ -1,22 +1,64 @@
# drone-scp
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp) [![Build Status](http://drone.wu-boy.com/api/badges/appleboy/drone-scp/status.svg)](http://drone.wu-boy.com/appleboy/drone-scp) [![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp) [![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/) [![](https://images.microbadger.com/badges/image/appleboy/drone-scp.svg)](https://microbadger.com/images/appleboy/drone-scp "Get your own image badge on microbadger.com")
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp)
[![Build Status](https://cloud.drone.io/api/badges/appleboy/drone-scp/status.svg)](https://cloud.drone.io/appleboy/drone-scp)
[![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/)
[![](https://images.microbadger.com/badges/image/appleboy/drone-scp.svg)](https://microbadger.com/images/appleboy/drone-scp "Get your own image badge on microbadger.com")
Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://readme.drone.io/0.5/).
Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://docs.drone.io/).
## Feature
* [x] Support routines.
* [x] Support wildcard pattern on source list.
* [x] Support send files to multiple host.
* [x] Support send files to multiple target folder on host.
* [x] Support load ssh key from absolute path or raw body.
* [x] Support SSH ProxyCommand.
```
+--------+ +----------+ +-----------+
| Laptop | <--> | Jumphost | <--> | FooServer |
+--------+ +----------+ +-----------+
OR
+--------+ +----------+ +-----------+
| Laptop | <--> | Firewall | <--> | FooServer |
+--------+ +----------+ +-----------+
192.168.1.5 121.1.2.3 10.10.29.68
```
## Breaking changes
`v1.5.0`: change command timeout flag to `Duration`. See the following setting:
```diff
pipeline:
scp:
image: appleboy/drone-scp
settings:
host:
- example1.com
- example2.com
user: ubuntu
port: 22
- command_timeout: 120
+ command_timeout: 2m
from_secret: ssh_password
target: /home/deploy/web
source:
- release/*.tar.gz
```
## Build or Download a binary
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-scp/releases). Support the following OS type.
* Windows amd64/386
* Linux amd64/386
* Linux arm/amd64/386
* Darwin amd64/386
With `Go` installed
@@ -28,7 +70,14 @@ $ go get -u -v github.com/appleboy/drone-scp
or build the binary with the following command:
```
$ make build
$ export GOOS=linux
$ export GOARCH=amd64
$ export CGO_ENABLED=0
$ export GO111MODULE=on
$ go test -cover ./...
$ go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
```
## Docker
@@ -75,7 +124,7 @@ drone-scp --host example.com \
drone-scp --host example.com \
--port 22 \
--username appleboy \
+ --password xxxxxxx \
+ --password xxxxxxx \
--target /home/appleboy/test \
--source your_local_folder_path
```
@@ -108,14 +157,14 @@ drone-scp --host example.com \
```diff
drone-scp --host example1.com \
+ --host example2.com \
+ --host example2.com \
--port 22 \
--username appleboy \
--password xxxxxxx
--target /home/appleboy/test1 \
+ --target /home/appleboy/test2 \
+ --target /home/appleboy/test2 \
--source your_local_folder_path_1
+ --source your_local_folder_path_2
+ --source your_local_folder_path_2
```
<a name="usage-from-docker"></a>
@@ -125,12 +174,12 @@ drone-scp --host example1.com \
```bash
docker run --rm \
-e SCP_HOST example.com \
-e SCP_USERNAME xxxxxxx \
-e SCP_PORT 22 \
-e SCP_KEY_PATH "${HOME}/.ssh/id_rsa"
-e SCP_SOURCE SOURCE_FILE_LIST \
-e SCP_TARGET TARGET_FOLDER_PATH \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_KEY_PATH="${HOME}/.ssh/id_rsa"
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
@@ -140,12 +189,12 @@ docker run --rm \
```diff
docker run --rm \
-e SCP_HOST example.com \
-e SCP_USERNAME xxxxxxx \
-e SCP_PORT 22 \
+ -e SCP_PASSWORD "xxxxxxx"
-e SCP_SOURCE SOURCE_FILE_LIST \
-e SCP_TARGET TARGET_FOLDER_PATH \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
+ -e SCP_PASSWORD="xxxxxxx"
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
@@ -169,11 +218,11 @@ You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH ` arguments.
```bash
docker run --rm \
-e SCP_HOST example.com \
-e SCP_USERNAME xxxxxxx \
-e SCP_PORT 22 \
-e SCP_SOURCE SOURCE_FILE_LIST \
-e SCP_TARGET TARGET_FOLDER_PATH \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
@@ -183,12 +232,12 @@ docker run --rm \
```bash
docker run --rm \
-e SCP_HOST example1.com,example2.com \
-e SCP_USERNAME xxxxxxx \
-e SCP_PASSWORD xxxxxxx \
-e SCP_PORT 22 \
-e SCP_SOURCE SOURCE_FILE_LIST_1,SOURCE_FILE_LIST_2 \
-e SCP_TARGET TARGET_FOLDER_PATH_1,TARGET_FOLDER_PATH_2 \
-e SCP_HOST=example1.com,example2.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PASSWORD=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_SOURCE=SOURCE_FILE_LIST_1,SOURCE_FILE_LIST_2 \
-e SCP_TARGET=TARGET_FOLDER_PATH_1,TARGET_FOLDER_PATH_2 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
@@ -201,29 +250,20 @@ Execute from the working directory:
```bash
docker run --rm \
-e PLUGIN_HOST example.com \
-e PLUGIN_USERNAME xxxxxxx \
-e PLUGIN_PASSWORD xxxxxxx \
-e PLUGIN_PORT xxxxxxx \
-e PLUGIN_KEY "$(cat ${HOME}/.ssh/id_rsa)"
-e PLUGIN_SOURCE SOURCE_FILE_LIST \
-e PLUGIN_TARGET TARGET_FOLDER_PATH \
-e PLUGIN_RM false \
-e PLUGIN_DEBUG false \
-e DRONE_REPO_OWNER appleboy \
-e DRONE_REPO_NAME go-hello \
-e DRONE_COMMIT_SHA e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
-e DRONE_COMMIT_BRANCH master \
-e DRONE_COMMIT_AUTHOR appleboy \
-e DRONE_BUILD_NUMBER 1 \
-e DRONE_BUILD_STATUS success \
-e DRONE_BUILD_LINK http://github.com/appleboy/go-hello \
-e PLUGIN_HOST=example.com \
-e PLUGIN_USERNAME=xxxxxxx \
-e PLUGIN_PASSWORD=xxxxxxx \
-e PLUGIN_PORT=xxxxxxx \
-e PLUGIN_SOURCE=SOURCE_FILE_LIST \
-e PLUGIN_TARGET=TARGET_FOLDER_PATH \
-e PLUGIN_RM=false \
-e PLUGIN_DEBUG=true \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
You can get more [information](DOCS.md) about how to use scp in drone.
You can get more [information](http://plugins.drone.io/appleboy/drone-scp/) about how to use scp in drone.
## Testing
+12
View File
@@ -0,0 +1,12 @@
FROM plugins/base:linux-amd64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SCP" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
COPY release/linux/amd64/drone-scp /bin/
ENTRYPOINT ["/bin/drone-scp"]
+12
View File
@@ -0,0 +1,12 @@
FROM plugins/base:linux-arm
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SCP" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
COPY release/linux/arm/drone-scp /bin/
ENTRYPOINT ["/bin/drone-scp"]
+12
View File
@@ -0,0 +1,12 @@
FROM plugins/base:linux-arm64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SCP" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
COPY release/linux/arm64/drone-scp /bin/
ENTRYPOINT ["/bin/drone-scp"]
+10
View File
@@ -0,0 +1,10 @@
FROM microsoft/nanoserver:10.0.14393.1884
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SCP" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
COPY drone-scp.exe /drone-scp.exe
ENTRYPOINT [ "\\drone-scp.exe" ]
+25
View File
@@ -0,0 +1,25 @@
image: appleboy/drone-scp:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
-
image: appleboy/drone-scp:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: appleboy/drone-scp:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
-
image: appleboy/drone-scp:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
variant: v7
-197
View File
@@ -1,197 +0,0 @@
// Package easyssh provides a simple implementation of some SSH protocol
// features in Go. You can simply run a command on a remote server or get a file
// even simpler than native console SSH client. You don't need to think about
// Dials, sessions, defers, or public keys... Let easyssh think about it!
package easyssh
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
// MakeConfig Contains main authority information.
// User field should be a name of user on remote server (ex. john in ssh john@example.com).
// Server field should be a remote machine address (ex. example.com in ssh john@example.com)
// Key is a path to private key on your local machine.
// Port is SSH server port on remote machine.
// Note: easyssh looking for private key in user's home directory (ex. /home/john + Key).
// Then ensure your Key begins from '/' (ex. /.ssh/id_rsa)
type MakeConfig struct {
User string
Server string
Key string
KeyPath string
Port string
Password string
}
// returns ssh.Signer from user you running app home path + cutted key path.
// (ex. pubkey,err := getKeyFile("/.ssh/id_rsa") )
func getKeyFile(keypath string) (ssh.Signer, error) {
buf, err := ioutil.ReadFile(keypath)
if err != nil {
return nil, err
}
pubkey, err := ssh.ParsePrivateKey(buf)
if err != nil {
return nil, err
}
return pubkey, nil
}
// connects to remote server using MakeConfig struct and returns *ssh.Session
func (ssh_conf *MakeConfig) connect() (*ssh.Session, error) {
// auths holds the detected ssh auth methods
auths := []ssh.AuthMethod{}
// figure out what auths are requested, what is supported
if ssh_conf.Password != "" {
auths = append(auths, ssh.Password(ssh_conf.Password))
}
if sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers))
defer sshAgent.Close()
}
if ssh_conf.KeyPath != "" {
if pubkey, err := getKeyFile(ssh_conf.KeyPath); err == nil {
auths = append(auths, ssh.PublicKeys(pubkey))
}
}
if ssh_conf.Key != "" {
signer, _ := ssh.ParsePrivateKey([]byte(ssh_conf.Key))
auths = append(auths, ssh.PublicKeys(signer))
}
config := &ssh.ClientConfig{
User: ssh_conf.User,
Auth: auths,
}
client, err := ssh.Dial("tcp", ssh_conf.Server+":"+ssh_conf.Port, config)
if err != nil {
return nil, err
}
session, err := client.NewSession()
if err != nil {
return nil, err
}
return session, nil
}
// Stream returns one channel that combines the stdout and stderr of the command
// as it is run on the remote machine, and another that sends true when the
// command is done. The sessions and channels will then be closed.
func (ssh_conf *MakeConfig) Stream(command string) (output chan string, done chan bool, err error) {
// connect to remote host
session, err := ssh_conf.connect()
if err != nil {
return output, done, err
}
// connect to both outputs (they are of type io.Reader)
outReader, err := session.StdoutPipe()
if err != nil {
return output, done, err
}
errReader, err := session.StderrPipe()
if err != nil {
return output, done, err
}
// combine outputs, create a line-by-line scanner
outputReader := io.MultiReader(outReader, errReader)
err = session.Start(command)
scanner := bufio.NewScanner(outputReader)
// continuously send the command's output over the channel
outputChan := make(chan string)
done = make(chan bool)
go func(scanner *bufio.Scanner, out chan string, done chan bool) {
defer close(outputChan)
defer close(done)
for scanner.Scan() {
outputChan <- scanner.Text()
}
// close all of our open resources
done <- true
session.Close()
}(scanner, outputChan, done)
return outputChan, done, err
}
// Run command on remote machine and returns its stdout as a string
func (ssh_conf *MakeConfig) Run(command string) (outStr string, err error) {
outChan, doneChan, err := ssh_conf.Stream(command)
if err != nil {
return outStr, err
}
// read from the output channel until the done signal is passed
stillGoing := true
for stillGoing {
select {
case <-doneChan:
stillGoing = false
case line := <-outChan:
outStr += line + "\n"
}
}
// return the concatenation of all signals from the output channel
return outStr, err
}
// Scp uploads sourceFile to remote machine like native scp console app.
func (ssh_conf *MakeConfig) Scp(sourceFile string) error {
session, err := ssh_conf.connect()
if err != nil {
return err
}
defer session.Close()
targetFile := filepath.Base(sourceFile)
src, srcErr := os.Open(sourceFile)
if srcErr != nil {
return srcErr
}
srcStat, statErr := src.Stat()
if statErr != nil {
return statErr
}
go func() {
w, _ := session.StdinPipe()
fmt.Fprintln(w, "C0644", srcStat.Size(), targetFile)
if srcStat.Size() > 0 {
io.Copy(w, src)
fmt.Fprint(w, "\x00")
w.Close()
} else {
fmt.Fprint(w, "\x00")
w.Close()
}
}()
if err := session.Run(fmt.Sprintf("scp -t %s", targetFile)); err != nil {
return err
}
return nil
}
Generated
-34
View File
@@ -1,34 +0,0 @@
hash: 324c76f4ece1989f584ec84aab8252020da4dcbc20e38990465a9a0b7400f8ec
updated: 2016-12-28T15:52:54.896825557+08:00
imports:
- name: github.com/appleboy/com
version: c2e1fea1b771a26cb55774843ebd8955d723ee4e
subpackages:
- random
- name: github.com/joho/godotenv
version: a01a834e1654b4c9ca5b3ad05159445cc9c7ad08
subpackages:
- autoload
- name: github.com/urfave/cli
version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6
- name: golang.org/x/crypto
version: c2f4947f41766b144bb09066e919466da5eddeae
subpackages:
- curve25519
- ed25519
- ed25519/internal/edwards25519
- ssh
- ssh/agent
testImports:
- name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
subpackages:
- spew
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
- difflib
- name: github.com/stretchr/testify
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
subpackages:
- assert
-20
View File
@@ -1,20 +0,0 @@
package: github.com/appleboy/drone-scp
import:
- package: github.com/joho/godotenv
version: ^1.0.0
subpackages:
- autoload
- package: github.com/urfave/cli
version: ^1.19.1
- package: golang.org/x/crypto
subpackages:
- ssh
- ssh/agent
- package: github.com/appleboy/com
subpackages:
- random
testImport:
- package: github.com/stretchr/testify
version: ^1.1.4
subpackages:
- assert
+14
View File
@@ -0,0 +1,14 @@
module github.com/appleboy/drone-scp
go 1.12
require (
github.com/appleboy/com v0.0.1
github.com/appleboy/easyssh-proxy v1.2.0
github.com/fatih/color v1.7.0
github.com/joho/godotenv v1.3.0
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.6 // indirect
github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0
)
+26
View File
@@ -0,0 +1,26 @@
github.com/appleboy/com v0.0.1 h1:SeP6J/YlZGWRwH7jdPYXXWA+qJy4GoQfcQFPda0ERYU=
github.com/appleboy/com v0.0.1/go.mod h1:rtwjPnHClMOJw4K5oW3ASx9BCPCJ1SDbFbzJjY4Ebqw=
github.com/appleboy/easyssh-proxy v1.2.0 h1:KvaUGC18WkBFet+N1oofQy03jkC5HaKFn2XGxFxCTtg=
github.com/appleboy/easyssh-proxy v1.2.0/go.mod h1:vHskChUNhxwW4dXMe2MNE/k+UBCkBagrQDm70UWZrS0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 h1:jsG6UpNLt9iAsb0S2AGW28DveNzzgmbXR+ENoPjUeIU=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-7
View File
@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="256px" height="210px" viewBox="0 0 256 210" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
<g>
<rect fill="#000000" x="0" y="0" width="256" height="209.342334" rx="5"></rect>
<path d="M28.2414658,21.7735776 C27.3856638,20.9177756 26.3529412,20.4898746 25.143298,20.4898746 C23.9336548,20.4898746 22.8968177,20.9218901 22.0327869,21.7859209 C21.1810993,22.6376085 20.7490839,23.6744455 20.7490839,24.8840887 C20.7490839,26.0937319 21.1810993,27.1305689 22.0327869,27.9822565 L35.4746384,41.424108 L22.0451302,54.8536162 C21.1810993,55.7176471 20.7490839,56.7544841 20.7367406,57.9641273 C20.7490839,59.1737705 21.1810993,60.2106075 22.0327869,61.0622951 C22.8968177,61.9139826 23.9336548,62.3459981 25.1309547,62.3583414 C26.3529412,62.3583414 27.3897782,61.9263259 28.2538091,61.0622951 L43.1891996,46.1145612 C46.3243973,42.9917068 46.3243973,39.8565092 43.1891996,36.7213115 L28.2414658,21.7735776 L28.2414658,21.7735776 Z M86.7857281,54.8783028 C85.9216972,54.0142719 84.8725169,53.5822565 83.6505304,53.5822565 L83.6505304,53.5760849 L54.8165863,53.5760849 L54.8165863,53.5822565 C53.5945998,53.5822565 52.5577628,54.0142719 51.6937319,54.8783028 C50.8297011,55.7423337 50.3976856,56.7791707 50.3976856,58.0011572 C50.3976856,59.2231437 50.8297011,60.272324 51.6937319,61.1363549 C52.5577628,62.0003857 53.5945998,62.4324012 54.8165863,62.4324012 L54.8165863,62.4262295 L83.6505304,62.4262295 L83.6505304,62.4324012 C84.8725169,62.4324012 85.9216972,62.0003857 86.7857281,61.1363549 C87.6497589,60.272324 88.0817743,59.2231437 88.0817743,58.0011572 C88.0817743,56.7791707 87.6497589,55.7423337 86.7857281,54.8783028 L86.7857281,54.8783028 L86.7857281,54.8783028 Z" fill="#FFFFFF"></path>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.8 KiB

+109 -17
View File
@@ -1,15 +1,21 @@
package main
import (
"log"
"os"
"time"
"github.com/appleboy/easyssh-proxy"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
)
// Version set at compile-time
var Version = "v1.0.0-dev"
var (
Version string
BuildNum string
)
func main() {
@@ -29,33 +35,44 @@ func main() {
cli.StringSliceFlag{
Name: "host, H",
Usage: "Server host",
EnvVar: "PLUGIN_HOST,SCP_HOST",
EnvVar: "PLUGIN_HOST,SCP_HOST,SSH_HOST",
},
cli.StringFlag{
Name: "port, P",
Value: "22",
Usage: "Server port, default to 22",
EnvVar: "PLUGIN_PORT,SCP_PORT",
EnvVar: "PLUGIN_PORT,SCP_PORT,SSH_PORT",
},
cli.StringFlag{
Name: "username, u",
Usage: "Server username",
EnvVar: "PLUGIN_USERNAME,SCP_USERNAME",
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SCP_USERNAME,SSH_USERNAME",
},
cli.StringFlag{
Name: "password, p",
Usage: "Password for password-based authentication",
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD",
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD,SSH_PASSWORD",
},
cli.DurationFlag{
Name: "timeout",
Usage: "connection timeout",
EnvVar: "PLUGIN_TIMEOUT,SCP_TIMEOUT",
},
cli.DurationFlag{
Name: "command.timeout,T",
Usage: "command timeout",
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT",
Value: 60 * time.Second,
},
cli.StringFlag{
Name: "key, k",
Usage: "ssh private key",
EnvVar: "PLUGIN_KEY,SCP_KEY",
EnvVar: "PLUGIN_KEY,SCP_KEY,SSH_KEY",
},
cli.StringFlag{
Name: "key-path, i",
Usage: "ssh private key path",
EnvVar: "PLUGIN_KEY_PATH,SCP_KEY_PATH",
EnvVar: "PLUGIN_KEY_PATH,SCP_KEY_PATH,SSH_KEY_PATH",
},
cli.StringSliceFlag{
Name: "target, t",
@@ -129,6 +146,59 @@ func main() {
Name: "env-file",
Usage: "source env file",
},
cli.StringFlag{
Name: "proxy.ssh-key",
Usage: "private ssh key of proxy",
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY",
},
cli.StringFlag{
Name: "proxy.key-path",
Usage: "ssh private key path of proxy",
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH",
},
cli.StringFlag{
Name: "proxy.username",
Usage: "connect as user of proxy",
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME",
Value: "root",
},
cli.StringFlag{
Name: "proxy.password",
Usage: "user password of proxy",
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD",
},
cli.StringFlag{
Name: "proxy.host",
Usage: "connect to host of proxy",
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST",
},
cli.StringFlag{
Name: "proxy.port",
Usage: "connect to port of proxy",
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT",
Value: "22",
},
cli.DurationFlag{
Name: "proxy.timeout",
Usage: "proxy connection timeout",
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT",
},
cli.IntFlag{
Name: "strip.components",
Usage: "Remove the specified number of leading path elements.",
EnvVar: "PLUGIN_STRIP_COMPONENTS,TAR_STRIP_COMPONENTS",
},
cli.StringFlag{
Name: "tar.exec",
Usage: "Alternative `tar` executable to on the dest host",
EnvVar: "PLUGIN_TAR_EXEC,SCP_TAR_EXEC",
Value: "tar",
},
cli.BoolFlag{
Name: "debug",
Usage: "remove target folder before upload data",
EnvVar: "PLUGIN_DEBUG,DEBUG",
},
}
// Override a template
@@ -163,7 +233,15 @@ VERSION:
REPOSITORY:
Github: https://github.com/appleboy/drone-scp
`
app.Run(os.Args)
app.Version = Version
if BuildNum != "" {
app.Version = app.Version + "+" + BuildNum
}
if err := app.Run(os.Args); err != nil {
log.Println(err)
}
}
func run(c *cli.Context) error {
@@ -187,15 +265,29 @@ func run(c *cli.Context) error {
Link: c.String("build.link"),
},
Config: Config{
Host: c.StringSlice("host"),
Port: c.String("port"),
Username: c.String("username"),
Password: c.String("password"),
Key: c.String("key"),
KeyPath: c.String("key-path"),
Target: c.StringSlice("target"),
Source: c.StringSlice("source"),
Remove: c.Bool("rm"),
Host: c.StringSlice("host"),
Port: c.String("port"),
Username: c.String("username"),
Password: c.String("password"),
Timeout: c.Duration("timeout"),
CommandTimeout: c.Duration("command.timeout"),
Key: c.String("key"),
KeyPath: c.String("key-path"),
Target: c.StringSlice("target"),
Source: c.StringSlice("source"),
Remove: c.Bool("rm"),
Debug: c.Bool("debug"),
StripComponents: c.Int("strip.components"),
TarExec: c.String("tar.exec"),
Proxy: easyssh.DefaultConfig{
Key: c.String("proxy.ssh-key"),
KeyPath: c.String("proxy.key-path"),
User: c.String("proxy.username"),
Password: c.String("proxy.password"),
Server: c.String("proxy.host"),
Port: c.String("proxy.port"),
Timeout: c.Duration("proxy.timeout"),
},
},
}
+281
View File
@@ -0,0 +1,281 @@
{
test:: {
kind: 'pipeline',
name: 'testing',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'vet',
image: 'golang:1.12',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make vet',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'lint',
image: 'golang:1.12',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make lint',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'misspell',
image: 'golang:1.12',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make misspell-check',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'test',
image: 'golang:1.12-alpine',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'apk add git make curl perl bash build-base zlib-dev ucl-dev',
'make ssh-server',
'make test',
'make coverage',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'codecov',
image: 'robertstettner/drone-codecov',
pull: 'always',
settings: {
token: { 'from_secret': 'codecov_token' },
},
},
],
volumes: [
{
name: 'gopath',
temp: {},
},
],
},
build(name, os='linux', arch='amd64'):: {
kind: 'pipeline',
name: os + '-' + arch,
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'build-push',
image: 'golang:1.12',
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
],
when: {
event: {
exclude: [ 'tag' ],
},
},
},
{
name: 'build-tag',
image: 'golang:1.12',
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
],
when: {
event: [ 'tag' ],
},
},
{
name: 'executable',
image: 'golang:1.12',
pull: 'always',
commands: [
'./release/' + os + '/' + arch + '/' + name + ' --help',
],
},
{
name: 'dryrun',
image: 'plugins/docker:' + os + '-' + arch,
pull: 'always',
settings: {
daemon_off: false,
dry_run: true,
tags: os + '-' + arch,
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
repo: 'appleboy/' + name,
cache_from: 'appleboy/' + name,
},
when: {
event: [ 'pull_request' ],
},
},
{
name: 'publish',
image: 'plugins/docker:' + os + '-' + arch,
pull: 'always',
settings: {
daemon_off: 'false',
auto_tag: true,
auto_tag_suffix: os + '-' + arch,
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
repo: 'appleboy/' + name,
cache_from: 'appleboy/' + name,
username: { 'from_secret': 'docker_username' },
password: { 'from_secret': 'docker_password' },
},
when: {
event: {
exclude: [ 'pull_request' ],
},
},
},
],
depends_on: [
'testing',
],
trigger: {
ref: [
'refs/heads/master',
'refs/pull/**',
'refs/tags/**',
],
},
},
release:: {
kind: 'pipeline',
name: 'release-binary',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'build-all-binary',
image: 'golang:1.12',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make release'
],
when: {
event: [ 'tag' ],
},
},
{
name: 'deploy-all-binary',
image: 'plugins/github-release',
pull: 'always',
settings: {
files: [ 'dist/release/*' ],
api_key: { 'from_secret': 'github_release_api_key' },
},
when: {
event: [ 'tag' ],
},
},
],
depends_on: [
'testing',
],
trigger: {
ref: [
'refs/tags/**',
],
},
},
notifications(os='linux', arch='amd64', depends_on=[]):: {
kind: 'pipeline',
name: 'notifications',
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'manifest',
image: 'plugins/manifest',
pull: 'always',
settings: {
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
spec: 'docker/manifest.tmpl',
ignore_missing: true,
},
},
{
name: 'microbadger',
image: 'plugins/webhook:1',
pull: 'always',
settings: {
url: { 'from_secret': 'microbadger_url' },
},
},
],
depends_on: depends_on,
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
],
},
},
signature(key):: {
kind: 'signature',
hmac: key,
}
}
+195 -40
View File
@@ -4,15 +4,23 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"time"
"github.com/appleboy/com/random"
"github.com/appleboy/drone-scp/easyssh"
"github.com/appleboy/easyssh-proxy"
"github.com/fatih/color"
)
var (
errMissingHost = errors.New("Error: missing server host")
errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password")
errSetPasswordandKey = errors.New("can't set password and key at the same time")
errMissingSourceOrTarget = errors.New("missing source or target config")
)
type (
@@ -36,26 +44,40 @@ type (
// Config for the plugin.
Config struct {
Host []string
Port string
Username string
Password string
Key string
KeyPath string
Target []string
Source []string
Remove bool
Host []string
Port string
Username string
Password string
Key string
KeyPath string
Timeout time.Duration
CommandTimeout time.Duration
Target []string
Source []string
Remove bool
StripComponents int
TarExec string
Proxy easyssh.DefaultConfig
Debug bool
}
// Plugin values.
Plugin struct {
Repo Repo
Build Build
Config Config
Repo Repo
Build Build
Config Config
DestFile string
}
copyError struct {
host string
message string
}
)
var wg sync.WaitGroup
func (e copyError) Error() string {
return fmt.Sprintf("error copy file to dest: %s, error message: %s\n", e.host, e.message)
}
func trimPath(keys []string) []string {
var newKeys []string
@@ -72,42 +94,148 @@ func trimPath(keys []string) []string {
return newKeys
}
func globList(paths []string) fileList {
var list fileList
for _, pattern := range paths {
ignore := false
pattern = strings.Trim(pattern, " ")
if string(pattern[0]) == "!" {
pattern = pattern[1:]
ignore = true
}
matches, err := filepath.Glob(pattern)
if err != nil {
fmt.Printf("Glob error for %q: %s\n", pattern, err)
continue
}
if ignore {
list.Ignore = append(list.Ignore, matches...)
} else {
list.Source = append(list.Source, matches...)
}
}
return list
}
func buildArgs(tar string, files fileList) []string {
args := []string{}
if len(files.Ignore) > 0 {
for _, v := range files.Ignore {
args = append(args, "--exclude")
args = append(args, v)
}
}
args = append(args, "-cf")
args = append(args, getRealPath(tar))
args = append(args, files.Source...)
return args
}
func (p Plugin) log(host string, message ...interface{}) {
log.Printf("%s: %s", host, fmt.Sprintln(message...))
if count := len(p.Config.Host); count == 1 {
fmt.Printf("%s", fmt.Sprintln(message...))
} else {
fmt.Printf("%s: %s", host, fmt.Sprintln(message...))
}
}
func (p *Plugin) removeDestFile(ssh *easyssh.MakeConfig) error {
p.log(ssh.Server, "remove file", p.DestFile)
_, errStr, _, err := ssh.Run(fmt.Sprintf("rm -rf %s", p.DestFile), p.Config.CommandTimeout)
if err != nil {
return err
}
if errStr != "" {
return errors.New(errStr)
}
return nil
}
func (p *Plugin) removeAllDestFile() error {
for _, host := range p.Config.Host {
ssh := &easyssh.MakeConfig{
Server: host,
User: p.Config.Username,
Password: p.Config.Password,
Port: p.Config.Port,
Key: p.Config.Key,
KeyPath: p.Config.KeyPath,
Timeout: p.Config.Timeout,
Proxy: easyssh.DefaultConfig{
Server: p.Config.Proxy.Server,
User: p.Config.Proxy.User,
Password: p.Config.Proxy.Password,
Port: p.Config.Proxy.Port,
Key: p.Config.Proxy.Key,
KeyPath: p.Config.Proxy.KeyPath,
Timeout: p.Config.Proxy.Timeout,
},
}
// remove tar file
err := p.removeDestFile(ssh)
if err != nil {
return err
}
}
return nil
}
type fileList struct {
Ignore []string
Source []string
}
// Exec executes the plugin.
func (p Plugin) Exec() error {
func (p *Plugin) Exec() error {
if len(p.Config.Host) == 0 {
return errMissingHost
}
if len(p.Config.Host) == 0 || len(p.Config.Username) == 0 {
return errors.New("missing ssh config (Host, Username)")
if len(p.Config.Key) == 0 && len(p.Config.Password) == 0 && len(p.Config.KeyPath) == 0 {
return errMissingPasswordOrKey
}
if len(p.Config.Key) != 0 && len(p.Config.Password) != 0 {
return errSetPasswordandKey
}
if len(p.Config.Source) == 0 || len(p.Config.Target) == 0 {
return errors.New("missing source or target config")
return errMissingSourceOrTarget
}
files := trimPath(p.Config.Source)
dest := fmt.Sprintf("%s.tar", random.String(10))
files := globList(trimPath(p.Config.Source))
p.DestFile = fmt.Sprintf("%s.tar", random.String(10))
// create a temporary file for the archive
dir, err := ioutil.TempDir("", "")
if err != nil {
return err
}
tar := filepath.Join(dir, dest)
tar := filepath.Join(dir, p.DestFile)
// run archive command
log.Println("tar all files into " + tar)
args := append(append([]string{}, "-cf", getRealPath(tar)), files...)
cmd := exec.Command("tar", args...)
fmt.Println("tar all files into " + tar)
args := buildArgs(tar, files)
cmd := exec.Command(p.Config.TarExec, args...)
if p.Config.Debug {
fmt.Println("$", strings.Join(cmd.Args, " "))
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
wg := sync.WaitGroup{}
wg.Add(len(p.Config.Host))
errChannel := make(chan error, 1)
finished := make(chan bool, 1)
@@ -121,15 +249,25 @@ func (p Plugin) Exec() error {
Port: p.Config.Port,
Key: p.Config.Key,
KeyPath: p.Config.KeyPath,
Timeout: p.Config.Timeout,
Proxy: easyssh.DefaultConfig{
Server: p.Config.Proxy.Server,
User: p.Config.Proxy.User,
Password: p.Config.Proxy.Password,
Port: p.Config.Proxy.Port,
Key: p.Config.Proxy.Key,
KeyPath: p.Config.Proxy.KeyPath,
Timeout: p.Config.Proxy.Timeout,
},
}
// Call Scp method with file you want to upload to remote server.
p.log(host, "scp file to server.")
err = ssh.Scp(tar)
err := ssh.Scp(tar, p.DestFile)
// Handle errors
if err != nil {
errChannel <- err
errChannel <- copyError{host, err.Error()}
return
}
for _, target := range p.Config.Target {
@@ -137,36 +275,46 @@ func (p Plugin) Exec() error {
if p.Config.Remove {
p.log(host, "Remove target folder:", target)
_, err := ssh.Run(fmt.Sprintf("rm -rf %s", target))
_, _, _, err := ssh.Run(fmt.Sprintf("rm -rf %s", target), p.Config.CommandTimeout)
if err != nil {
errChannel <- err
return
}
}
// mkdir path
p.log(host, "create folder", target)
response, _ := ssh.Run(fmt.Sprintf("mkdir -p %s", target))
_, errStr, _, err := ssh.Run(fmt.Sprintf("mkdir -p %s", target), p.Config.CommandTimeout)
if err != nil {
errChannel <- err
return
}
if response != "" {
errChannel <- errors.New(response)
if len(errStr) != 0 {
errChannel <- fmt.Errorf(errStr)
return
}
// untar file
p.log(host, "untar file", dest)
_, err = ssh.Run(fmt.Sprintf("tar -xf %s -C %s", dest, target))
p.log(host, "untar file", p.DestFile)
if p.Config.StripComponents > 0 {
_, _, _, err = ssh.Run(fmt.Sprintf("%s -xf %s --strip-components=%d -C %s", p.Config.TarExec, p.DestFile, p.Config.StripComponents, target), p.Config.CommandTimeout)
} else {
_, _, _, err = ssh.Run(fmt.Sprintf("%s -xf %s -C %s", p.Config.TarExec, p.DestFile, target), p.Config.CommandTimeout)
}
if err != nil {
errChannel <- err
return
}
}
// remove tar file
p.log(host, "remove file", dest)
_, err = ssh.Run(fmt.Sprintf("rm -rf %s", dest))
err = p.removeDestFile(ssh)
if err != nil {
errChannel <- err
return
}
wg.Done()
@@ -183,12 +331,19 @@ func (p Plugin) Exec() error {
case <-finished:
case err := <-errChannel:
if err != nil {
fmt.Println("drone-scp error: ", err)
c := color.New(color.FgRed)
c.Println("drone-scp error: ", err)
if _, ok := err.(copyError); !ok {
fmt.Println("drone-scp rollback: remove all target tmp file")
p.removeAllDestFile()
}
return err
}
}
fmt.Println("================================================")
fmt.Println("Successfully executed transfer data to all host.")
fmt.Println("================================================")
return nil
}
+295 -37
View File
@@ -1,12 +1,15 @@
package main
import (
"github.com/stretchr/testify/assert"
"os"
"os/exec"
"os/user"
"path/filepath"
"testing"
"time"
"github.com/appleboy/easyssh-proxy"
"github.com/stretchr/testify/assert"
)
func TestMissingAllConfig(t *testing.T) {
@@ -45,6 +48,23 @@ func TestMissingSourceConfig(t *testing.T) {
assert.NotNil(t, err)
}
func TestSetPasswordAndKey(t *testing.T) {
plugin := Plugin{
Config: Config{
Host: []string{"example.com"},
Username: "ubuntu",
Port: "443",
Password: "1234",
Key: "test",
},
}
err := plugin.Exec()
assert.NotNil(t, err)
assert.Equal(t, errSetPasswordandKey, err)
}
func TestTrimElement(t *testing.T) {
var input, result []string
@@ -61,7 +81,9 @@ func TestTrimElement(t *testing.T) {
func TestSCPFileFromPublicKey(t *testing.T) {
if os.Getenv("SSH_AUTH_SOCK") != "" {
exec.Command("eval", "`ssh-agent -k`").Run()
if err := exec.Command("eval", "`ssh-agent -k`").Run(); err != nil {
t.Fatalf("exec: %v", err)
}
}
u, err := user.Lookup("drone-scp")
@@ -71,12 +93,14 @@ func TestSCPFileFromPublicKey(t *testing.T) {
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{u.HomeDir + "/test"},
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{filepath.Join(u.HomeDir, "/test")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}
@@ -84,11 +108,11 @@ func TestSCPFileFromPublicKey(t *testing.T) {
assert.Nil(t, err)
// check file exist
if _, err := os.Stat(u.HomeDir + "/test/tests/a.txt"); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(u.HomeDir, "/test/tests/a.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
if _, err := os.Stat(u.HomeDir + "/test/tests/b.txt"); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(u.HomeDir, "/test/tests/b.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
@@ -100,7 +124,166 @@ func TestSCPFileFromPublicKey(t *testing.T) {
assert.Nil(t, err)
// check file exist
if _, err := os.Stat(u.HomeDir + "/test/tests/b.txt"); os.IsExist(err) {
if _, err := os.Stat(filepath.Join(u.HomeDir, "/test/tests/b.txt")); os.IsExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}
func TestSCPWildcardFileList(t *testing.T) {
if os.Getenv("SSH_AUTH_SOCK") != "" {
if err := exec.Command("eval", "`ssh-agent -k`").Run(); err != nil {
t.Fatalf("exec: %v", err)
}
}
u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
Target: []string{filepath.Join(u.HomeDir, "abc")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}
err = plugin.Exec()
assert.Nil(t, err)
// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "abc/tests/global/c.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
if _, err := os.Stat(filepath.Join(u.HomeDir, "abc/tests/global/d.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}
func TestSCPFromProxySetting(t *testing.T) {
u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
Target: []string{filepath.Join(u.HomeDir, "def")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
Proxy: easyssh.DefaultConfig{
Server: "localhost",
User: "drone-scp",
Port: "22",
KeyPath: "./tests/.ssh/id_rsa",
},
},
}
err = plugin.Exec()
assert.Nil(t, err)
// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "def/tests/global/c.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
if _, err := os.Stat(filepath.Join(u.HomeDir, "def/tests/global/d.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}
func TestStripComponentsFlag(t *testing.T) {
if os.Getenv("SSH_AUTH_SOCK") != "" {
if err := exec.Command("eval", "`ssh-agent -k`").Run(); err != nil {
t.Fatalf("exec: %v", err)
}
}
u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
StripComponents: 2,
Target: []string{filepath.Join(u.HomeDir, "123")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}
err = plugin.Exec()
assert.Nil(t, err)
// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "123/c.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
if _, err := os.Stat(filepath.Join(u.HomeDir, "123/d.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}
func TestIgnoreList(t *testing.T) {
if os.Getenv("SSH_AUTH_SOCK") != "" {
if err := exec.Command("eval", "`ssh-agent -k`").Run(); err != nil {
t.Fatalf("exec: %v", err)
}
}
u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"},
StripComponents: 2,
Target: []string{filepath.Join(u.HomeDir, "ignore")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}
err = plugin.Exec()
assert.Nil(t, err)
// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/c.txt")); err == nil {
t.Fatal("c.txt file exist")
}
// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/e.txt")); err == nil {
t.Fatal("c.txt file exist")
}
if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/d.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}
@@ -154,12 +337,14 @@ func TestSCPFileFromPublicKey(t *testing.T) {
func TestIncorrectPassword(t *testing.T) {
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Password: "123456",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{"/home"},
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Password: "123456",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{"/home"},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}
@@ -168,33 +353,106 @@ func TestIncorrectPassword(t *testing.T) {
}
func TestNoPermissionCreateFolder(t *testing.T) {
u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{"/etc/test"},
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{"/etc/test"},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}
err := plugin.Exec()
err = plugin.Exec()
assert.NotNil(t, err)
// check tmp file exist
if _, err = os.Stat(filepath.Join(u.HomeDir, plugin.DestFile)); os.IsExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}
func TestSourceNotFound(t *testing.T) {
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/aa.txt", "tests/b.txt"},
Target: []string{"/test"},
},
func TestGlobList(t *testing.T) {
// wrong patern
paterns := []string{"[]a]", "tests/?.txt"}
expects := []string{"tests/a.txt", "tests/b.txt"}
assert.Equal(t, expects, globList(paterns).Source)
paterns = []string{"tests/*.txt", "tests/.ssh/*", "abc*"}
expects = []string{"tests/a.txt", "tests/b.txt", "tests/.ssh/id_rsa", "tests/.ssh/id_rsa.pub"}
assert.Equal(t, expects, globList(paterns).Source)
paterns = []string{"tests/?.txt"}
expects = []string{"tests/a.txt", "tests/b.txt"}
assert.Equal(t, expects, globList(paterns).Source)
// remove item which file not found.
paterns = []string{"tests/aa.txt", "tests/b.txt"}
expects = []string{"tests/b.txt"}
assert.Equal(t, expects, globList(paterns).Source)
paterns = []string{"./tests/b.txt"}
expects = []string{"./tests/b.txt"}
assert.Equal(t, expects, globList(paterns).Source)
paterns = []string{"./tests/*.txt", "!./tests/b.txt"}
expectSources := []string{"tests/a.txt", "tests/b.txt"}
expectIgnores := []string{"./tests/b.txt"}
result := globList(paterns)
assert.Equal(t, expectSources, result.Source)
assert.Equal(t, expectIgnores, result.Ignore)
}
func TestBuildArgs(t *testing.T) {
list := fileList{
Source: []string{"tests/a.txt", "tests/b.txt", "tests/c.txt"},
Ignore: []string{"tests/a.txt", "tests/b.txt"},
}
err := plugin.Exec()
assert.NotNil(t, err)
result := buildArgs("test.tar.gz", list)
expects := []string{"--exclude", "tests/a.txt", "--exclude", "tests/b.txt", "-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt", "tests/c.txt"}
assert.Equal(t, expects, result)
list = fileList{
Source: []string{"tests/a.txt", "tests/b.txt"},
}
result = buildArgs("test.tar.gz", list)
expects = []string{"-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt"}
assert.Equal(t, expects, result)
}
func TestRemoveDestFile(t *testing.T) {
ssh := &easyssh.MakeConfig{
Server: "localhost",
User: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
// io timeout
Timeout: 1,
}
plugin := Plugin{
Config: Config{
CommandTimeout: 60 * time.Second,
},
DestFile: "/etc/resolv.conf",
}
// ssh io timeout
err := plugin.removeDestFile(ssh)
assert.Error(t, err)
ssh.Timeout = 0
// permission denied
err = plugin.removeDestFile(ssh)
assert.Error(t, err)
}
+1
View File
@@ -0,0 +1 @@
appleboy
View File
View File
View File