Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buildah: add heredoc support for RUN, COPY and ADD
Following PR is a attempt to add `Heredoc` support to buildah. Once this PR is merged buildah is supposed to honor heredoc syntax while processing containerfiles Expected syntax to work ```Dockerfile FROM docker.io/library/python:latest RUN <<EOF echo "Hello" >> /hello echo "World!" >> /hello EOF RUN python3 <<EOF with open("/hello", "w") as f: print("Hello", file=f) print("Something", file=f) EOF RUN ls -a RUN cat hello ``` Signed-off-by: Aditya R <arajan@redhat.com>
- Loading branch information
Showing
9 changed files
with
288 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
FROM docker.io/library/python:latest | ||
|
||
RUN <<EOF | ||
echo "print first line from heredoc" | ||
echo "print second line from heredoc" | ||
EOF | ||
|
||
RUN <<EOF | ||
echo "Heredoc writing first file" >> /file1 | ||
echo "some text of first file" >> /file1 | ||
EOF | ||
|
||
RUN cat file1 | ||
|
||
RUN python3 <<EOF | ||
with open("/file2", "w") as f: | ||
print("file2 from python", file=f) | ||
EOF | ||
|
||
RUN cat file2 | ||
|
||
ADD <<EOF /index.html | ||
(your index page goes here) | ||
EOF | ||
|
||
RUN cat index.html | ||
|
||
COPY <<robots.txt <<humans.txt /test/ | ||
(robots content) | ||
robots.txt | ||
(humans content) | ||
humans.txt | ||
|
||
RUN cat /proc/self/fd/5 /proc/self/fd/6 5<<FILE1 6<<FILE2 > test6.txt | ||
this is the output of test6 part1 | ||
FILE1 | ||
this is the output of test6 part2 | ||
FILE2 | ||
|
||
RUN 5<<file cat /proc/self/fd/5 /proc/self/fd/6 6<<FILE | cat /dev/stdin /proc/self/fd/6 6<<File > test7.txt | ||
this is the output of test7 part1 | ||
file | ||
this is the output of test7 part2 | ||
FILE | ||
this is the output of test7 part3 | ||
File | ||
|
||
RUN <<FILE1 cat > test8.1 && <<FILE2 cat > test8.2 | ||
this is the output of test8 part1 | ||
FILE1 | ||
this is the output of test8 part2 | ||
FILE2 | ||
|
||
RUN cat /test/robots.txt | ||
RUN cat /test/humans.txt | ||
RUN cat test6.txt | ||
RUN cat test7.txt | ||
RUN cat test8.1 | ||
RUN cat test8.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM busybox | ||
RUN <<EOF | ||
#!/bin/sh | ||
echo " | ||
this is the output of test9" > test9.txt | ||
EOF | ||
|
||
RUN <<-EOF | ||
#!/bin/sh | ||
echo " | ||
this is the output of test10" > test10.txt | ||
EOF | ||
|
||
RUN cat test9.txt | ||
RUN cat test10.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM alpine | ||
|
||
RUN <<EOF | ||
#!/bin/sh | ||
echo " | ||
this is the output of test" > test.txt | ||
# Mount of this file must exists till this run step | ||
# so this `ls` command should not fail | ||
ls -a /dev/pipes/ | ||
EOF | ||
|
||
RUN cat test.txt | ||
|
||
# This ls command must fail, since mount is removed in this step | ||
RUN ls -a /dev/pipes | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/conformance/testdata/heredoc/Dockerfile.heredoc_copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# syntax=docker/dockerfile:1.3-labs | ||
FROM busybox as one | ||
RUN echo helloworld > image_file | ||
FROM busybox | ||
RUN echo hello | ||
# copy two heredoc and one from context | ||
COPY <<robots.txt <<humans.txt file /test/ | ||
(robots content) | ||
Long file with random text | ||
Random line | ||
HelloWorld | ||
robots.txt | ||
(humans content) | ||
humans.txt | ||
# copy two heredoc and one from another stage | ||
COPY --from=one image_file <<robots.txt <<humans.txt /test2/ | ||
(robots content) | ||
Long file with random text | ||
Random line | ||
HelloWorld | ||
robots.txt | ||
(humans content) | ||
humans.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
somefile |