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

Files with --pre-archive are only copied if there are Volumes/Bind Mounts #89

Closed
tricktron opened this issue Jun 5, 2024 · 1 comment · Fixed by #90
Closed

Files with --pre-archive are only copied if there are Volumes/Bind Mounts #89

tricktron opened this issue Jun 5, 2024 · 1 comment · Fixed by #90
Labels
bug Something isn't working

Comments

@tricktron
Copy link
Contributor

First of all thank you for this great project. It works amazingly well.

Summary

  • Current behaviour: Using the --pre-archive flag only copies files if there are volumes configured.
  • Expected behaviour: Using the --pre-archive flag always copies files, if there are files available.

Context

The withFileSystemBind got deprecated and replaced with withCopyToContainer. As a result, most testcontainer module providers will therefore switch to using withCopyToContainer somewhere deep down in their file config helper methods, e.g.:

yourContainer = new ContainerFromModule("someImage")
    .withRamPercentage(75, 75) // some nice helper config function
    .withRealmImportFile("/your-realm.json") // some file helper function which will use `withCopyToContainer` in the end
    ...

These config files must be copied to the container before it is started. It makes therefore sense to use the --pre-archive flag to get these files copied so that we can continue profiting from these useful upstream helper functions because otherwise the alternatives are:

  • Use the --pre-archive flag and replace the helper functions with your own manual withFileSystemBind calls: This is not nice because you will have to do all the work of the upstream helper functions manually. See also Copying a file to a container before starting it #53.
  • Do not use the --pre-archive flag and therefore kubedock will copy the files after the container has already started and therefore you need to wait for the files to be copied using a custom command/entrypoint (See also Copying a file to a container before starting it #53).
  • Use the --pre-archive flag and a manual existing bind mount as shown below as a current work around

Current Manual Workaround

Just add an existing Bind mount and the --pre-archive flag works as expected and you can continue using the upstream testcontainer module's helper functions, e.g.:

yourContainer = new ContainerFromModule("someImage")
    .withCreateContainerCmdModifier(
         cmd ->
            cmd.getHostConfig()
            .withBinds
            (
                Bind.parse
                (
                    System.getProperty("user.dir") + "/pom.xml:/tmp/pom.xml" // any manual existing bind will do
                )
            )
    )
    ...
@joyrex2001
Copy link
Owner

Thanks for the great work 👍

@joyrex2001 joyrex2001 added the bug Something isn't working label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants