github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/build/testdata/Dockerfile.TestBuildPreserveOwnership (about) 1 # Set up files and directories with known ownership 2 FROM busybox AS source 3 RUN touch /file && chown 100:200 /file \ 4 && mkdir -p /dir/subdir \ 5 && touch /dir/subdir/nestedfile \ 6 && chown 100:200 /dir \ 7 && chown 101:201 /dir/subdir \ 8 && chown 102:202 /dir/subdir/nestedfile 9 10 FROM busybox AS test_base 11 RUN mkdir -p /existingdir/existingsubdir \ 12 && touch /existingdir/existingfile \ 13 && chown 500:600 /existingdir \ 14 && chown 501:601 /existingdir/existingsubdir \ 15 && chown 501:601 /existingdir/existingfile 16 17 18 # Copy files from the source stage 19 FROM test_base AS copy_from 20 COPY --from=source /file . 21 # Copy to a non-existing target directory creates the target directory (as root), then copies the _contents_ of the source directory into it 22 COPY --from=source /dir /dir 23 # Copying to an existing target directory will copy the _contents_ of the source directory into it 24 COPY --from=source /dir/. /existingdir 25 26 RUN e="100:200"; p="/file" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 27 && e="0:0"; p="/dir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 28 && e="101:201"; p="/dir/subdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 29 && e="102:202"; p="/dir/subdir/nestedfile" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 30 # Existing files and directories ownership should not be modified 31 && e="500:600"; p="/existingdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 32 && e="501:601"; p="/existingdir/existingsubdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 33 && e="501:601"; p="/existingdir/existingfile" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 34 # But new files and directories should maintain their ownership 35 && e="101:201"; p="/existingdir/subdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 36 && e="102:202"; p="/existingdir/subdir/nestedfile"; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi 37 38 39 # Copy files from the source stage and chown them. 40 FROM test_base AS copy_from_chowned 41 COPY --from=source --chown=300:400 /file . 42 # Copy to a non-existing target directory creates the target directory (as root), then copies the _contents_ of the source directory into it 43 COPY --from=source --chown=300:400 /dir /dir 44 # Copying to an existing target directory copies the _contents_ of the source directory into it 45 COPY --from=source --chown=300:400 /dir/. /existingdir 46 47 RUN e="300:400"; p="/file" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 48 && e="300:400"; p="/dir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 49 && e="300:400"; p="/dir/subdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 50 && e="300:400"; p="/dir/subdir/nestedfile" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 51 # Existing files and directories ownership should not be modified 52 && e="500:600"; p="/existingdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 53 && e="501:601"; p="/existingdir/existingsubdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 54 && e="501:601"; p="/existingdir/existingfile" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 55 # But new files and directories should be chowned 56 && e="300:400"; p="/existingdir/subdir" ; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi \ 57 && e="300:400"; p="/existingdir/subdir/nestedfile"; a=`stat -c "%u:%g" "$p"`; if [ "$a" != "$e" ]; then echo "incorrect ownership on $p. expected $e, got $a"; exit 1; fi