@@ -7311,3 +7311,154 @@ func (s *DockerSuite) TestBuildNetContainer(c *check.C) {
73117311 host , _ := dockerCmd (c , "run" , "testbuildnetcontainer" , "cat" , "/otherhost" )
73127312 c .Assert (strings .TrimSpace (host ), check .Equals , "foobar" )
73137313}
7314+
7315+ // Test case for #24693
7316+ func (s * DockerSuite ) TestBuildRunEmptyLineAfterEscape (c * check.C ) {
7317+ name := "testbuildemptylineafterescape"
7318+ _ , out , err := buildImageWithOut (name ,
7319+ `
7320+ FROM busybox
7321+ RUN echo x \
7322+
7323+ RUN echo y
7324+ RUN echo z
7325+ # Comment requires the '#' to start from position 1
7326+ # RUN echo w
7327+ ` , true )
7328+ c .Assert (err , checker .IsNil )
7329+ c .Assert (out , checker .Contains , "Step 1/4 : FROM busybox" )
7330+ c .Assert (out , checker .Contains , "Step 2/4 : RUN echo x" )
7331+ c .Assert (out , checker .Contains , "Step 3/4 : RUN echo y" )
7332+ c .Assert (out , checker .Contains , "Step 4/4 : RUN echo z" )
7333+
7334+ // With comment, see #24693
7335+ name = "testbuildcommentandemptylineafterescape"
7336+ _ , out , err = buildImageWithOut (name ,
7337+ `
7338+ FROM busybox
7339+ RUN echo grafana && \
7340+ echo raintank \
7341+ #echo env-load
7342+ RUN echo vegeta
7343+ ` , true )
7344+ c .Assert (err , checker .IsNil )
7345+ c .Assert (out , checker .Contains , "Step 1/3 : FROM busybox" )
7346+ c .Assert (out , checker .Contains , "Step 2/3 : RUN echo grafana && echo raintank" )
7347+ c .Assert (out , checker .Contains , "Step 3/3 : RUN echo vegeta" )
7348+ }
7349+
7350+ // Verifies if COPY file . when WORKDIR is set to a non-existing directory,
7351+ // the directory is created and the file is copied into the directory,
7352+ // as opposed to the file being copied as a file with the name of the
7353+ // directory. Fix for 27545 (found on Windows, but regression good for Linux too)
7354+ func (s * DockerSuite ) TestBuildCopyFileDotWithWorkdir (c * check.C ) {
7355+ name := "testbuildcopyfiledotwithworkdir"
7356+
7357+ ctx , err := fakeContext (`FROM busybox
7358+ WORKDIR /foo
7359+ COPY file .
7360+ RUN ["cat", "/foo/file"]
7361+ ` ,
7362+ map [string ]string {})
7363+ if err != nil {
7364+ c .Fatal (err )
7365+ }
7366+ defer ctx .Close ()
7367+ if err := ctx .Add ("file" , "content" ); err != nil {
7368+ c .Fatal (err )
7369+ }
7370+ if _ , err = buildImageFromContext (name , ctx , true ); err != nil {
7371+ c .Fatal (err )
7372+ }
7373+ }
7374+
7375+ func (s * DockerSuite ) TestBuildSquashParent (c * check.C ) {
7376+ testRequires (c , ExperimentalDaemon )
7377+ dockerFile := `
7378+ FROM busybox
7379+ RUN echo hello > /hello
7380+ RUN echo world >> /hello
7381+ RUN echo hello > /remove_me
7382+ ENV HELLO world
7383+ RUN rm /remove_me
7384+ `
7385+ // build and get the ID that we can use later for history comparison
7386+ origID , err := buildImage ("test" , dockerFile , false )
7387+ c .Assert (err , checker .IsNil )
7388+
7389+ // build with squash
7390+ id , err := buildImage ("test" , dockerFile , true , "--squash" )
7391+ c .Assert (err , checker .IsNil )
7392+
7393+ out , _ := dockerCmd (c , "run" , "--rm" , id , "/bin/sh" , "-c" , "cat /hello" )
7394+ c .Assert (strings .TrimSpace (out ), checker .Equals , "hello\n world" )
7395+
7396+ dockerCmd (c , "run" , "--rm" , id , "/bin/sh" , "-c" , "[ ! -f /remove_me ]" )
7397+ dockerCmd (c , "run" , "--rm" , id , "/bin/sh" , "-c" , `[ "$(echo $HELLO)" == "world" ]` )
7398+
7399+ // make sure the ID produced is the ID of the tag we specified
7400+ inspectID , err := inspectImage ("test" , ".ID" )
7401+ c .Assert (err , checker .IsNil )
7402+ c .Assert (inspectID , checker .Equals , id )
7403+
7404+ origHistory , _ := dockerCmd (c , "history" , origID )
7405+ testHistory , _ := dockerCmd (c , "history" , "test" )
7406+
7407+ splitOrigHistory := strings .Split (strings .TrimSpace (origHistory ), "\n " )
7408+ splitTestHistory := strings .Split (strings .TrimSpace (testHistory ), "\n " )
7409+ c .Assert (len (splitTestHistory ), checker .Equals , len (splitOrigHistory )+ 1 )
7410+
7411+ out , err = inspectImage (id , "len .RootFS.Layers" )
7412+ c .Assert (err , checker .IsNil )
7413+ c .Assert (strings .TrimSpace (out ), checker .Equals , "3" )
7414+ }
7415+
7416+ func (s * DockerSuite ) TestBuildContChar (c * check.C ) {
7417+ name := "testbuildcontchar"
7418+
7419+ _ , out , err := buildImageWithOut (name ,
7420+ `FROM busybox\` , true )
7421+ c .Assert (err , checker .IsNil )
7422+ c .Assert (out , checker .Contains , "Step 1/1 : FROM busybox" )
7423+
7424+ _ , out , err = buildImageWithOut (name ,
7425+ `FROM busybox
7426+ RUN echo hi \` , true )
7427+ c .Assert (err , checker .IsNil )
7428+ c .Assert (out , checker .Contains , "Step 1/2 : FROM busybox" )
7429+ c .Assert (out , checker .Contains , "Step 2/2 : RUN echo hi\n " )
7430+
7431+ _ , out , err = buildImageWithOut (name ,
7432+ `FROM busybox
7433+ RUN echo hi \\` , true )
7434+ c .Assert (err , checker .IsNil )
7435+ c .Assert (out , checker .Contains , "Step 1/2 : FROM busybox" )
7436+ c .Assert (out , checker .Contains , "Step 2/2 : RUN echo hi \\ \n " )
7437+
7438+ _ , out , err = buildImageWithOut (name ,
7439+ `FROM busybox
7440+ RUN echo hi \\\` , true )
7441+ c .Assert (err , checker .IsNil )
7442+ c .Assert (out , checker .Contains , "Step 1/2 : FROM busybox" )
7443+ c .Assert (out , checker .Contains , "Step 2/2 : RUN echo hi \\ \\ \n " )
7444+ }
7445+
7446+ // TestBuildOpaqueDirectory tests that a build succeeds which
7447+ // creates opaque directories.
7448+ // See https://github.com/docker/docker/issues/25244
7449+ func (s * DockerSuite ) TestBuildOpaqueDirectory (c * check.C ) {
7450+ testRequires (c , DaemonIsLinux )
7451+
7452+ dockerFile := `
7453+ FROM busybox
7454+ RUN mkdir /dir1 && touch /dir1/f1
7455+ RUN rm -rf /dir1 && mkdir /dir1 && touch /dir1/f2
7456+ RUN touch /dir1/f3
7457+ RUN [ -f /dir1/f2 ]
7458+ `
7459+
7460+ // Test that build succeeds, last command fails if opaque directory
7461+ // was not handled correctly
7462+ _ , err := buildImage ("testopaquedirectory" , dockerFile , false )
7463+ c .Assert (err , checker .IsNil )
7464+ }
0 commit comments