Browse code

Optimize slow bottleneck test of DockerSuite.TestBuildDockerignoringWildDirs.

This PR fix the DockerSuite.TestBuildDockerignoringWildDirs test
in #19425.
Instead of having multiple RUN instructions in Dockerfile for every
single directory tested, this PR tries to collapse multiple RUN
instructions into one RUN instruction in Dockerfile.
When a docker image is built, each RUN instruction in Dockerfile
will generate one layer in history. It takes considerable amount of
time to build many layers if there are many RUN instructions within
the Dockerfile. Collapsing into one RUN instruction not only speeds
up the execution significantly, it also conforms to the general
guideline of the Dockerfile reference.
Since the test (DockerSuite.TestBuildDockerignoringWildDirs) is
really about testing the docker build with ignoring wild
directories, the purpose of the test is not altered with this PR
fix.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2016/03/04 08:16:10
Showing 1 changed files
... ...
@@ -3694,30 +3694,25 @@ func (s *DockerSuite) TestBuildDockerignoringWildDirs(c *check.C) {
3694 3694
         FROM busybox
3695 3695
 		COPY . /
3696 3696
 		#RUN sh -c "[[ -e /.dockerignore ]]"
3697
-		RUN sh -c "[[ -e /Dockerfile ]]"
3698
-
3699
-		RUN sh -c "[[ ! -e /file0 ]]"
3700
-		RUN sh -c "[[ ! -e /dir1/file0 ]]"
3701
-		RUN sh -c "[[ ! -e /dir2/file0 ]]"
3702
-
3703
-		RUN sh -c "[[ ! -e /file1 ]]"
3704
-		RUN sh -c "[[ ! -e /dir1/file1 ]]"
3705
-		RUN sh -c "[[ ! -e /dir1/dir2/file1 ]]"
3706
-
3707
-		RUN sh -c "[[ ! -e /dir1/file2 ]]"
3708
-		RUN sh -c "[[   -e /dir1/dir2/file2 ]]"
3709
-
3710
-		RUN sh -c "[[ ! -e /dir1/dir2/file4 ]]"
3711
-		RUN sh -c "[[ ! -e /dir1/dir2/file5 ]]"
3712
-		RUN sh -c "[[ ! -e /dir1/dir2/file6 ]]"
3713
-		RUN sh -c "[[ ! -e /dir1/dir3/file7 ]]"
3714
-		RUN sh -c "[[ ! -e /dir1/dir3/file8 ]]"
3715
-		RUN sh -c "[[   -e /dir1/dir3 ]]"
3716
-		RUN sh -c "[[   -e /dir1/dir4 ]]"
3717
-
3718
-		RUN sh -c "[[ ! -e 'dir1/dir5/fileAA' ]]"
3719
-		RUN sh -c "[[   -e 'dir1/dir5/fileAB' ]]"
3720
-		RUN sh -c "[[   -e 'dir1/dir5/fileB' ]]"   # "." in pattern means nothing
3697
+		RUN sh -c "[[ -e /Dockerfile ]]           && \
3698
+		           [[ ! -e /file0 ]]              && \
3699
+		           [[ ! -e /dir1/file0 ]]         && \
3700
+		           [[ ! -e /dir2/file0 ]]         && \
3701
+		           [[ ! -e /file1 ]]              && \
3702
+		           [[ ! -e /dir1/file1 ]]         && \
3703
+		           [[ ! -e /dir1/dir2/file1 ]]    && \
3704
+		           [[ ! -e /dir1/file2 ]]         && \
3705
+		           [[   -e /dir1/dir2/file2 ]]    && \
3706
+		           [[ ! -e /dir1/dir2/file4 ]]    && \
3707
+		           [[ ! -e /dir1/dir2/file5 ]]    && \
3708
+		           [[ ! -e /dir1/dir2/file6 ]]    && \
3709
+		           [[ ! -e /dir1/dir3/file7 ]]    && \
3710
+		           [[ ! -e /dir1/dir3/file8 ]]    && \
3711
+		           [[   -e /dir1/dir3 ]]          && \
3712
+		           [[   -e /dir1/dir4 ]]          && \
3713
+		           [[ ! -e 'dir1/dir5/fileAA' ]]  && \
3714
+		           [[   -e 'dir1/dir5/fileAB' ]]  && \
3715
+		           [[   -e 'dir1/dir5/fileB' ]]"   # "." in pattern means nothing
3721 3716
 
3722 3717
 		RUN echo all done!`
3723 3718