Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extraDirectories property should validate if the supplied path exists #3542

Closed
tommysitu opened this issue Dec 31, 2021 · 14 comments · Fixed by #3550
Closed

extraDirectories property should validate if the supplied path exists #3542

tommysitu opened this issue Dec 31, 2021 · 14 comments · Fixed by #3550

Comments

@tommysitu
Copy link
Contributor

tommysitu commented Dec 31, 2021

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

@meltsufin
Copy link
Contributor

Thank you for submitting this enhancement request.

@chanseokoh
Copy link
Member

chanseokoh commented Jan 4, 2022

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
Copy link
Contributor Author

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

@chanseokoh
Copy link
Member

@tommysitu I just approved it.

@tommysitu
Copy link
Contributor Author

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

@chanseokoh chanseokoh added this to the v3.2.0 milestone Jan 19, 2022
@chanseokoh
Copy link
Member

chanseokoh commented Jan 26, 2022

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
Copy link

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
Copy link
Member

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

@cebrailinanc
Copy link

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

@chanseokoh
Copy link
Member

chanseokoh commented Feb 9, 2024

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
Copy link

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

@chanseokoh
Copy link
Member

Sure, go ahead open a new issue.

@chanseokoh
Copy link
Member

chanseokoh commented Feb 9, 2024

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
Copy link

cebrailinanc commented Feb 9, 2024

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants