GoogleContainerTools / jib

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

extraDirectories property should validate if the supplied path exists #3542

Closed tommysitu closed 2 years ago

tommysitu commented 2 years ago

Environment:

Description of the issue:

<configuration>
    <extraDirectories>
         <paths>
             <path>missing/folder</path>
          </paths>
     </extraDirectories>
</configuration>

Using the extraDirectories config above to copy additional files doesn't fail the build even the path is invalid or not a folder. This behaviour is not good for catching bugs early if the additional files are crucial for the docker container.

Expected behaviour: Should be similar to the docker build command which would throw the following exception if a Dockerfile has a command to copy a non-existent folder:

 => ERROR [stage-1 2/2] COPY missing/folder /app                                                                                                                                     0.0s
------
 > [stage-1 2/2] COPY missing/folder /app:
------
failed to compute cache key: "/missing/folder" not found: not found
meltsufin commented 2 years ago

Thank you for submitting this enhancement request.

chanseokoh commented 2 years ago

The reason we don't check the existence is due to the default implicit directory src/main/jib, which doesn't exist often. Perhaps we should fail only for non-default directories. Contributions are welcome.

tommysitu commented 2 years ago

Hi @chanseokoh I've raised a PR. Could you approve the build? so that we can see which tests are failing. Thanks!

chanseokoh commented 2 years ago

@tommysitu I just approved it.

tommysitu commented 2 years ago

Thanks for reviewing the PR @chanseokoh. Shall I close this issue?

chanseokoh commented 2 years ago

From Jib Gitter:

extraDirectories now have to be present while running the jib plugin. I have some directories which might be generated during the build process (depending on the situation). How can we deal with such situation? Checking for the existence of the file does not work since the extraDirectories setting is evaluated during the Configuration Stage of the plugin, when the directory is not present yet.

One workaround in Gradle I can think of is to create it explicitly:

  extraDirectories {
    mkdir "${buildDir}/jib-extras"
    paths = ["${buildDir}/jib-extras"]
  }
cebrailinanc commented 9 months ago

i got error on gradle Execution failed for task ':jib'.

extraDirectories.paths contain "from" directory that doesn't exist locally: /aass/test

my command: ./gradlew jib ... -Djib.extraDirectories.paths=truststore,/aass/test

chanseokoh commented 9 months ago

@cebrailinanc just create the directory before running Gradle, like mkdir /aass/test.

cebrailinanc commented 9 months ago

I tried but it didn't work. Because we need to open a folder within the image.

chanseokoh commented 9 months ago

Oh, I see what you were thinking. It must be that you thought the syntax of the command-line parameter would be

-Djib.extraDirectories.paths=<from_1>,<to_1>,<from_2>,<to_2>,...

, but the command-line supports only the basic form of

-Djib.extraDirectories.paths=<from_1>,<from_2>,<from_3>,...

. If you want to specify the to directories, you have to set it in a Gradle build file.

cebrailinanc commented 9 months ago

i think, it's not useful, Should we open an issue?

chanseokoh commented 9 months ago

Sure, go ahead open a new issue.

chanseokoh commented 9 months ago

Anyways, if you are familiar with Gradle, you can always define your own property as a workaround to templatize to directiories on the command-line.

cebrailinanc commented 9 months ago

I used it by defining it in the build.gradle. But it would be usable to add the command line in the future, thank you.

jib {
    extraDirectories {
        paths {
            path {
                setFrom("extra")
                into = "/aass/test"
            }
        }
    }
}