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

Enhancement: Have an <extraFiles> option to add individual files instead of a whole directory #3164

Closed
MiellyEllen opened this issue Mar 23, 2021 · 4 comments

Comments

@MiellyEllen
Copy link

MiellyEllen commented Mar 23, 2021

Environment:

  • *Jib version:*2.8.0
  • Build tool: mvn
  • OS: Windows

Description of the issue:
If this does not exist already, could there be an enhancement to add individual files into an image layer, rather than selecting all the files in a directory.

Expected behavior:

<extraFiles>
   <extraFile><from>../folder1/context1.xml</from><to>/app/contexts</to></extrafile>
<extraFiles>

Additional Information: If this is not available, is there an expected version where this might be added?

@chanseokoh
Copy link
Member

Thanks for the feedback! Yeah, unfortunately <extraDirectories> requires preparing a directory. If you can just put the file at src/main/jib/app/contexts/context1.xml, the file will be copied into the image (as /src/main/jib is the default extra directory).

If you can't put it in src/main/jib (e.g., you don't want to duplicate the file, or you only want to filter out a single file in a directory), it's still easy to prepare a directory in Maven. Here's an example using maven-resources-plugin, which prepares the directory target/jib-extras to be used for <extraDirectories>:

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-extras</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>target/jib-extras</outputDirectory>
              <resources>
                <resource>
                  <directory>target/some-files</directory>
                  <includes>**/*.txt,**/*.rtf</includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

Then for the Jib configuration,

          <extraDirectories>
            <paths>
              <path>
                <from>target/jib-extras</from>
                <into>/dest-dir</into>
              </path>
            </paths>
          </extraDirectories>

I'm not saying that adding the <extraFiles> feature doesn't provide a value; I think it's useful in many situations. It's just that it will be a low priority for us, and there's a workaround.

But probably, instead of adding the new config <extraFiles>, what we could do is to add a filtering mechanism similar to maven-resources-plugin. For example,

          <extraDirectories>
            <paths>
              <path>
                <from>../folder1/</from>
                <into>/app/contexts</into>
                <includes>context1.xml</includes>
              </path>
            </paths>
          </extraDirectories>

That way, we can have the same effect of copying a single file without adding <extraFiles>. What's even better is that it's more general and flexible and enables copying multiple files.

@chanseokoh
Copy link
Member

Actually, we have an open issue. Closing this as a dup of #2564. Please follow #2564.

@MiellyEllen
Copy link
Author

Thanks so much for the very helpful feedback as well as the priority insight.
Cheers!

@chanseokoh
Copy link
Member

@tomikmar @labmonkey @andritch @daanschipper @cpvandehey @Nemesys @MiellyEllen

We released Jib plugins 3.0 that implemented a inclusion/exclusion feature to <extraDirectories>, which not only makes it super easy to add a single file but is very flexible in copying a subset of files. Check out the docs (Gradle / Maven) for example usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants