Compare commits

..

11 Commits

Author SHA1 Message Date
Bo-Yi Wu 66579b6dae chore: add proxy variable 2019-05-11 19:51:39 +08:00
Bo-Yi Wu 06609f35cf add key variable
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-05-11 16:50:50 +08:00
Bo-Yi Wu c9771cce78 chore: add variable 2019-05-11 16:49:20 +08:00
Bo-Yi Wu 6088f7da5a chore: update build tag 2019-05-11 16:34:36 +08:00
Bo-Yi Wu 6de8f74170 docs: add ignore list example. 2019-05-11 14:34:40 +08:00
Bo-Yi Wu bb63d55f89 Update README.md 2019-05-09 14:08:52 +08:00
Bo-Yi Wu da44b071c4 chore: switch finished to struct{} for zero allocate (#96) 2019-03-30 07:26:53 +08:00
Bo-Yi Wu a7eddc4b11 docs: fix setting
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-11 17:22:33 +08:00
Bo-Yi Wu 813faf56be chore: remove build number 2019-03-10 23:43:06 +08:00
Bo-Yi Wu 4117d2ca30 fix: trigger build fail if error (#94)
fix #93
2019-03-10 23:41:21 +08:00
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
9 changed files with 111 additions and 64 deletions
+45
View File
@@ -146,6 +146,48 @@ pipeline:
- release/*.tar.gz
```
Example configuration using command timeout:
```diff
pipeline:
scp:
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
pipeline:
scp:
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/*
```
# Parameter Reference
host
@@ -175,6 +217,9 @@ rm
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
+23 -8
View File
@@ -31,6 +31,29 @@ Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://doc
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
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
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-scp/releases). Support the following OS type.
@@ -66,14 +89,6 @@ 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..
```
## Usage
There are three ways to send notification.
+2 -4
View File
@@ -4,13 +4,11 @@ go 1.12
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/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
golang.org/x/crypto v0.0.0-20170413182223-cbc3d0884eac // indirect
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10 // indirect
)
+4 -13
View File
@@ -1,11 +1,11 @@
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/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.4.1 h1:YJhD/SoQqn7ev9zwhIm7lHTAqsOAF2AN4xlAVZzNZnU=
github.com/fatih/color v1.4.1/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
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=
@@ -15,21 +15,12 @@ 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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
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=
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=
+21 -26
View File
@@ -3,6 +3,7 @@ package main
import (
"log"
"os"
"time"
"github.com/appleboy/easyssh-proxy"
"github.com/joho/godotenv"
@@ -12,16 +13,15 @@ import (
// 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.Copyright = "Copyright (c) 2019 Bo-Yi Wu"
app.Version = Version
app.Authors = []cli.Author{
{
Name: "Bo-Yi Wu",
@@ -34,39 +34,39 @@ func main() {
cli.StringSliceFlag{
Name: "host, H",
Usage: "Server host",
EnvVar: "PLUGIN_HOST,SCP_HOST,SSH_HOST",
EnvVar: "PLUGIN_HOST,SCP_HOST,SSH_HOST,HOST",
},
cli.StringFlag{
Name: "port, P",
Value: "22",
Usage: "Server port, default to 22",
EnvVar: "PLUGIN_PORT,SCP_PORT,SSH_PORT",
EnvVar: "PLUGIN_PORT,SCP_PORT,SSH_PORT,PORT",
},
cli.StringFlag{
Name: "username, u",
Usage: "Server username",
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SCP_USERNAME,SSH_USERNAME",
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SCP_USERNAME,SSH_USERNAME,USERNAME",
},
cli.StringFlag{
Name: "password, p",
Usage: "Password for password-based authentication",
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD,SSH_PASSWORD",
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD,SSH_PASSWORD,PASSWORD",
},
cli.DurationFlag{
Name: "timeout",
Usage: "connection timeout",
EnvVar: "PLUGIN_TIMEOUT,SCP_TIMEOUT",
},
cli.IntFlag{
cli.DurationFlag{
Name: "command.timeout,T",
Usage: "command timeout",
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT",
Value: 60,
Value: 60 * time.Second,
},
cli.StringFlag{
Name: "key, k",
Usage: "ssh private key",
EnvVar: "PLUGIN_KEY,SCP_KEY,SSH_KEY",
EnvVar: "PLUGIN_KEY,SCP_KEY,SSH_KEY,KEY",
},
cli.StringFlag{
Name: "key-path, i",
@@ -76,17 +76,17 @@ func main() {
cli.StringSliceFlag{
Name: "target, t",
Usage: "Target path on the server",
EnvVar: "PLUGIN_TARGET,SCP_TARGET",
EnvVar: "PLUGIN_TARGET,SCP_TARGET,TARGET",
},
cli.StringSliceFlag{
Name: "source, s",
Usage: "scp file list",
EnvVar: "PLUGIN_SOURCE,SCP_SOURCE",
EnvVar: "PLUGIN_SOURCE,SCP_SOURCE,SOURCE",
},
cli.BoolFlag{
Name: "rm, r",
Usage: "remove target folder before upload data",
EnvVar: "PLUGIN_RM,SCP_RM",
EnvVar: "PLUGIN_RM,SCP_RM,RM",
},
cli.StringFlag{
Name: "repo.owner",
@@ -148,7 +148,7 @@ func main() {
cli.StringFlag{
Name: "proxy.ssh-key",
Usage: "private ssh key of proxy",
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY",
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY,PROXY_KEY",
},
cli.StringFlag{
Name: "proxy.key-path",
@@ -158,23 +158,23 @@ func main() {
cli.StringFlag{
Name: "proxy.username",
Usage: "connect as user of proxy",
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME",
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME,PROXY_USERNAME",
Value: "root",
},
cli.StringFlag{
Name: "proxy.password",
Usage: "user password of proxy",
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD",
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD,PROXY_PASSWORD",
},
cli.StringFlag{
Name: "proxy.host",
Usage: "connect to host of proxy",
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST",
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST,PROXY_HOST",
},
cli.StringFlag{
Name: "proxy.port",
Usage: "connect to port of proxy",
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT",
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT,PROXY_PORT",
Value: "22",
},
cli.DurationFlag{
@@ -232,14 +232,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)
}
}
@@ -269,7 +264,7 @@ func run(c *cli.Context) error {
Username: c.String("username"),
Password: c.String("password"),
Timeout: c.Duration("timeout"),
CommandTimeout: c.Int("command.timeout"),
CommandTimeout: c.Duration("command.timeout"),
Key: c.String("key"),
KeyPath: c.String("key-path"),
Target: c.StringSlice("target"),
+1 -1
View File
@@ -1,4 +1,4 @@
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
// +build !windows
package main
+3 -1
View File
@@ -1,6 +1,8 @@
package main
import "testing"
import (
"testing"
)
func TestGetRealPath(t *testing.T) {
type args struct {
+3 -3
View File
@@ -51,7 +51,7 @@ type (
Key string
KeyPath string
Timeout time.Duration
CommandTimeout int
CommandTimeout time.Duration
Target []string
Source []string
Remove bool
@@ -237,8 +237,8 @@ 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.
+9 -8
View File
@@ -6,6 +6,7 @@ import (
"os/user"
"path/filepath"
"testing"
"time"
"github.com/appleboy/easyssh-proxy"
"github.com/stretchr/testify/assert"
@@ -98,7 +99,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",
},
}
@@ -148,7 +149,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 +181,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 +226,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,7 +265,7 @@ 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",
},
}
@@ -342,7 +343,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 +366,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",
},
}
@@ -440,7 +441,7 @@ func TestRemoveDestFile(t *testing.T) {
}
plugin := Plugin{
Config: Config{
CommandTimeout: 60,
CommandTimeout: 60 * time.Second,
},
DestFile: "/etc/resolv.conf",
}