mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 18:23:59 +08:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fe231a1c43 | |||
| 177625c6e7 | |||
| bb6466e8d9 | |||
| e5eae442c3 | |||
| b73ec894ab | |||
| 05eba8f809 | |||
| a2493062f7 | |||
| b2b346a0ca | |||
| 9d8f5ac419 | |||
| 5d93e7b8ab | |||
| bf812f8e29 | |||
| 8814cfe72c | |||
| 954e0069e6 | |||
| 03524ed8bd | |||
| 531df19c8c | |||
| df8214b645 | |||
| c85ca1ffd2 | |||
| 933b45bc15 | |||
| 15344d67ae | |||
| cf9e6f260d | |||
| cfa325a8c4 | |||
| c8dbddab25 | |||
| 1b27d28b27 | |||
| 8a0b0f3c0c | |||
| ec489106f9 | |||
| 9ed20ee32d | |||
| 2aee5a3df1 | |||
| bc633e27cf | |||
| 9dad691d4f | |||
| 66579b6dae | |||
| 06609f35cf | |||
| c9771cce78 | |||
| 6088f7da5a | |||
| 6de8f74170 | |||
| bb63d55f89 | |||
| da44b071c4 | |||
| a7eddc4b11 | |||
| 813faf56be | |||
| 4117d2ca30 | |||
| 15bd1a11e4 |
+29
-52
@@ -9,47 +9,39 @@ platform:
|
||||
steps:
|
||||
- name: vet
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- make vet
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: lint
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- make lint
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: misspell
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- make misspell-check
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: test
|
||||
pull: always
|
||||
image: golang:1.12-alpine
|
||||
image: golang:1.13-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
|
||||
@@ -76,12 +68,11 @@ platform:
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp"
|
||||
- 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:
|
||||
@@ -89,19 +80,18 @@ steps:
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp"
|
||||
- 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
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- ./release/linux/amd64/drone-scp --help
|
||||
|
||||
@@ -140,8 +130,8 @@ steps:
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/pull/**"
|
||||
- "refs/tags/**"
|
||||
- refs/pull/**
|
||||
- refs/tags/**
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
@@ -157,12 +147,11 @@ platform:
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp"
|
||||
- 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:
|
||||
@@ -170,19 +159,18 @@ steps:
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp"
|
||||
- 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
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- ./release/linux/arm64/drone-scp --help
|
||||
|
||||
@@ -221,8 +209,8 @@ steps:
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/pull/**"
|
||||
- "refs/tags/**"
|
||||
- refs/pull/**
|
||||
- refs/tags/**
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
@@ -238,12 +226,11 @@ platform:
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp"
|
||||
- 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:
|
||||
@@ -251,19 +238,18 @@ steps:
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp"
|
||||
- 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
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- ./release/linux/arm/drone-scp --help
|
||||
|
||||
@@ -302,8 +288,8 @@ steps:
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/pull/**"
|
||||
- "refs/tags/**"
|
||||
- refs/pull/**
|
||||
- refs/tags/**
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
@@ -319,11 +305,9 @@ platform:
|
||||
steps:
|
||||
- name: build-all-binary
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
image: golang:1.13
|
||||
commands:
|
||||
- make release
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
@@ -335,14 +319,14 @@ steps:
|
||||
api_key:
|
||||
from_secret: github_release_api_key
|
||||
files:
|
||||
- "dist/release/*"
|
||||
- dist/release/*
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- "refs/tags/**"
|
||||
- refs/tags/**
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
@@ -367,17 +351,10 @@ steps:
|
||||
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/**"
|
||||
- refs/tags/**
|
||||
|
||||
depends_on:
|
||||
- linux-amd64
|
||||
|
||||
@@ -11,35 +11,21 @@ image: appleboy/drone-scp
|
||||
The SCP plugin copy files and artifacts to target host machine via SSH. The below pipeline configuration demonstrates simple usage:
|
||||
|
||||
```yaml
|
||||
pipeline:
|
||||
scp:
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host: example.com
|
||||
target: /home/deploy/web
|
||||
source: release.tar.gz
|
||||
```
|
||||
|
||||
Example configuration with custom username, password and port:
|
||||
|
||||
```diff
|
||||
pipeline:
|
||||
scp:
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host: example.com
|
||||
+ username: appleboy
|
||||
+ password: 12345678
|
||||
+ port: 4430
|
||||
target: /home/deploy/web
|
||||
source: release.tar.gz
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host: example.com
|
||||
username: foo
|
||||
password: bar
|
||||
port: 22
|
||||
target: /var/www/deploy/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}
|
||||
source: release.tar.gz
|
||||
```
|
||||
|
||||
Example configuration with multiple source and target folder:
|
||||
|
||||
```diff
|
||||
pipeline:
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host: example.com
|
||||
@@ -54,8 +40,7 @@ pipeline:
|
||||
Example configuration with multiple host:
|
||||
|
||||
```diff
|
||||
pipeline:
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
- host: example.com
|
||||
@@ -69,8 +54,7 @@ pipeline:
|
||||
Example configuration with wildcard pattern of source list:
|
||||
|
||||
```diff
|
||||
pipeline:
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
@@ -86,9 +70,8 @@ pipeline:
|
||||
Remove target folder before copy files and artifacts to target:
|
||||
|
||||
```diff
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
host: example.com
|
||||
settings:
|
||||
target: /home/deploy/web
|
||||
source: release.tar.gz
|
||||
@@ -98,7 +81,7 @@ Remove target folder before copy files and artifacts to target:
|
||||
Example for remove the specified number of leading path elements:
|
||||
|
||||
```diff
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host: example.com
|
||||
@@ -110,8 +93,7 @@ Example for remove the specified number of leading path elements:
|
||||
Example configuration using `SSHProxyCommand`:
|
||||
|
||||
```diff
|
||||
pipeline:
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
@@ -129,8 +111,7 @@ pipeline:
|
||||
Example configuration using password from secrets:
|
||||
|
||||
```diff
|
||||
pipeline:
|
||||
scp:
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
@@ -140,13 +121,73 @@ pipeline:
|
||||
port: 22
|
||||
- password: 1234
|
||||
+ password:
|
||||
from_secret: ssh_password
|
||||
+ from_secret: ssh_password
|
||||
target: /home/deploy/web
|
||||
source:
|
||||
- release/*.tar.gz
|
||||
```
|
||||
|
||||
# Parameter Reference
|
||||
Example configuration using command timeout:
|
||||
|
||||
```diff
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
- example1.com
|
||||
- example2.com
|
||||
user: ubuntu
|
||||
password:
|
||||
from_secret: ssh_password
|
||||
port: 22
|
||||
- command_timeout: 120
|
||||
+ command_timeout: 2m
|
||||
target: /home/deploy/web
|
||||
source:
|
||||
- release/*.tar.gz
|
||||
```
|
||||
|
||||
Example configuration for ignore list:
|
||||
|
||||
```diff
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
- example1.com
|
||||
- example2.com
|
||||
user: ubuntu
|
||||
password:
|
||||
from_secret: ssh_password
|
||||
port: 22
|
||||
command_timeout: 2m
|
||||
target: /home/deploy/web
|
||||
source:
|
||||
+ - !release/README.md
|
||||
- release/*
|
||||
```
|
||||
|
||||
Example configuration for passphrase which protecting a private key:
|
||||
|
||||
```diff
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
- example1.com
|
||||
- example2.com
|
||||
user: ubuntu
|
||||
+ key:
|
||||
+ from_secret: ssh_key
|
||||
+ passphrase: 1234
|
||||
port: 22
|
||||
command_timeout: 2m
|
||||
target: /home/deploy/web
|
||||
source:
|
||||
- release/*
|
||||
```
|
||||
|
||||
## Parameter Reference
|
||||
|
||||
host
|
||||
: target hostname or IP
|
||||
@@ -163,6 +204,9 @@ password
|
||||
key
|
||||
: plain text of user private key
|
||||
|
||||
ssh_passphrase
|
||||
: The purpose of the passphrase is usually to encrypt the private key.
|
||||
|
||||
target
|
||||
: folder path of target host
|
||||
|
||||
@@ -173,11 +217,23 @@ rm
|
||||
: remove target folder before copy files and artifacts
|
||||
|
||||
timeout
|
||||
: timeout is the maximum amount of time for the TCP connection to establish
|
||||
: Timeout is the maximum amount of time for the ssh connection to establish, default is 30 seconds.
|
||||
|
||||
command_timeout
|
||||
: Command timeout is the maximum amount of time for the execute commands, default is 10 minutes.
|
||||
|
||||
strip_components
|
||||
: remove the specified number of leading path elements
|
||||
|
||||
tar_tmp_path
|
||||
: temporary path for tar file on the dest host
|
||||
|
||||
tar_exec
|
||||
: alternative `tar` executable to on the dest host
|
||||
|
||||
overwrite
|
||||
: use `--overwrite` flag with tar
|
||||
|
||||
proxy_host
|
||||
: proxy hostname or IP
|
||||
|
||||
@@ -196,7 +252,10 @@ proxy_key
|
||||
proxy_key_path
|
||||
: key path of proxy private key
|
||||
|
||||
# Template Reference
|
||||
proxy_ssh_passphrase
|
||||
: The purpose of the passphrase is usually to encrypt the private key.
|
||||
|
||||
## Template Reference
|
||||
|
||||
repo.owner
|
||||
: repository owner
|
||||
|
||||
@@ -8,6 +8,7 @@ DEPLOY_ACCOUNT := appleboy
|
||||
DEPLOY_IMAGE := $(EXECUTABLE)
|
||||
|
||||
TARGETS ?= linux darwin windows
|
||||
ARCHS ?= amd64 386
|
||||
PACKAGES ?= $(shell $(GO) list ./...)
|
||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
TAGS ?=
|
||||
@@ -82,7 +83,7 @@ release-build:
|
||||
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
|
||||
$(GO) get -u github.com/mitchellh/gox; \
|
||||
fi
|
||||
gox -os="$(TARGETS)" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
|
||||
gox -os="$(TARGETS)" -arch="$(ARCHS)" -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));)
|
||||
@@ -121,7 +122,8 @@ ssh-server:
|
||||
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
|
||||
cat tests/.ssh/id_rsa.pub >> /home/drone-scp/.ssh/authorized_keys
|
||||
cat tests/.ssh/test.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
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# drone-scp
|
||||
|
||||
[](https://godoc.org/github.com/appleboy/drone-scp)
|
||||
[](https://godoc.org/github.com/appleboy/drone-scp)
|
||||
[](https://cloud.drone.io/appleboy/drone-scp)
|
||||
[](https://codecov.io/gh/appleboy/drone-scp)
|
||||
[](https://goreportcard.com/report/github.com/appleboy/drone-scp)
|
||||
[](https://hub.docker.com/r/appleboy/drone-scp/)
|
||||
[](https://microbadger.com/images/appleboy/drone-scp "Get your own image badge on microbadger.com")
|
||||
[](https://codecov.io/gh/appleboy/drone-scp)
|
||||
[](https://goreportcard.com/report/github.com/appleboy/drone-scp)
|
||||
[](https://hub.docker.com/r/appleboy/drone-scp/)
|
||||
[](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://docs.drone.io/).
|
||||
|
||||
@@ -18,17 +18,39 @@ Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://doc
|
||||
* [x] Support load ssh key from absolute path or raw body.
|
||||
* [x] Support SSH ProxyCommand.
|
||||
|
||||
```sh
|
||||
+--------+ +----------+ +-----------+
|
||||
| Laptop | <--> | Jumphost | <--> | FooServer |
|
||||
+--------+ +----------+ +-----------+
|
||||
|
||||
OR
|
||||
|
||||
+--------+ +----------+ +-----------+
|
||||
| Laptop | <--> | Firewall | <--> | FooServer |
|
||||
+--------+ +----------+ +-----------+
|
||||
192.168.1.5 121.1.2.3 10.10.29.68
|
||||
```
|
||||
+--------+ +----------+ +-----------+
|
||||
| Laptop | <--> | Jumphost | <--> | FooServer |
|
||||
+--------+ +----------+ +-----------+
|
||||
|
||||
OR
|
||||
## Breaking changes
|
||||
|
||||
+--------+ +----------+ +-----------+
|
||||
| Laptop | <--> | Firewall | <--> | FooServer |
|
||||
+--------+ +----------+ +-----------+
|
||||
192.168.1.5 121.1.2.3 10.10.29.68
|
||||
`v1.5.0`: change command timeout flag to `Duration`. See the following setting:
|
||||
|
||||
```diff
|
||||
- name: scp files
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
- example1.com
|
||||
- example2.com
|
||||
username: ubuntu
|
||||
password:
|
||||
from_secret: ssh_password
|
||||
port: 22
|
||||
- command_timeout: 120
|
||||
+ command_timeout: 2m
|
||||
target: /home/deploy/web
|
||||
source:
|
||||
- release/*.tar.gz
|
||||
```
|
||||
|
||||
## Build or Download a binary
|
||||
@@ -41,37 +63,30 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
|
||||
|
||||
With `Go` installed
|
||||
|
||||
```sh
|
||||
export GO111MODULE=on
|
||||
go get -u -v github.com/appleboy/drone-scp
|
||||
```
|
||||
$ go get -u -v github.com/appleboy/drone-scp
|
||||
```
|
||||
|
||||
or build the binary with the following command:
|
||||
|
||||
```
|
||||
$ export GOOS=linux
|
||||
$ export GOARCH=amd64
|
||||
$ export CGO_ENABLED=0
|
||||
$ export GO111MODULE=on
|
||||
```sh
|
||||
export GOOS=linux
|
||||
export GOARCH=amd64
|
||||
export CGO_ENABLED=0
|
||||
export GO111MODULE=on
|
||||
|
||||
$ go test -cover ./...
|
||||
go test -cover ./...
|
||||
|
||||
$ go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
|
||||
go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
|
||||
```
|
||||
|
||||
## Docker
|
||||
|
||||
Build the docker image with the following commands:
|
||||
|
||||
```
|
||||
$ make docker
|
||||
```
|
||||
|
||||
Please note incorrectly building the image for the correct x64 linux and with
|
||||
CGO disabled will result in an error when running the Docker image:
|
||||
|
||||
```
|
||||
docker: Error response from daemon: Container command
|
||||
'/bin/drone-scp' not found or does not exist..
|
||||
```sh
|
||||
make docker
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -82,7 +97,6 @@ There are three ways to send notification.
|
||||
* [usage from docker](#usage-from-docker)
|
||||
* [usage from drone ci](#usage-from-drone-ci)
|
||||
|
||||
<a name="usage-from-binary"></a>
|
||||
### Usage from binary
|
||||
|
||||
#### Using public key
|
||||
@@ -117,8 +131,8 @@ eval `ssh-agent -s`
|
||||
|
||||
Import your local public key `~/.ssh/id_rsa`
|
||||
|
||||
```bash
|
||||
$ ssh-add
|
||||
```sh
|
||||
ssh-add
|
||||
```
|
||||
|
||||
You don't need to add `--password` or `--key-path` arguments.
|
||||
@@ -145,10 +159,9 @@ drone-scp --host example1.com \
|
||||
+ --source your_local_folder_path_2
|
||||
```
|
||||
|
||||
<a name="usage-from-docker"></a>
|
||||
### Usage from docker
|
||||
|
||||
#### Using public key
|
||||
Using public key
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
@@ -163,7 +176,7 @@ docker run --rm \
|
||||
appleboy/drone-scp
|
||||
```
|
||||
|
||||
#### Using password
|
||||
Using password
|
||||
|
||||
```diff
|
||||
docker run --rm \
|
||||
@@ -178,9 +191,7 @@ docker run --rm \
|
||||
appleboy/drone-scp
|
||||
```
|
||||
|
||||
#### Using ssh-agent
|
||||
|
||||
Start your local ssh agent:
|
||||
Using ssh-agent, start your local ssh agent:
|
||||
|
||||
```bash
|
||||
eval `ssh-agent -s`
|
||||
@@ -188,11 +199,11 @@ eval `ssh-agent -s`
|
||||
|
||||
Import your local public key `~/.ssh/id_rsa`
|
||||
|
||||
```bash
|
||||
$ ssh-add
|
||||
```sh
|
||||
ssh-add
|
||||
```
|
||||
|
||||
You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH ` arguments.
|
||||
You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH` arguments.
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
@@ -206,7 +217,7 @@ docker run --rm \
|
||||
appleboy/drone-scp
|
||||
```
|
||||
|
||||
#### Send multiple source or target folder and hosts
|
||||
Send multiple source or target folder and hosts
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
@@ -221,7 +232,6 @@ docker run --rm \
|
||||
appleboy/drone-scp
|
||||
```
|
||||
|
||||
<a name="usage-from-drone-ci"></a>
|
||||
### Usage from drone ci
|
||||
|
||||
Execute from the working directory:
|
||||
@@ -247,6 +257,6 @@ You can get more [information](http://plugins.drone.io/appleboy/drone-scp/) abou
|
||||
|
||||
Test the package with the following command:
|
||||
|
||||
```
|
||||
$ make test
|
||||
```sh
|
||||
make test
|
||||
```
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
module github.com/appleboy/drone-scp
|
||||
|
||||
go 1.12
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/appleboy/com v0.0.1
|
||||
github.com/appleboy/easyssh-proxy v0.0.0-20170511070730-14882d1d04ac
|
||||
github.com/fatih/color v1.4.1
|
||||
github.com/appleboy/com v0.0.2
|
||||
github.com/appleboy/easyssh-proxy v1.3.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
|
||||
golang.org/x/crypto v0.0.0-20170413182223-cbc3d0884eac // indirect
|
||||
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10 // indirect
|
||||
github.com/mattn/go-colorable v0.1.4 // indirect
|
||||
github.com/mattn/go-isatty v0.0.10 // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/urfave/cli/v2 v2.1.1
|
||||
)
|
||||
|
||||
@@ -1,35 +1,49 @@
|
||||
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 v0.0.0-20170511070730-14882d1d04ac h1:OcOz99ulMMpNqjpRVE8UBqFo5pyRamELU6xZuOR7GJs=
|
||||
github.com/appleboy/easyssh-proxy v0.0.0-20170511070730-14882d1d04ac/go.mod h1:bQbHdUQpAmc4Nv22/0slLXWdllbncGfA9ALkPuCe704=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681 h1:JS2rl38kZmHgWa0xINSaSYH0Whtvem64/4+Ef0+Y5pE=
|
||||
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681/go.mod h1:WfDateMPQ/55dPbZRp5Zxrux5WiEaHsjk9puUhz0KgY=
|
||||
github.com/appleboy/com v0.0.2 h1:sexcPX7gp7peXMlOJMxEYcRucW7DW0XHgFZqUB6PI6g=
|
||||
github.com/appleboy/com v0.0.2/go.mod h1:jnufjIC3opMlReyPPPye+8JqNvUzLm25o7h6SOy8nv0=
|
||||
github.com/appleboy/easyssh-proxy v1.3.0 h1:ToH+hZDPWP9/9E58lwxDLJQSHvgGgDAQ9ZVx6x5oofI=
|
||||
github.com/appleboy/easyssh-proxy v1.3.0/go.mod h1:Kk57I3w7OCafOjp5kgZFvxk2fO8Tca5CriBTOsbSbjY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
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.4.1 h1:YJhD/SoQqn7ev9zwhIm7lHTAqsOAF2AN4xlAVZzNZnU=
|
||||
github.com/fatih/color v1.4.1/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
|
||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
|
||||
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/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
|
||||
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||
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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1 h1:Zx8Rp9ozC4FPFxfEKRSUu8+Ay3sZxEUZ7JrCWMbGgvE=
|
||||
github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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.19.1 h1:0mKm4ZoB74PxYmZVua162y1dGt1qc10MyymYRBf3lb8=
|
||||
github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
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-20170413182223-cbc3d0884eac h1:XuNEIEGF9/ewb6jVpjEjwb46FsNjTtgWCseDgY136n0=
|
||||
golang.org/x/crypto v0.0.0-20170413182223-cbc3d0884eac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
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=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
|
||||
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90onWEf1dF4C+0hPJCc9Mpc=
|
||||
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||
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=
|
||||
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10 h1:xQJI9OEiErEQ++DoXOHqEpzsGMrAv2Q2jyCpi7DmfpQ=
|
||||
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
|
||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -3,26 +3,26 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/appleboy/easyssh-proxy"
|
||||
"github.com/joho/godotenv"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version set at compile-time
|
||||
var (
|
||||
Version string
|
||||
BuildNum string
|
||||
Version string
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "Drone SCP"
|
||||
app.Usage = "Copy files and artifacts via SSH."
|
||||
app.Copyright = "Copyright (c) 2017 Bo-Yi Wu"
|
||||
app.Authors = []cli.Author{
|
||||
app.Copyright = "Copyright (c) 2019 Bo-Yi Wu"
|
||||
app.Version = Version
|
||||
app.Authors = []*cli.Author{
|
||||
{
|
||||
Name: "Bo-Yi Wu",
|
||||
Email: "appleboy.tw@gmail.com",
|
||||
@@ -31,172 +31,193 @@ func main() {
|
||||
app.Action = run
|
||||
app.Version = Version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "host, H",
|
||||
Usage: "Server host",
|
||||
EnvVar: "PLUGIN_HOST,SCP_HOST,SSH_HOST",
|
||||
&cli.StringSliceFlag{
|
||||
Name: "host, H",
|
||||
Usage: "Server host",
|
||||
EnvVars: []string{"PLUGIN_HOST", "SCP_HOST", "SSH_HOST", "HOST", "INPUT_HOST"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "port, P",
|
||||
Value: "22",
|
||||
Usage: "Server port, default to 22",
|
||||
EnvVar: "PLUGIN_PORT,SCP_PORT,SSH_PORT",
|
||||
&cli.StringFlag{
|
||||
Name: "port, P",
|
||||
Value: "22",
|
||||
Usage: "Server port, default to 22",
|
||||
EnvVars: []string{"PLUGIN_PORT", "SCP_PORT", "SSH_PORT", "PORT", "INPUT_PORT"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username, u",
|
||||
Usage: "Server username",
|
||||
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SCP_USERNAME,SSH_USERNAME",
|
||||
&cli.StringFlag{
|
||||
Name: "username, u",
|
||||
Usage: "Server username",
|
||||
EnvVars: []string{"PLUGIN_USERNAME", "PLUGIN_USER", "SCP_USERNAME", "SSH_USERNAME", "USERNAME", "INPUT_USERNAME"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password, p",
|
||||
Usage: "Password for password-based authentication",
|
||||
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD,SSH_PASSWORD",
|
||||
&cli.StringFlag{
|
||||
Name: "password, p",
|
||||
Usage: "Password for password-based authentication",
|
||||
EnvVars: []string{"PLUGIN_PASSWORD", "SCP_PASSWORD", "SSH_PASSWORD", "PASSWORD", "INPUT_PASSWORD"},
|
||||
},
|
||||
cli.DurationFlag{
|
||||
Name: "timeout",
|
||||
Usage: "connection timeout",
|
||||
EnvVar: "PLUGIN_TIMEOUT,SCP_TIMEOUT",
|
||||
&cli.DurationFlag{
|
||||
Name: "timeout",
|
||||
Usage: "connection timeout",
|
||||
EnvVars: []string{"PLUGIN_TIMEOUT", "SCP_TIMEOUT", "INPUT_TIMEOUT"},
|
||||
Value: 30 * time.Second,
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "command.timeout,T",
|
||||
Usage: "command timeout",
|
||||
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT",
|
||||
Value: 60,
|
||||
&cli.DurationFlag{
|
||||
Name: "command.timeout",
|
||||
Usage: "command timeout",
|
||||
EnvVars: []string{"PLUGIN_COMMAND_TIMEOUT", "SSH_COMMAND_TIMEOUT", "INPUT_COMMAND_TIMEOUT"},
|
||||
Value: 10 * time.Minute,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "key, k",
|
||||
Usage: "ssh private key",
|
||||
EnvVar: "PLUGIN_KEY,SCP_KEY,SSH_KEY",
|
||||
&cli.StringFlag{
|
||||
Name: "ssh-key, k",
|
||||
Usage: "ssh private key",
|
||||
EnvVars: []string{"PLUGIN_SSH_KEY,", "PLUGIN_KEY", "SCP_KEY", "SSH_KEY", "KEY", "INPUT_KEY"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "key-path, i",
|
||||
Usage: "ssh private key path",
|
||||
EnvVar: "PLUGIN_KEY_PATH,SCP_KEY_PATH,SSH_KEY_PATH",
|
||||
&cli.StringFlag{
|
||||
Name: "ssh-passphrase",
|
||||
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
||||
EnvVars: []string{"PLUGIN_SSH_PASSPHRASE", "PLUGIN_PASSPHRASE", "SSH_PASSPHRASE", "PASSPHRASE", "INPUT_PASSPHRASE"},
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "target, t",
|
||||
Usage: "Target path on the server",
|
||||
EnvVar: "PLUGIN_TARGET,SCP_TARGET",
|
||||
&cli.StringFlag{
|
||||
Name: "key-path, i",
|
||||
Usage: "ssh private key path",
|
||||
EnvVars: []string{"PLUGIN_KEY_PATH", "SCP_KEY_PATH", "SSH_KEY_PATH", "INPUT_KEY_PATH"},
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "source, s",
|
||||
Usage: "scp file list",
|
||||
EnvVar: "PLUGIN_SOURCE,SCP_SOURCE",
|
||||
&cli.StringSliceFlag{
|
||||
Name: "target, t",
|
||||
Usage: "Target path on the server",
|
||||
EnvVars: []string{"PLUGIN_TARGET", "SCP_TARGET", "TARGET", "INPUT_TARGET"},
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "rm, r",
|
||||
Usage: "remove target folder before upload data",
|
||||
EnvVar: "PLUGIN_RM,SCP_RM",
|
||||
&cli.StringSliceFlag{
|
||||
Name: "source, s",
|
||||
Usage: "scp file list",
|
||||
EnvVars: []string{"PLUGIN_SOURCE", "SCP_SOURCE", "SOURCE", "INPUT_SOURCE"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
Usage: "repository owner",
|
||||
EnvVar: "DRONE_REPO_OWNER",
|
||||
&cli.BoolFlag{
|
||||
Name: "rm, r",
|
||||
Usage: "remove target folder before upload data",
|
||||
EnvVars: []string{"PLUGIN_RM", "SCP_RM", "RM", "INPUT_RM"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "repository name",
|
||||
EnvVar: "DRONE_REPO_NAME",
|
||||
&cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
Usage: "repository owner",
|
||||
EnvVars: []string{"DRONE_REPO_OWNER"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "git commit sha",
|
||||
EnvVar: "DRONE_COMMIT_SHA",
|
||||
&cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "repository name",
|
||||
EnvVars: []string{"DRONE_REPO_NAME"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Value: "master",
|
||||
Usage: "git commit branch",
|
||||
EnvVar: "DRONE_COMMIT_BRANCH",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "git commit sha",
|
||||
EnvVars: []string{"DRONE_COMMIT_SHA"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.author",
|
||||
Usage: "git author name",
|
||||
EnvVar: "DRONE_COMMIT_AUTHOR",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Value: "master",
|
||||
Usage: "git commit branch",
|
||||
EnvVars: []string{"DRONE_COMMIT_BRANCH"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
EnvVar: "DRONE_COMMIT_MESSAGE",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author",
|
||||
Usage: "git author name",
|
||||
EnvVars: []string{"DRONE_COMMIT_AUTHOR"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.event",
|
||||
Value: "push",
|
||||
Usage: "build event",
|
||||
EnvVar: "DRONE_BUILD_EVENT",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
EnvVars: []string{"DRONE_COMMIT_MESSAGE"},
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "build.number",
|
||||
Usage: "build number",
|
||||
EnvVar: "DRONE_BUILD_NUMBER",
|
||||
&cli.StringFlag{
|
||||
Name: "build.event",
|
||||
Value: "push",
|
||||
Usage: "build event",
|
||||
EnvVars: []string{"DRONE_BUILD_EVENT"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "build status",
|
||||
Value: "success",
|
||||
EnvVar: "DRONE_BUILD_STATUS",
|
||||
&cli.IntFlag{
|
||||
Name: "build.number",
|
||||
Usage: "build number",
|
||||
EnvVars: []string{"DRONE_BUILD_NUMBER"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.link",
|
||||
Usage: "build link",
|
||||
EnvVar: "DRONE_BUILD_LINK",
|
||||
&cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "build status",
|
||||
Value: "success",
|
||||
EnvVars: []string{"DRONE_BUILD_STATUS"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "build.link",
|
||||
Usage: "build link",
|
||||
EnvVars: []string{"DRONE_BUILD_LINK"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
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.ssh-key",
|
||||
Usage: "private ssh key of proxy",
|
||||
EnvVars: []string{"PLUGIN_PROXY_SSH_KEY", "PLUGIN_PROXY_KEY", "PROXY_SSH_KEY", "PROXY_KEY", "INPUT_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.ssh-passphrase",
|
||||
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
||||
EnvVars: []string{"PLUGIN_PROXY_SSH_PASSPHRASE", "PLUGIN_PROXY_PASSPHRASE", "PROXY_SSH_PASSPHRASE,PROXY_PASSPHRASE", "INPUT_PROXY_PASSPHRASE"},
|
||||
},
|
||||
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.key-path",
|
||||
Usage: "ssh private key path of proxy",
|
||||
EnvVars: []string{"PLUGIN_PROXY_KEY_PATH", "PROXY_SSH_KEY_PATH", "INPUT_PROXY_SSH_KEY_PATH"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy.password",
|
||||
Usage: "user password of proxy",
|
||||
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD",
|
||||
&cli.StringFlag{
|
||||
Name: "proxy.username",
|
||||
Usage: "connect as user of proxy",
|
||||
EnvVars: []string{"PLUGIN_PROXY_USERNAME", "PLUGIN_PROXY_USER", "PROXY_SSH_USERNAME", "PROXY_USERNAME", "INPUT_PROXY_USERNAME"},
|
||||
Value: "root",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy.host",
|
||||
Usage: "connect to host of proxy",
|
||||
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST",
|
||||
&cli.StringFlag{
|
||||
Name: "proxy.password",
|
||||
Usage: "user password of proxy",
|
||||
EnvVars: []string{"PLUGIN_PROXY_PASSWORD", "PROXY_SSH_PASSWORD", "PROXY_PASSWORD", "INPUT_PROXY_PASSWORD"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy.port",
|
||||
Usage: "connect to port of proxy",
|
||||
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT",
|
||||
Value: "22",
|
||||
&cli.StringFlag{
|
||||
Name: "proxy.host",
|
||||
Usage: "connect to host of proxy",
|
||||
EnvVars: []string{"PLUGIN_PROXY_HOST", "PROXY_SSH_HOST", "PROXY_HOST", "INPUT_PROXY_HOST"},
|
||||
},
|
||||
cli.DurationFlag{
|
||||
Name: "proxy.timeout",
|
||||
Usage: "proxy connection timeout",
|
||||
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT",
|
||||
&cli.StringFlag{
|
||||
Name: "proxy.port",
|
||||
Usage: "connect to port of proxy",
|
||||
EnvVars: []string{"PLUGIN_PROXY_PORT", "PROXY_SSH_PORT", "PROXY_PORT", "INPUT_PROXY_PORT"},
|
||||
Value: "22",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "strip.components",
|
||||
Usage: "Remove the specified number of leading path elements.",
|
||||
EnvVar: "PLUGIN_STRIP_COMPONENTS,TAR_STRIP_COMPONENTS",
|
||||
&cli.DurationFlag{
|
||||
Name: "proxy.timeout",
|
||||
Usage: "proxy connection timeout",
|
||||
EnvVars: []string{"PLUGIN_PROXY_TIMEOUT", "PROXY_SSH_TIMEOUT", "INPUT_PROXY_TIMEOUT"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tar.exec",
|
||||
Usage: "Alternative `tar` executable to on the dest host",
|
||||
EnvVar: "PLUGIN_TAR_EXEC,SCP_TAR_EXEC",
|
||||
Value: "tar",
|
||||
&cli.IntFlag{
|
||||
Name: "strip.components",
|
||||
Usage: "Remove the specified number of leading path elements.",
|
||||
EnvVars: []string{"PLUGIN_STRIP_COMPONENTS", "TAR_STRIP_COMPONENTS", "INPUT_STRIP_COMPONENTS"},
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "remove target folder before upload data",
|
||||
EnvVar: "PLUGIN_DEBUG,DEBUG",
|
||||
&cli.StringFlag{
|
||||
Name: "tar.exec",
|
||||
Usage: "Alternative `tar` executable to on the dest host",
|
||||
EnvVars: []string{"PLUGIN_TAR_EXEC", "SCP_TAR_EXEC", "INPUT_TAR_EXEC"},
|
||||
Value: "tar",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "tar.tmp-path",
|
||||
Usage: "Temporary path for tar file on the dest host",
|
||||
EnvVars: []string{"PLUGIN_TAR_TMP_PATH", "SCP_TAR_TMP_PATH"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "remove target folder before upload data",
|
||||
EnvVars: []string{"PLUGIN_DEBUG", "DEBUG", "INPUT_DEBUG"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "overwrite",
|
||||
Usage: "use --overwrite flag with tar",
|
||||
EnvVars: []string{"PLUGIN_OVERWRITE", "SCP_OVERWRITE", "INPUT_OVERWRITE"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -232,14 +253,9 @@ VERSION:
|
||||
REPOSITORY:
|
||||
Github: https://github.com/appleboy/drone-scp
|
||||
`
|
||||
app.Version = Version
|
||||
|
||||
if BuildNum != "" {
|
||||
app.Version = app.Version + "+" + BuildNum
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Println(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,9 +284,10 @@ func run(c *cli.Context) error {
|
||||
Port: c.String("port"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
Passphrase: c.String("ssh-passphrase"),
|
||||
Timeout: c.Duration("timeout"),
|
||||
CommandTimeout: c.Int("command.timeout"),
|
||||
Key: c.String("key"),
|
||||
CommandTimeout: c.Duration("command.timeout"),
|
||||
Key: c.String("ssh-key"),
|
||||
KeyPath: c.String("key-path"),
|
||||
Target: c.StringSlice("target"),
|
||||
Source: c.StringSlice("source"),
|
||||
@@ -278,14 +295,17 @@ func run(c *cli.Context) error {
|
||||
Debug: c.Bool("debug"),
|
||||
StripComponents: c.Int("strip.components"),
|
||||
TarExec: c.String("tar.exec"),
|
||||
TarTmpPath: c.String("tar.tmp-path"),
|
||||
Overwrite: c.Bool("overwrite"),
|
||||
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"),
|
||||
Key: c.String("proxy.ssh-key"),
|
||||
Passphrase: c.String("proxy.ssh-passphrase"),
|
||||
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"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetRealPath(t *testing.T) {
|
||||
type args struct {
|
||||
|
||||
+8
-33
@@ -9,11 +9,8 @@
|
||||
steps: [
|
||||
{
|
||||
name: 'vet',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make vet',
|
||||
],
|
||||
@@ -26,11 +23,8 @@
|
||||
},
|
||||
{
|
||||
name: 'lint',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make lint',
|
||||
],
|
||||
@@ -43,11 +37,8 @@
|
||||
},
|
||||
{
|
||||
name: 'misspell',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make misspell-check',
|
||||
],
|
||||
@@ -60,11 +51,8 @@
|
||||
},
|
||||
{
|
||||
name: 'test',
|
||||
image: 'golang:1.12-alpine',
|
||||
image: 'golang:1.13-alpine',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'apk add git make curl perl bash build-base zlib-dev ucl-dev',
|
||||
'make ssh-server',
|
||||
@@ -105,11 +93,10 @@
|
||||
steps: [
|
||||
{
|
||||
name: 'build-push',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
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,
|
||||
@@ -122,11 +109,10 @@
|
||||
},
|
||||
{
|
||||
name: 'build-tag',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
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,
|
||||
@@ -137,7 +123,7 @@
|
||||
},
|
||||
{
|
||||
name: 'executable',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
pull: 'always',
|
||||
commands: [
|
||||
'./release/' + os + '/' + arch + '/' + name + ' --help',
|
||||
@@ -202,11 +188,8 @@
|
||||
steps: [
|
||||
{
|
||||
name: 'build-all-binary',
|
||||
image: 'golang:1.12',
|
||||
image: 'golang:1.13',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make release'
|
||||
],
|
||||
@@ -256,14 +239,6 @@
|
||||
ignore_missing: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'microbadger',
|
||||
image: 'plugins/webhook:1',
|
||||
pull: 'always',
|
||||
settings: {
|
||||
url: { 'from_secret': 'microbadger_url' },
|
||||
},
|
||||
},
|
||||
],
|
||||
depends_on: depends_on,
|
||||
trigger: {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -49,16 +50,19 @@ type (
|
||||
Username string
|
||||
Password string
|
||||
Key string
|
||||
Passphrase string
|
||||
KeyPath string
|
||||
Timeout time.Duration
|
||||
CommandTimeout int
|
||||
CommandTimeout time.Duration
|
||||
Target []string
|
||||
Source []string
|
||||
Remove bool
|
||||
StripComponents int
|
||||
TarExec string
|
||||
TarTmpPath string
|
||||
Proxy easyssh.DefaultConfig
|
||||
Debug bool
|
||||
Overwrite bool
|
||||
}
|
||||
|
||||
// Plugin values.
|
||||
@@ -161,21 +165,23 @@ func (p *Plugin) removeDestFile(ssh *easyssh.MakeConfig) error {
|
||||
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,
|
||||
Server: host,
|
||||
User: p.Config.Username,
|
||||
Password: p.Config.Password,
|
||||
Port: p.Config.Port,
|
||||
Key: p.Config.Key,
|
||||
KeyPath: p.Config.KeyPath,
|
||||
Passphrase: p.Config.Passphrase,
|
||||
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,
|
||||
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,
|
||||
Passphrase: p.Config.Proxy.Passphrase,
|
||||
Timeout: p.Config.Proxy.Timeout,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -194,6 +200,32 @@ type fileList struct {
|
||||
Source []string
|
||||
}
|
||||
|
||||
func (p *Plugin) buildArgs(target string) []string {
|
||||
args := []string{}
|
||||
|
||||
args = append(args,
|
||||
p.Config.TarExec,
|
||||
"-xf",
|
||||
p.DestFile,
|
||||
)
|
||||
|
||||
if p.Config.StripComponents > 0 {
|
||||
args = append(args, "--strip-components")
|
||||
args = append(args, strconv.Itoa(p.Config.StripComponents))
|
||||
}
|
||||
|
||||
if p.Config.Overwrite {
|
||||
args = append(args, "--overwrite")
|
||||
}
|
||||
|
||||
args = append(args,
|
||||
"-C",
|
||||
target,
|
||||
)
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
// Exec executes the plugin.
|
||||
func (p *Plugin) Exec() error {
|
||||
if len(p.Config.Host) == 0 {
|
||||
@@ -237,30 +269,35 @@ func (p *Plugin) Exec() error {
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(p.Config.Host))
|
||||
errChannel := make(chan error, 1)
|
||||
finished := make(chan bool, 1)
|
||||
errChannel := make(chan error)
|
||||
finished := make(chan struct{})
|
||||
for _, host := range p.Config.Host {
|
||||
go func(host string) {
|
||||
// Create MakeConfig instance with remote username, server address and path to private key.
|
||||
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,
|
||||
Server: host,
|
||||
User: p.Config.Username,
|
||||
Password: p.Config.Password,
|
||||
Port: p.Config.Port,
|
||||
Key: p.Config.Key,
|
||||
KeyPath: p.Config.KeyPath,
|
||||
Passphrase: p.Config.Passphrase,
|
||||
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,
|
||||
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,
|
||||
Passphrase: p.Config.Proxy.Passphrase,
|
||||
Timeout: p.Config.Proxy.Timeout,
|
||||
},
|
||||
}
|
||||
|
||||
// upload file to the tmp path
|
||||
p.DestFile = fmt.Sprintf("%s%s", p.Config.TarTmpPath, p.DestFile)
|
||||
|
||||
// Call Scp method with file you want to upload to remote server.
|
||||
p.log(host, "scp file to server.")
|
||||
err := ssh.Scp(tar, p.DestFile)
|
||||
@@ -298,10 +335,18 @@ func (p *Plugin) Exec() error {
|
||||
|
||||
// untar file
|
||||
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)
|
||||
commamd := strings.Join(p.buildArgs(target), " ")
|
||||
if p.Config.Debug {
|
||||
fmt.Println("$", commamd)
|
||||
}
|
||||
outStr, errStr, _, err := ssh.Run(commamd, p.Config.CommandTimeout)
|
||||
|
||||
if outStr != "" {
|
||||
p.log(host, "output: ", outStr)
|
||||
}
|
||||
|
||||
if errStr != "" {
|
||||
p.log(host, "error: ", errStr)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
+127
-9
@@ -5,7 +5,9 @@ import (
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/appleboy/easyssh-proxy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -98,7 +100,7 @@ func TestSCPFileFromPublicKey(t *testing.T) {
|
||||
KeyPath: "tests/.ssh/id_rsa",
|
||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||
Target: []string{filepath.Join(u.HomeDir, "/test")},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
},
|
||||
}
|
||||
@@ -128,6 +130,45 @@ func TestSCPFileFromPublicKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSCPFileFromPublicKeyWithPassphrase(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/test",
|
||||
Passphrase: "1234",
|
||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||
Target: []string{filepath.Join(u.HomeDir, "/test2")},
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
},
|
||||
}
|
||||
|
||||
err = plugin.Exec()
|
||||
assert.Nil(t, err)
|
||||
|
||||
// check file exist
|
||||
if _, err := os.Stat(filepath.Join(u.HomeDir, "/test2/tests/a.txt")); os.IsNotExist(err) {
|
||||
t.Fatalf("SCP-error: %v", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(u.HomeDir, "/test2/tests/b.txt")); os.IsNotExist(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 {
|
||||
@@ -148,7 +189,7 @@ func TestSCPWildcardFileList(t *testing.T) {
|
||||
KeyPath: "tests/.ssh/id_rsa",
|
||||
Source: []string{"tests/global/*"},
|
||||
Target: []string{filepath.Join(u.HomeDir, "abc")},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
},
|
||||
}
|
||||
@@ -180,7 +221,7 @@ func TestSCPFromProxySetting(t *testing.T) {
|
||||
KeyPath: "tests/.ssh/id_rsa",
|
||||
Source: []string{"tests/global/*"},
|
||||
Target: []string{filepath.Join(u.HomeDir, "def")},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
Proxy: easyssh.DefaultConfig{
|
||||
Server: "localhost",
|
||||
@@ -225,7 +266,7 @@ func TestStripComponentsFlag(t *testing.T) {
|
||||
Source: []string{"tests/global/*"},
|
||||
StripComponents: 2,
|
||||
Target: []string{filepath.Join(u.HomeDir, "123")},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
},
|
||||
}
|
||||
@@ -264,8 +305,9 @@ func TestIgnoreList(t *testing.T) {
|
||||
Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"},
|
||||
StripComponents: 2,
|
||||
Target: []string{filepath.Join(u.HomeDir, "ignore")},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
Debug: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -342,7 +384,7 @@ func TestIncorrectPassword(t *testing.T) {
|
||||
Password: "123456",
|
||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||
Target: []string{"/home"},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
},
|
||||
}
|
||||
@@ -365,7 +407,7 @@ func TestNoPermissionCreateFolder(t *testing.T) {
|
||||
KeyPath: "tests/.ssh/id_rsa",
|
||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||
Target: []string{"/etc/test"},
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
TarExec: "tar",
|
||||
},
|
||||
}
|
||||
@@ -386,7 +428,7 @@ func TestGlobList(t *testing.T) {
|
||||
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"}
|
||||
expects = []string{"tests/a.txt", "tests/b.txt", "tests/.ssh/id_rsa", "tests/.ssh/id_rsa.pub", "tests/.ssh/test", "tests/.ssh/test.pub"}
|
||||
assert.Equal(t, expects, globList(paterns).Source)
|
||||
|
||||
paterns = []string{"tests/?.txt"}
|
||||
@@ -440,7 +482,7 @@ func TestRemoveDestFile(t *testing.T) {
|
||||
}
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
CommandTimeout: 60,
|
||||
CommandTimeout: 60 * time.Second,
|
||||
},
|
||||
DestFile: "/etc/resolv.conf",
|
||||
}
|
||||
@@ -455,3 +497,79 @@ func TestRemoveDestFile(t *testing.T) {
|
||||
err = plugin.removeDestFile(ssh)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestPlugin_buildArgs(t *testing.T) {
|
||||
type fields struct {
|
||||
Repo Repo
|
||||
Build Build
|
||||
Config Config
|
||||
DestFile string
|
||||
}
|
||||
type args struct {
|
||||
target string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "default command",
|
||||
fields: fields{
|
||||
Config: Config{
|
||||
Overwrite: false,
|
||||
TarExec: "tar",
|
||||
},
|
||||
DestFile: "foo.tar",
|
||||
},
|
||||
args: args{
|
||||
target: "foo",
|
||||
},
|
||||
want: []string{"tar", "-xf", "foo.tar", "-C", "foo"},
|
||||
},
|
||||
{
|
||||
name: "strip components",
|
||||
fields: fields{
|
||||
Config: Config{
|
||||
Overwrite: false,
|
||||
TarExec: "tar",
|
||||
StripComponents: 2,
|
||||
},
|
||||
DestFile: "foo.tar",
|
||||
},
|
||||
args: args{
|
||||
target: "foo",
|
||||
},
|
||||
want: []string{"tar", "-xf", "foo.tar", "--strip-components", "2", "-C", "foo"},
|
||||
},
|
||||
{
|
||||
name: "overwrite",
|
||||
fields: fields{
|
||||
Config: Config{
|
||||
TarExec: "tar",
|
||||
StripComponents: 2,
|
||||
Overwrite: true,
|
||||
},
|
||||
DestFile: "foo.tar",
|
||||
},
|
||||
args: args{
|
||||
target: "foo",
|
||||
},
|
||||
want: []string{"tar", "-xf", "foo.tar", "--strip-components", "2", "--overwrite", "-C", "foo"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := &Plugin{
|
||||
Repo: tt.fields.Repo,
|
||||
Build: tt.fields.Build,
|
||||
Config: tt.fields.Config,
|
||||
DestFile: tt.fields.DestFile,
|
||||
}
|
||||
if got := p.buildArgs(tt.args.target); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Plugin.buildArgs() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
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
|
||||
l4njcaMpg4tpQMHtCBOicGyV0=
|
||||
-----END OPENSSH PRIVATE KEY-----
|
||||
@@ -0,0 +1 @@
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDz6aZ1jY2onnuj2YNHJ/HhfvIu0B973v/+pFFOavnTUOhEEKEy3TASu+s9CkHrYZAtRc+QYIkNZI31mhHBhotdeP/7GoO2UirkFtrzyQKPNJxEcv0RBoG9ssN8jex0PyK6DHIYYFnIWadVBEEOh/H+rK7j7u2/big3oTzYBuFrCwmYFcz5na99MzFeAUhazF44gVBma+zO+1quGeqF51UDIg1SMGvX8I7LNEqrKEBaIUQJKFQcxlOWlRLQsjJCymrOujsXsRrXHAQWcnxDcNevv2ZMOUl0ybvv9yH0BiGbRBd1Hy8/QPILbAQaqu0oQE7fubN8Q8lqb3Jg0loID4x/5GPhSY8WAXpuLcXTOrb93SnCw1JsAgJDNqpuuRFy3BSZ7wBOr1jfeIoo7xk14OHiUjJ0uXDL9cLMkcw6ElWz81mrD2VCkXUz+qFyjJ+G7aGWRtctZoOzKln4yfNfUmwW8/8ra3QnmrMZ2xW2Ylw3ZhO+tLi7jINHYFb54bAdLVPUU1ctIuJns2qkWnjJCxxMiynIqCif20/OU1n8CTJuOWiURmRdmvKOH4PE3JxC2Qnk/3tV3Cf8hp1CH5VjBZ9AjGj5MDMHXyu34VY2WvYo5QyzfS3ySPoT8kCO0G0xpvjwCMHOK+G2RP4kqb/KKZguiKdgintBXuskTlJmD7kcMQ== deploy@easyssh
|
||||
Reference in New Issue
Block a user