Add support for no-arg commands in Dockerfile
We're hoping to add some new commands that don't have any args so this PR will enable that by removing all of the hard-coded checks that require commands to have at least one arg. It also adds some checks to each command so we're consistent in the error message we get. Added a test for this too. We actually had this check in at least 3 different places (twice in the parser and once in most cmds), this removes 2 of them (the parser ones). Had to remove/modify some testcases because its now legal to have certain commands w/o args - e.g. RUN. This was actually inconsistent because we used to allow "RUN []" but not "RUN" even though they would generate (almost) the same net result. Now we're consistent. Signed-off-by: Doug Davis <dug@us.ibm.com> Upstream-commit: e4f02abb51534e560311b0afcfb7b586d9587e67 Component: engine
This commit is contained in:
@ -49,14 +49,14 @@ func TestBuildEmptyWhitespace(t *testing.T) {
|
||||
name,
|
||||
`
|
||||
FROM busybox
|
||||
RUN
|
||||
COPY
|
||||
quux \
|
||||
bar
|
||||
`,
|
||||
true)
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("no error when dealing with a RUN statement with no content on the same line")
|
||||
t.Fatal("no error when dealing with a COPY statement with no content on the same line")
|
||||
}
|
||||
|
||||
logDone("build - statements with whitespace and no content should generate a parse error")
|
||||
@ -4822,3 +4822,51 @@ func TestBuildVolumeFileExistsinContainer(t *testing.T) {
|
||||
|
||||
logDone("build - errors when volume is specified where a file exists")
|
||||
}
|
||||
|
||||
func TestBuildMissingArgs(t *testing.T) {
|
||||
// test to make sure these cmds w/o any args will generate an error
|
||||
// Notice some commands are missing because its ok for them to
|
||||
// not have any args - like: CMD, RUN, ENTRYPOINT
|
||||
cmds := []string{
|
||||
"ADD",
|
||||
"COPY",
|
||||
"ENV",
|
||||
"EXPOSE",
|
||||
"FROM",
|
||||
"MAINTAINER",
|
||||
"ONBUILD",
|
||||
"USER",
|
||||
"VOLUME",
|
||||
"WORKDIR",
|
||||
}
|
||||
|
||||
defer deleteAllContainers()
|
||||
|
||||
for _, cmd := range cmds {
|
||||
var dockerfile string
|
||||
|
||||
if cmd == "FROM" {
|
||||
dockerfile = cmd
|
||||
} else {
|
||||
// Add FROM to make sure we don't complain about it missing
|
||||
dockerfile = "FROM busybox\n" + cmd
|
||||
}
|
||||
|
||||
ctx, err := fakeContext(dockerfile, map[string]string{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ctx.Close()
|
||||
var out string
|
||||
if out, err = buildImageFromContext("args", ctx, true); err == nil {
|
||||
t.Fatalf("%s was supposed to fail:%s", cmd, out)
|
||||
}
|
||||
if !strings.Contains(err.Error(), cmd+" requires") {
|
||||
t.Fatalf("%s returned the wrong type of error:%s", cmd, err)
|
||||
}
|
||||
|
||||
ctx.Close()
|
||||
}
|
||||
|
||||
logDone("build - verify missing args")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user