chore: change command timeout flag (#138)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2019-03-11 14:36:17 +08:00 committed by GitHub
parent e79f8934dc
commit 56b67e1314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 40 deletions

View File

@ -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) ![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 ## 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. The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-ssh/releases). Support the following OS type.

14
go.mod
View File

@ -1,12 +1,10 @@
module github.com/appleboy/drone-ssh module github.com/appleboy/drone-ssh
go 1.12
require ( require (
github.com/appleboy/easyssh-proxy v0.0.0-20170516072225-33d87eae3a01 github.com/appleboy/easyssh-proxy v1.2.0
github.com/davecgh/go-spew v1.1.0 // indirect github.com/joho/godotenv v1.3.0
github.com/joho/godotenv v0.0.0-20161216230537-726cc8b906e3 github.com/stretchr/testify v1.3.0
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/urfave/cli v1.20.0
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
) )

25
go.sum
View File

@ -1,16 +1,17 @@
github.com/appleboy/easyssh-proxy v0.0.0-20170516072225-33d87eae3a01 h1:F7XJNUrMJTvV2TXiHndZWSpyLCGuc+TqQ46SYKE7I0Q= github.com/appleboy/easyssh-proxy v1.2.0 h1:KvaUGC18WkBFet+N1oofQy03jkC5HaKFn2XGxFxCTtg=
github.com/appleboy/easyssh-proxy v0.0.0-20170516072225-33d87eae3a01/go.mod h1:bQbHdUQpAmc4Nv22/0slLXWdllbncGfA9ALkPuCe704= 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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v0.0.0-20161216230537-726cc8b906e3/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= 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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
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/urfave/cli v0.0.0-20170215051705-2526b57c56f3 h1:XXFtT/u0D9gLQ7Cw/xA8KLFXegCx9Sxq1wUKosSkhYE= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v0.0.0-20170215051705-2526b57c56f3/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
golang.org/x/crypto v0.0.0-20170413182223-cbc3d0884eac h1:XuNEIEGF9/ewb6jVpjEjwb46FsNjTtgWCseDgY136n0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
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/sys v0.0.0-20190303192550-c2f5717e611c h1:AXm9RSDBofvoECjrx/I1fceu1mdoJP5zCjxjsOmyGgI= golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/sys v0.0.0-20190303192550-c2f5717e611c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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=

View File

@ -3,6 +3,7 @@ package main
import ( import (
"log" "log"
"os" "os"
"time"
"github.com/appleboy/easyssh-proxy" "github.com/appleboy/easyssh-proxy"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@ -74,11 +75,11 @@ func main() {
Usage: "connection timeout", Usage: "connection timeout",
EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT", EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT",
}, },
cli.IntFlag{ cli.DurationFlag{
Name: "command.timeout,T", Name: "command.timeout,T",
Usage: "command timeout", Usage: "command timeout",
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT", EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT",
Value: 60, Value: 60 * time.Second,
}, },
cli.StringSliceFlag{ cli.StringSliceFlag{
Name: "script,s", Name: "script,s",
@ -192,7 +193,7 @@ func run(c *cli.Context) error {
Host: c.StringSlice("host"), Host: c.StringSlice("host"),
Port: c.Int("port"), Port: c.Int("port"),
Timeout: c.Duration("timeout"), Timeout: c.Duration("timeout"),
CommandTimeout: c.Int("command.timeout"), CommandTimeout: c.Duration("command.timeout"),
Script: c.StringSlice("script"), Script: c.StringSlice("script"),
ScriptStop: c.Bool("script.stop"), ScriptStop: c.Bool("script.stop"),
Secrets: c.StringSlice("secrets"), Secrets: c.StringSlice("secrets"),

View File

@ -30,7 +30,7 @@ type (
Host []string Host []string
Port int Port int
Timeout time.Duration Timeout time.Duration
CommandTimeout int CommandTimeout time.Duration
Script []string Script []string
ScriptStop bool ScriptStop bool
Secrets []string Secrets []string

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"strings" "strings"
"testing" "testing"
"time"
"github.com/appleboy/easyssh-proxy" "github.com/appleboy/easyssh-proxy"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -59,7 +60,7 @@ func TestIncorrectPassword(t *testing.T) {
Port: 22, Port: 22,
Password: "123456", Password: "123456",
Script: []string{"whoami"}, Script: []string{"whoami"},
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
}, },
} }
@ -73,7 +74,7 @@ func TestSSHScriptFromRawKey(t *testing.T) {
Host: []string{"localhost"}, Host: []string{"localhost"},
Username: "drone-scp", Username: "drone-scp",
Port: 22, Port: 22,
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
Key: `-----BEGIN RSA PRIVATE KEY----- Key: `-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26 MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26
VbfAF0hIJji7ltvnYnqCU9oFfvEM33cTn7T96+od8ib/Vz25YU8ZbstqtIskPuwC VbfAF0hIJji7ltvnYnqCU9oFfvEM33cTn7T96+od8ib/Vz25YU8ZbstqtIskPuwC
@ -118,7 +119,7 @@ func TestSSHScriptFromKeyFile(t *testing.T) {
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"whoami", "ls -al"}, Script: []string{"whoami", "ls -al"},
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
}, },
} }
@ -134,7 +135,7 @@ func TestStreamFromSSHCommand(t *testing.T) {
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"whoami", "for i in {1..5}; do echo ${i}; sleep 1; done", "echo 'done'"}, 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, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"exit 1"}, Script: []string{"exit 1"},
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
}, },
} }
@ -167,7 +168,7 @@ func TestSSHCommandTimeOut(t *testing.T) {
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"sleep 5"}, Script: []string{"sleep 5"},
CommandTimeout: 1, CommandTimeout: 1 * time.Second,
}, },
} }
@ -183,7 +184,7 @@ func TestProxyCommand(t *testing.T) {
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"whoami"}, Script: []string{"whoami"},
CommandTimeout: 1, CommandTimeout: 1 * time.Second,
Proxy: easyssh.DefaultConfig{ Proxy: easyssh.DefaultConfig{
Server: "localhost", Server: "localhost",
User: "drone-scp", User: "drone-scp",
@ -205,7 +206,7 @@ func TestSSHCommandError(t *testing.T) {
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"mkdir a", "mkdir a"}, Script: []string{"mkdir a", "mkdir a"},
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
}, },
} }
@ -227,7 +228,7 @@ func TestSSHCommandExitCodeError(t *testing.T) {
"mkdir a", "mkdir a",
"echo 2", "echo 2",
}, },
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
}, },
} }
@ -247,7 +248,7 @@ func TestSetENV(t *testing.T) {
Envs: []string{"foo"}, Envs: []string{"foo"},
Debug: true, Debug: true,
Script: []string{"whoami; echo $FOO"}, Script: []string{"whoami; echo $FOO"},
CommandTimeout: 1, CommandTimeout: 1 * time.Second,
Proxy: easyssh.DefaultConfig{ Proxy: easyssh.DefaultConfig{
Server: "localhost", Server: "localhost",
User: "drone-scp", User: "drone-scp",
@ -274,7 +275,7 @@ func TestSetExistingENV(t *testing.T) {
Envs: []string{"foo", "bar", "baz"}, Envs: []string{"foo", "bar", "baz"},
Debug: true, 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"}, 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{ Proxy: easyssh.DefaultConfig{
Server: "localhost", Server: "localhost",
User: "drone-scp", User: "drone-scp",
@ -296,7 +297,7 @@ func TestSyncMode(t *testing.T) {
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{"whoami", "for i in {1..3}; do echo ${i}; sleep 1; done", "echo 'done'"}, Script: []string{"whoami", "for i in {1..3}; do echo ${i}; sleep 1; done", "echo 'done'"},
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
Sync: true, Sync: true,
}, },
} }
@ -371,7 +372,7 @@ func TestCommandOutput(t *testing.T) {
"whoami", "whoami",
"uname", "uname",
}, },
CommandTimeout: 60, CommandTimeout: 60 * time.Second,
Sync: true, Sync: true,
}, },
Writer: &buffer, Writer: &buffer,
@ -405,7 +406,7 @@ func TestScriptStop(t *testing.T) {
"mkdir a/b/c", "mkdir a/b/c",
"mkdir d/e/f", "mkdir d/e/f",
}, },
CommandTimeout: 10, CommandTimeout: 10 * time.Second,
ScriptStop: true, ScriptStop: true,
}, },
Writer: &buffer, Writer: &buffer,
@ -440,7 +441,7 @@ func TestNoneScriptStop(t *testing.T) {
"mkdir a/b/c", "mkdir a/b/c",
"mkdir d/e/f", "mkdir d/e/f",
}, },
CommandTimeout: 10, CommandTimeout: 10 * time.Second,
}, },
Writer: &buffer, Writer: &buffer,
} }
@ -508,7 +509,7 @@ func TestEnvOutput(t *testing.T) {
`echo "[${ENV_6}]"`, `echo "[${ENV_6}]"`,
`echo "[${ENV_7}]"`, `echo "[${ENV_7}]"`,
}, },
CommandTimeout: 10, CommandTimeout: 10 * time.Second,
Proxy: easyssh.DefaultConfig{ Proxy: easyssh.DefaultConfig{
Server: "localhost", Server: "localhost",
User: "drone-scp", User: "drone-scp",