Skip to content

Commit

Permalink
Merge pull request #2708 from rhatdan/stdin
Browse files Browse the repository at this point in the history
Buildah bud should not use stdin by default
  • Loading branch information
openshift-merge-robot authored Oct 21, 2020
2 parents 467acc3 + fb60bc4 commit d33bb41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 1 addition & 10 deletions cmd/buildah/bud.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
return errors.Wrapf(err, "error evaluating symlinks in build context path")
}

var stdin, stdout, stderr, reporter *os.File
stdin = os.Stdin
var stdout, stderr, reporter *os.File
stdout = os.Stdout
stderr = os.Stderr
reporter = os.Stderr
Expand Down Expand Up @@ -302,13 +301,6 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
return errors.Wrapf(err, "unable to obtain decrypt config")
}

if iopts.Jobs > 1 {
stdin, err = os.OpenFile("/dev/null", os.O_RDONLY|os.O_CREATE, 0000)
if err != nil {
return err
}
}

options := imagebuildah.BuildOptions{
AddCapabilities: iopts.CapAdd,
AdditionalTags: tags,
Expand All @@ -329,7 +321,6 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
ForceRmIntermediateCtrs: iopts.ForceRm,
IDMappingOptions: idmappingOptions,
IIDFile: iopts.Iidfile,
In: stdin,
Isolation: isolation,
Labels: iopts.Label,
Layers: layers,
Expand Down
22 changes: 22 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2273,3 +2273,25 @@ EOM
expect_output --substring "CapBnd: 00000000a80425fb"
expect_output --substring "CapEff: 0000000000000000"
}

@test "bud does not gobble stdin" {
_prefetch alpine

ctxdir=${TESTDIR}/bud
mkdir -p $ctxdir
cat >$ctxdir/Dockerfile <<EOF
FROM alpine
RUN true
EOF

random_msg=$(head -10 /dev/urandom | tr -dc a-zA-Z0-9 | head -c12)

# Prior to #2708, buildah bud would gobble up its stdin even if it
# didn't actually use it. This prevented the use of 'cmdlist | bash';
# if 'buildah bud' was in cmdlist, everything past it would be lost.
#
# This is ugly but effective: it checks that buildah passes stdin untouched.
passthru=$(echo "$random_msg" | (run_buildah bud --quiet --signature-policy ${TESTSDIR}/policy.json -t stdin-test ${ctxdir} >/dev/null; cat))

expect_output --from="$passthru" "$random_msg" "stdin was passed through"
}

0 comments on commit d33bb41

Please sign in to comment.