From c77bb28dfb4e248005ed0c447df9d11d1822e133 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 3 Mar 2016 23:16:10 +0000 Subject: [PATCH] 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 --- integration-cli/docker_cli_build_test.go | 43 +++++++++++------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 387ee86603..fe037de3ba 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -3694,30 +3694,25 @@ func (s *DockerSuite) TestBuildDockerignoringWildDirs(c *check.C) { FROM busybox COPY . / #RUN sh -c "[[ -e /.dockerignore ]]" - RUN sh -c "[[ -e /Dockerfile ]]" - - RUN sh -c "[[ ! -e /file0 ]]" - RUN sh -c "[[ ! -e /dir1/file0 ]]" - RUN sh -c "[[ ! -e /dir2/file0 ]]" - - RUN sh -c "[[ ! -e /file1 ]]" - RUN sh -c "[[ ! -e /dir1/file1 ]]" - RUN sh -c "[[ ! -e /dir1/dir2/file1 ]]" - - RUN sh -c "[[ ! -e /dir1/file2 ]]" - RUN sh -c "[[ -e /dir1/dir2/file2 ]]" - - RUN sh -c "[[ ! -e /dir1/dir2/file4 ]]" - RUN sh -c "[[ ! -e /dir1/dir2/file5 ]]" - RUN sh -c "[[ ! -e /dir1/dir2/file6 ]]" - RUN sh -c "[[ ! -e /dir1/dir3/file7 ]]" - RUN sh -c "[[ ! -e /dir1/dir3/file8 ]]" - RUN sh -c "[[ -e /dir1/dir3 ]]" - RUN sh -c "[[ -e /dir1/dir4 ]]" - - RUN sh -c "[[ ! -e 'dir1/dir5/fileAA' ]]" - RUN sh -c "[[ -e 'dir1/dir5/fileAB' ]]" - RUN sh -c "[[ -e 'dir1/dir5/fileB' ]]" # "." in pattern means nothing + RUN sh -c "[[ -e /Dockerfile ]] && \ + [[ ! -e /file0 ]] && \ + [[ ! -e /dir1/file0 ]] && \ + [[ ! -e /dir2/file0 ]] && \ + [[ ! -e /file1 ]] && \ + [[ ! -e /dir1/file1 ]] && \ + [[ ! -e /dir1/dir2/file1 ]] && \ + [[ ! -e /dir1/file2 ]] && \ + [[ -e /dir1/dir2/file2 ]] && \ + [[ ! -e /dir1/dir2/file4 ]] && \ + [[ ! -e /dir1/dir2/file5 ]] && \ + [[ ! -e /dir1/dir2/file6 ]] && \ + [[ ! -e /dir1/dir3/file7 ]] && \ + [[ ! -e /dir1/dir3/file8 ]] && \ + [[ -e /dir1/dir3 ]] && \ + [[ -e /dir1/dir4 ]] && \ + [[ ! -e 'dir1/dir5/fileAA' ]] && \ + [[ -e 'dir1/dir5/fileAB' ]] && \ + [[ -e 'dir1/dir5/fileB' ]]" # "." in pattern means nothing RUN echo all done!`