Skip to content

Commit e2f51ee

Browse files
Merge pull request #10651 from rhatdan/build
Add support for podman remote build -f - .
2 parents e3dd12a + 3a65ba2 commit e2f51ee

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pkg/bindings/images/build.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,22 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
299299
tarContent := []string{options.ContextDirectory}
300300
newContainerFiles := []string{}
301301
for _, c := range containerFiles {
302+
if c == "/dev/stdin" {
303+
content, err := ioutil.ReadAll(os.Stdin)
304+
if err != nil {
305+
return nil, err
306+
}
307+
tmpFile, err := ioutil.TempFile("", "build")
308+
if err != nil {
309+
return nil, err
310+
}
311+
defer os.Remove(tmpFile.Name()) // clean up
312+
defer tmpFile.Close()
313+
if _, err := tmpFile.Write(content); err != nil {
314+
return nil, err
315+
}
316+
c = tmpFile.Name()
317+
}
302318
containerfile, err := filepath.Abs(c)
303319
if err != nil {
304320
logrus.Errorf("cannot find absolute path of %v: %v", c, err)

test/system/070-build.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ EOF
2929
run_podman rmi -f build_test
3030
}
3131

32+
@test "podman build test -f -" {
33+
rand_filename=$(random_string 20)
34+
rand_content=$(random_string 50)
35+
36+
tmpdir=$PODMAN_TMPDIR/build-test
37+
mkdir -p $tmpdir
38+
containerfile=$PODMAN_TMPDIR/Containerfile
39+
cat >$containerfile <<EOF
40+
FROM $IMAGE
41+
RUN apk add nginx
42+
RUN echo $rand_content > /$rand_filename
43+
EOF
44+
45+
# The 'apk' command can take a long time to fetch files; bump timeout
46+
PODMAN_TIMEOUT=240 run_podman build -t build_test -f - --format=docker $tmpdir < $containerfile
47+
is "$output" ".*STEP 4: COMMIT" "COMMIT seen in log"
48+
49+
run_podman run --rm build_test cat /$rand_filename
50+
is "$output" "$rand_content" "reading generated file in image"
51+
52+
run_podman rmi -f build_test
53+
}
54+
3255
@test "podman build - global runtime flags test" {
3356
skip_if_remote "--runtime-flag flag not supported for remote"
3457

0 commit comments

Comments
 (0)