From 882705063ed6a497d8eb482dac68e1c0cd76f907 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 6 Apr 2022 10:58:45 +0200 Subject: [PATCH] buildah build should accept at most one arg Right now buildah just ignores it when you set more than one argument for build. Only the first argument is used as context dir. This looks wrong to me and can lead to users errors. Fixes test failure in https://github.com/containers/podman/pull/13687 Signed-off-by: Paul Holzinger --- cmd/buildah/build.go | 8 ++------ tests/bud.bats | 21 ++++++--------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/cmd/buildah/build.go b/cmd/buildah/build.go index 4501b6d92d6..17324f31b27 100644 --- a/cmd/buildah/build.go +++ b/cmd/buildah/build.go @@ -43,7 +43,7 @@ func init() { namespaceResults := buildahcli.NameSpaceResults{} buildCommand := &cobra.Command{ - Use: "build", + Use: "build [CONTEXT]", Aliases: []string{"build-using-dockerfile", "bud"}, Short: "Build an image using instructions in a Containerfile", Long: buildDescription, @@ -57,6 +57,7 @@ func init() { } return buildCmd(cmd, args, br) }, + Args: cobra.MaximumNArgs(1), Example: `buildah build buildah bud -f Containerfile.simple . buildah bud --volume /home/test:/myvol:ro,Z -t imageName . @@ -199,11 +200,6 @@ func buildCmd(c *cobra.Command, inputArgs []string, iopts buildOptions) error { contextDir = absDir } } - cliArgs = Tail(cliArgs) - - if err := buildahcli.VerifyFlagsArgsOrder(cliArgs); err != nil { - return err - } if len(containerfiles) == 0 { // Try to find the Containerfile/Dockerfile within the contextDir diff --git a/tests/bud.bats b/tests/bud.bats index f0e92786007..86434d16dee 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -171,20 +171,6 @@ _EOF expect_output --substring $targetarch } -@test "bud-flags-order-verification" { - run_buildah 125 build /tmp/tmpdockerfile/ -t blabla - check_options_flag_err "-t" - - run_buildah 125 build /tmp/tmpdockerfile/ -q -t blabla - check_options_flag_err "-q" - - run_buildah 125 build /tmp/tmpdockerfile/ --force-rm - check_options_flag_err "--force-rm" - - run_buildah 125 build /tmp/tmpdockerfile/ --userns=cnt1 - check_options_flag_err "--userns=cnt1" -} - @test "bud with --layers and --no-cache flags" { cp -a ${TESTSDIR}/bud/use-layers ${TESTDIR}/use-layers @@ -3170,10 +3156,15 @@ from alpine run echo hello _EOF - run_buildah 1 build --signature-policy ${TESTSDIR}/policy.json --runtime-flag invalidflag -t build_test $mytmpdir . + run_buildah 1 build --signature-policy ${TESTSDIR}/policy.json --runtime-flag invalidflag -t build_test $mytmpdir assert "$output" =~ ".*invalidflag" "failed when passing undefined flags to the runtime" } +@test "bud - accept at most one arg" { + run_buildah 125 build --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/dns extraarg + assert "accepts at most 1 arg(s), received 2" "error while parsing arguments" +} + @test "bud with --add-host" { skip_if_no_runtime