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

Allow to add single file to a container (with setting rights) #2564

Closed
tomikmar opened this issue Jul 2, 2020 · 3 comments · Fixed by #3173
Closed

Allow to add single file to a container (with setting rights) #2564

tomikmar opened this issue Jul 2, 2020 · 3 comments · Fixed by #3173

Comments

@tomikmar
Copy link

tomikmar commented Jul 2, 2020

Environment:

  • Jib version: 2.4.0
  • Build tool: maven:3.6.3-amazoncorretto-11
  • OS: Amazon Linux 2

Description of the issue:

It would be useful if it was possible to add single file to a container (with setting rights). I am currently migrating from one system to the other and for some time I need to keep things compatible between both of them. Currently it is not possible (without workaround) to move the following Dockerfile command to jib-maven-plugin (it's possible only for directories):

COPY ./ssh/id_rsa /home/myuser/.ssh/id_rsa

Steps to reproduce:

<extraDirectories>
    <paths>
        <path>
            <from>./ssh/id_rsa</from>
            <into>/home/myuser/.ssh/id_rsa</into>
         </path>
    </paths>
</extraDirectories>

Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.4.0:build (default-cli) on project config: /home/builder/src/config/ssh/id_rsa is not a directory -> [Help 1]

@loosebazooka
Copy link
Member

Yeah it's a limitation of our system, it only works for directories. You probably need to make sure the ssh directory only has the id_rsa file, and copy that directory over.

<from>./ssh</from>
<into>/home/myuser/.ssh</into>

@chanseokoh
Copy link
Member

Copying the following comment from #3164, as this issue was opened far earlier and has many thumbs-ups.


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

chanseokoh commented Apr 9, 2021

@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

Successfully merging a pull request may close this issue.

3 participants