Skip to content

extraDirectories property should validate if the supplied path exists #3542

Closed
@tommysitu

Description

@tommysitu
Contributor

Environment:

  • Jib version: 3.1.4
  • Build tool: Maven 3.6.2

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

Activity

meltsufin

meltsufin commented on Jan 4, 2022

@meltsufin
Contributor

Thank you for submitting this enhancement request.

chanseokoh

chanseokoh commented on Jan 4, 2022

@chanseokoh
Member

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

tommysitu commented on Jan 14, 2022

@tommysitu
ContributorAuthor

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

chanseokoh

chanseokoh commented on Jan 14, 2022

@chanseokoh
Member

@tommysitu I just approved it.

tommysitu

tommysitu commented on Jan 19, 2022

@tommysitu
ContributorAuthor

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

added this to the v3.2.0 milestone on Jan 19, 2022
chanseokoh

chanseokoh commented on Jan 26, 2022

@chanseokoh
Member

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

cebrailinanc commented on Feb 9, 2024

@cebrailinanc

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

chanseokoh commented on Feb 9, 2024

@chanseokoh
Member

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

cebrailinanc

cebrailinanc commented on Feb 9, 2024

@cebrailinanc

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

chanseokoh

chanseokoh commented on Feb 9, 2024

@chanseokoh
Member

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

cebrailinanc commented on Feb 9, 2024

@cebrailinanc

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

chanseokoh

chanseokoh commented on Feb 9, 2024

@chanseokoh
Member

Sure, go ahead open a new issue.

chanseokoh

chanseokoh commented on Feb 9, 2024

@chanseokoh
Member

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

cebrailinanc commented on Feb 9, 2024

@cebrailinanc

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"
			}
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @tommysitu@chanseokoh@cebrailinanc@meltsufin

      Issue actions

        extraDirectories property should validate if the supplied path exists · Issue #3542 · GoogleContainerTools/jib