GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.64k stars 1.44k forks source link

Empty folders in the /app/resources directory slow down resource file scanning #4209

Open gubiao opened 7 months ago

gubiao commented 7 months ago

Environment:

Description of the issue: There are a large number of empty folders in the /app/resources directory in the container. It seems that all java packages have corresponding folders in the /resources directory, regardless of whether they contain resource files.

Expected behavior: If the java package does not contain resource files, do not create corresponding empty folders in the /app/resources directory in the container. Or provide an includeEmptyDirs configuration parameter like maven resource plugin.

Steps to reproduce:

$ git clone https://github.com/GoogleContainerTools/jib.git
$ cd jib/examples/helloworld
Delete the following lines in pom.xml
<configuration>
  <to>
    <image>gcr.io/REPLACE-WITH-YOUR-GCP-PROJECT/image-built-with-jib</image>
  </to>
</configuration>
$ mvn compile jib:dockerBuild
$ docker run --entrypoint /bin/bash --interactive --tty helloworld:1
# ls -alh /app/resources/example/
total 8.0K
drwxr-xr-x 2 root root 4.0K Jan  1  1970 .
drwxr-xr-x 3 root root 4.0K Jan  1  1970 ..

As you can see now, every java package that does not contain resource files has an empty folder in the /app/resources directory.

There are a lot of java packages in my current project. If there are a lot of empty folders in the /app/resources directory in the container, resource file search will become slow. For example, use Spring to scan the Hibernate mapping files: classpath*:/*/.hbm .xml.

Additional Information: I also tried Jib Layer-Filter Extension, but it only provides glob-based file filter and cannot filter empty folders.