fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 643 forks source link

docker-build.tar does not include broken symlinks #1123

Open jakub-bochenski opened 6 years ago

jakub-bochenski commented 6 years ago

Description

Symlinks might not point to anything on the host system, but be useful inside the container.

More importantly this is different from the standard Docker behavior.

Info

Check the sample output in https://github.com/jakub-bochenski/demp-link-problem/blob/master/README.md

jakub-bochenski commented 6 years ago

I've checked that the files are already missing docker-build.tar

$ tar -tvf  target/docker/samples/demp-sample-zero-config/0.27.2/tmp/docker-build.tar 
-rw-rw-r-- bochja/bochja    69 2018-11-14 15:55 Dockerfile
drwxrwxr-x bochja/bochja     0 2018-11-14 15:55 target/
-rw-rw-r-- bochja/bochja   944 2018-11-14 15:50 pom.xml
lrwxrwxrwx bochja/bochja     0 2018-11-14 15:06 relative.link -> file
lrwxrwxrwx bochja/bochja     0 2018-11-14 15:06 absolute.link -> /home/bochja/tmp/linktest/file
-rw-rw-r-- bochja/bochja     0 2018-11-14 15:06 file
jakub-bochenski commented 6 years ago

@rhuss some pointers on how to fix this would be appreciated, I expect it's some simple configuration option

rhuss commented 5 years ago

Sorry for the late response, November is crazy busy with travelling for me. Actually I think this should be an option in the Maven archiver used for creating that tar, so that symlinks get resolved before being included into the tar. Need to check that, but I'm afraid can' t do it before mid December. Please ping me again in case I should forget it.

jakub-bochenski commented 5 years ago

I tried to follow your lead, but I see that since 3.5 the plexus archiver is not following symlinks: https://github.com/codehaus-plexus/plexus-archiver/commit/def8cab5b8496f7735f21a792619060d72958f59

I think it has to be something else, do you have any other hints? :)

screenshot_20181203_172222

jakub-bochenski commented 5 years ago

can' t do it before mid December. Please ping me again in case I should forget it.

Ping @rhuss Please note the post above about the plexus-archiver lead.

rhuss commented 5 years ago

Actually I could track down the issue to the Archiver which uses a DirectoryScanner which in turn is responsible for picking up the images. It has a loop like:

 for ( String newfile : newfiles )
        {
            if ( file.isDirectory() )
            {
                // ....
            }
            else if ( file.isFile() )
            {
               // ......
             }
     }

Unfortunately, java.io.File returns false for a symlink which does not point to a real file (true for an existing link).

I'm afraid that there is not much I can do here as it is burried deep in the libraries (plexus, Java SDK) which we are using and fixing this would require a major refactoring.

I'm out of ideas how to fix this without doing a massive change of the code base. Do you have any idea ?

jakub-bochenski commented 5 years ago

I should have just tried building a .tar with the assembly plugin earlier -- sorry about not doing that.

I think it's a valid issue that could be reported to plexus-utils, but I wouldn't expect a fix any time soon.

I'm out of ideas how to fix this without doing a massive change of the code base. Do you have any idea ?

There are some workarounds if you go outside the plugin. An obvious one would be to tar the contents from command line (exec plugin etc.) and use ADD instead of COPY to extract it.

For my case I think the best I can do is just do a RUN ln ... inside the Dockerfile instead. (I prefer to prepare the directory structure outside and just copy it whole into the docker context).

jakub-bochenski commented 5 years ago

PS. What I find really strange here is that apparently nobody ever hit this issue before.

Another thought: maybe it would be worth checking out how https://github.com/mojohaus/rpm-maven-plugin is handling this. (Specifically http://www.mojohaus.org/rpm-maven-plugin/map-params.html)