[FIX] fix docker run parser bug

This commit is contained in:
goodrain 2018-02-26 14:03:44 +08:00
parent 866b7b301f
commit dfd4593317
2 changed files with 10 additions and 12 deletions

View File

@ -19,6 +19,7 @@
package parser
import (
"fmt"
"strconv"
"strings"
@ -73,15 +74,19 @@ func (d *DockerRunOrImageParse) Parse() ParseErrorList {
//docker run
if strings.HasPrefix(d.source, "docker") {
d.dockerun(strings.Split(d.source, " "))
if d.image.String() == "" || d.image.String() == ":" {
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("镜像名称识别失败"), "请确认DockerRun命令是否合法"))
return d.errors
}
if _, err := reference.ParseAnyReference(d.image.String()); err != nil {
d.errappend(Errorf(FatalError, "Error parsing reference: %q is not a valid repository/tag", d.image))
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("镜像名称(%s)不合法", d.image.String()), "请确认输入镜像名是否正确"))
return d.errors
}
} else {
//else image
_, err := reference.ParseAnyReference(d.source)
if err != nil {
d.errappend(Errorf(FatalError, "Error parsing reference: %q is not a valid repository/tag", d.source))
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("镜像名称(%s)不合法", d.image.String()), "请确认输入镜像名是否正确"))
return d.errors
}
d.image = parseImageName(d.source)
@ -156,8 +161,10 @@ func (d *DockerRunOrImageParse) dockerun(source []string) {
case "memory", "m":
d.memory = readmemory(s)
}
name = ""
}
} else {
fmt.Printf("Name %s S : %s \n", name, s)
switch name {
case "e", "env":
info := strings.Split(s, "=")

View File

@ -27,16 +27,7 @@ import (
"github.com/docker/engine-api/client"
)
var dockerrun = `
docker run --name my-custom-nginx-container \
-d -it \
-v=/host/path/nginx.conf:/etc/nginx/nginx.conf:ro \
-e=xxx=xxx \
--public 90:90 \
-m 10g \
mysql
`
var dockerrun = `docker run -d -p 8080:8080 -e PWD=1qa2ws --name=tomcat_demo tomcat`
func TestParse(t *testing.T) {
dockerclient, err := client.NewEnvClient()