diff --git a/README.md b/README.md index 5e60b8c..ee11d57 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,28 @@ information and a listing of the available options please take a look at [the do ![demo](./images/demo2017.05.10.gif) +## 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 + script: + - echo "Hello World" +``` + ## Build or Download a binary The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-ssh/releases). Support the following OS type. diff --git a/go.mod b/go.mod index dca2964..cac401d 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,10 @@ module github.com/appleboy/drone-ssh +go 1.12 + require ( - github.com/appleboy/easyssh-proxy v0.0.0-20170516072225-33d87eae3a01 - github.com/davecgh/go-spew v1.1.0 // indirect - github.com/joho/godotenv v0.0.0-20161216230537-726cc8b906e3 - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1 - github.com/urfave/cli v0.0.0-20170215051705-2526b57c56f3 - golang.org/x/crypto v0.0.0-20170413182223-cbc3d0884eac // indirect - golang.org/x/sys v0.0.0-20190303192550-c2f5717e611c // indirect + github.com/appleboy/easyssh-proxy v1.2.0 + github.com/joho/godotenv v1.3.0 + github.com/stretchr/testify v1.3.0 + github.com/urfave/cli v1.20.0 ) diff --git a/go.sum b/go.sum index f83fbba..2c1a183 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,17 @@ -github.com/appleboy/easyssh-proxy v0.0.0-20170516072225-33d87eae3a01 h1:F7XJNUrMJTvV2TXiHndZWSpyLCGuc+TqQ46SYKE7I0Q= -github.com/appleboy/easyssh-proxy v0.0.0-20170516072225-33d87eae3a01/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/joho/godotenv v0.0.0-20161216230537-726cc8b906e3 h1:zShOjUfrFegEHgln4TPkWk3KkN9sug3Es3Ml6YpgFJI= -github.com/joho/godotenv v0.0.0-20161216230537-726cc8b906e3/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +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/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/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/urfave/cli v0.0.0-20170215051705-2526b57c56f3 h1:XXFtT/u0D9gLQ7Cw/xA8KLFXegCx9Sxq1wUKosSkhYE= -github.com/urfave/cli v0.0.0-20170215051705-2526b57c56f3/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/sys v0.0.0-20190303192550-c2f5717e611c h1:AXm9RSDBofvoECjrx/I1fceu1mdoJP5zCjxjsOmyGgI= -golang.org/x/sys v0.0.0-20190303192550-c2f5717e611c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +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 h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/main.go b/main.go index 026b92c..452d999 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "log" "os" + "time" "github.com/appleboy/easyssh-proxy" "github.com/joho/godotenv" @@ -74,11 +75,11 @@ func main() { Usage: "connection timeout", EnvVar: "PLUGIN_TIMEOUT,SSH_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.StringSliceFlag{ Name: "script,s", @@ -192,7 +193,7 @@ func run(c *cli.Context) error { Host: c.StringSlice("host"), Port: c.Int("port"), Timeout: c.Duration("timeout"), - CommandTimeout: c.Int("command.timeout"), + CommandTimeout: c.Duration("command.timeout"), Script: c.StringSlice("script"), ScriptStop: c.Bool("script.stop"), Secrets: c.StringSlice("secrets"), diff --git a/plugin.go b/plugin.go index 1e29264..9c921a9 100644 --- a/plugin.go +++ b/plugin.go @@ -30,7 +30,7 @@ type ( Host []string Port int Timeout time.Duration - CommandTimeout int + CommandTimeout time.Duration Script []string ScriptStop bool Secrets []string diff --git a/plugin_test.go b/plugin_test.go index b9cb43f..faf6e7e 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -5,6 +5,7 @@ import ( "os" "strings" "testing" + "time" "github.com/appleboy/easyssh-proxy" "github.com/stretchr/testify/assert" @@ -59,7 +60,7 @@ func TestIncorrectPassword(t *testing.T) { Port: 22, Password: "123456", Script: []string{"whoami"}, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, }, } @@ -73,7 +74,7 @@ func TestSSHScriptFromRawKey(t *testing.T) { Host: []string{"localhost"}, Username: "drone-scp", Port: 22, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, Key: `-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26 VbfAF0hIJji7ltvnYnqCU9oFfvEM33cTn7T96+od8ib/Vz25YU8ZbstqtIskPuwC @@ -118,7 +119,7 @@ func TestSSHScriptFromKeyFile(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"whoami", "ls -al"}, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, }, } @@ -134,7 +135,7 @@ func TestStreamFromSSHCommand(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"whoami", "for i in {1..5}; do echo ${i}; sleep 1; done", "echo 'done'"}, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, }, } @@ -150,7 +151,7 @@ func TestSSHScriptWithError(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"exit 1"}, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, }, } @@ -167,7 +168,7 @@ func TestSSHCommandTimeOut(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"sleep 5"}, - CommandTimeout: 1, + CommandTimeout: 1 * time.Second, }, } @@ -183,7 +184,7 @@ func TestProxyCommand(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"whoami"}, - CommandTimeout: 1, + CommandTimeout: 1 * time.Second, Proxy: easyssh.DefaultConfig{ Server: "localhost", User: "drone-scp", @@ -205,7 +206,7 @@ func TestSSHCommandError(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"mkdir a", "mkdir a"}, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, }, } @@ -227,7 +228,7 @@ func TestSSHCommandExitCodeError(t *testing.T) { "mkdir a", "echo 2", }, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, }, } @@ -247,7 +248,7 @@ func TestSetENV(t *testing.T) { Envs: []string{"foo"}, Debug: true, Script: []string{"whoami; echo $FOO"}, - CommandTimeout: 1, + CommandTimeout: 1 * time.Second, Proxy: easyssh.DefaultConfig{ Server: "localhost", User: "drone-scp", @@ -274,7 +275,7 @@ func TestSetExistingENV(t *testing.T) { Envs: []string{"foo", "bar", "baz"}, Debug: true, Script: []string{"export FOO", "export BAR", "export BAZ", "env | grep -q '^FOO=Value for foo$'", "env | grep -q '^BAR=$'", "if env | grep -q BAZ; then false; else true; fi"}, - CommandTimeout: 1, + CommandTimeout: 1 * time.Second, Proxy: easyssh.DefaultConfig{ Server: "localhost", User: "drone-scp", @@ -296,7 +297,7 @@ func TestSyncMode(t *testing.T) { Port: 22, KeyPath: "./tests/.ssh/id_rsa", Script: []string{"whoami", "for i in {1..3}; do echo ${i}; sleep 1; done", "echo 'done'"}, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, Sync: true, }, } @@ -371,7 +372,7 @@ func TestCommandOutput(t *testing.T) { "whoami", "uname", }, - CommandTimeout: 60, + CommandTimeout: 60 * time.Second, Sync: true, }, Writer: &buffer, @@ -405,7 +406,7 @@ func TestScriptStop(t *testing.T) { "mkdir a/b/c", "mkdir d/e/f", }, - CommandTimeout: 10, + CommandTimeout: 10 * time.Second, ScriptStop: true, }, Writer: &buffer, @@ -440,7 +441,7 @@ func TestNoneScriptStop(t *testing.T) { "mkdir a/b/c", "mkdir d/e/f", }, - CommandTimeout: 10, + CommandTimeout: 10 * time.Second, }, Writer: &buffer, } @@ -508,7 +509,7 @@ func TestEnvOutput(t *testing.T) { `echo "[${ENV_6}]"`, `echo "[${ENV_7}]"`, }, - CommandTimeout: 10, + CommandTimeout: 10 * time.Second, Proxy: easyssh.DefaultConfig{ Server: "localhost", User: "drone-scp",