Jib: extraDirectory should maintain same project structure

Created on 26 Sep 2018  路  7Comments  路  Source: GoogleContainerTools/jib

Description of the issue:
Currently, when using <extraDirectories>, it dumps all files in the specific directory into the root of the docker container.

Expected behavior:
Similar to while using src/main/jib/..., <extraDirectories> should just use the directory structure when copying it into the docker container.

Environment: Maven

discuss

All 7 comments

Hi @bspradling , thanks for reporting this issue. We'll take a look at why this is happening (this is unintended).

Hi @bspradling, could you give more information, like the jib configuration in your pom.xml (with sensitive information removed if necessary) and the directory structure you're using? I'm having trouble reproducing the issue - when I try to use a custom <extraDirectories>, the directory structure within my custom directory is maintained relative to / within the image as intended.

Hey @TadCordle. I have a single module Maven project and the following is the Jib plugin configuration within my pom.xml:

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>0.9.10</version>
        <configuration>
          <from>
            <image>anapsix/alpine-java:8_server-jre_unlimited</image>
          </from>
          <to>
            <image>my-image:built-with-jib</image>
          </to>
          <extraDirectories><paths>${project.basedir}/.build/secrets/decrypted</paths></extraDirectories>
        </configuration>
      </plugin>

I'm trying to mount some secret files from .build/secrets/decrypted but when the image is created, I can exec into the container and see the expected files in the root (/) directory.

Let me know if there is anything else that I can provide or I am doing something wrong!

I think I might understand. Jib just takes the contents of the directory you specify and moves it to the root directory in the image, which is intended. To get the files where you need them to go, you need to setup the exact intended destination directory structure within your extra directory.

If you want your secret files to be in /.build/secrets/decrypted on your container, for example, then you would need to configure your extra directory, and have the extra directory itself contain .build/secrets/decrypted/....

E.g. configure <extraDirectories><paths>${project.basedir}/secretsDir</paths></extraDirectories> then put your secret files in <project dir>/secretsDir/.build/secrets/decrypted/... to get your files in /.build/secrets/decrypted/ on your image.

But I think I can see why you might not want to do this, if the .build directory contains other files that you don't want to add to the container, and you only want to add those secret files, but you don't want to add them to /. Extra layers in Jib is still an incubating feature, though, so if the current design doesn't match your use case and you have any suggestions for how you'd like it to work, feel free to let us know.

Let me know if this does/doesn't make sense, or if I'm misinterpreting the problem!

Nope! You are spot on there. Now that I understand, it makes a little more sense.

The concern that I would have is that you are effectively changing the directory structure from local runtime to docker runtime. Meaning that the same references to the files while running locally will now have to be different for when I run in a Docker container.

I see the workaround that keeps the directory structure the same by just having the / directory be the <extraDirectories>. However, as you mentioned, now I'm including my entire source code within the Docker image which is unnecessary.

I still think that using the directory structure provided in the <extraDirectories> would be my desired functionality. This would still allow people to add everything via / or add multiple tags (not sure if that is supported today) in the event a user wants to add multiple specific directories to the Docker container.

@bspradling it may be possible to use the copy-resources goal from the Maven resources plugin to set up whatever files and directory structures you need in an independent output directory and have <extraDirectories> to point to that output directory.

We discussed this as a team, and as @chanseokoh mentioned, we decided this is something best solved using maven/gradle to do some post-build processing. You should be able to accomplish what you need using copy-resources in Maven or a Copy task in Gradle. We've updated the FAQ with some simple examples for how to do this, which you can check out over here.

Was this page helpful?
0 / 5 - 0 ratings