Created method which copy file from repository to container#378
Created method which copy file from repository to container#378lukidzi wants to merge 9 commits intotestcontainers:masterfrom
Conversation
…e point to container path.
|
|
||
| InspectContainerResponse getContainerInfo(); | ||
|
|
||
| void copyFileToContanier(String localPath, String containerPath); |
There was a problem hiding this comment.
I suggest using MountableFile instead of String localPath
| */ | ||
| @Override | ||
| public void copyFileToContanier(String localPath, String containerPath){ | ||
|
|
There was a problem hiding this comment.
since isRunning calls Docker API, I would remove this check and catch an exception from .exec()
| @@ -850,6 +850,27 @@ public ExecResult execInContainer(String... command) | |||
| return execInContainer(UTF8, command); | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
please move the JavaDoc to Container interface
|
Hi @lukidzi, Thanks for your contribution! I added a few review notes from me :) I would also like to see the tests for this change |
|
|
||
| InspectContainerResponse getContainerInfo(); | ||
|
|
||
| void copyFileToContanier(String localPath, String containerPath); |
|
Hey @glebsts, looks good, but could you please fix what Coday says? (press Thanks! |
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public void copyFileToContainer(MountableFile mountableLocalFile, String containerPath) throws IOException, InterruptedException { |
| * Create a container which wait for some time to test if copy to container works. | ||
| */ | ||
| @ClassRule | ||
| public static GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") |
There was a problem hiding this comment.
Actually, it would be nice if you can replace it with try-with-resources version (see NetworkTest.WithoutRules). It helps to run individual tests without starting everything
|
@bsideup wrong mention, I guess?) |
…ed method to getResolvedPath
|
|
||
| /** | ||
| * | ||
| * Method allow to copy file which we have in our repository to docker container |
There was a problem hiding this comment.
Small Javadoc change:
This method allows to copy a file
There was a problem hiding this comment.
I also think it's a file inside the classpath and not inside the repository, correct?
| .withCommand("/bin/sh", "-c", "while true; do cat /etc/hosts | nc -l -p 80; done"); | ||
|
|
||
| // @Test |
There was a problem hiding this comment.
the code wasn't commented in this PR.
Although +1 for removing this added space
|
@lukidzi I think this would be a good thing to have if you're still interested in contributing. If you're stuck for time please let us know, though, as it doesn't look like thee's too much more to do. |
kiview
left a comment
There was a problem hiding this comment.
Hey, sorry for not looking into this PR for some time. I've requested some minor Javadoc changes, and will merge ASAP afterwards.
|
|
||
| /** | ||
| * | ||
| * Method allow to copy file which is inside classpath to docker container |
There was a problem hiding this comment.
Copies a file which resides inside the classpath to the container.
| * | ||
| * Method allow to copy file which is inside classpath to docker container | ||
| * | ||
| * @param mountableLocalFile path to file which we would like to place in container |
There was a problem hiding this comment.
file which is copied into the container
| * Method allow to copy file which is inside classpath to docker container | ||
| * | ||
| * @param mountableLocalFile path to file which we would like to place in container | ||
| * @param containerPath path where we want to copy file |
There was a problem hiding this comment.
destination path inside the container
|
@bsideup You're review is still pending, I think the changes are fine now? |
|
|
||
| try ( | ||
| GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") | ||
| .withCommand("sleep 9999") |
There was a problem hiding this comment.
please use top instead of sleep 9999
| final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); | ||
| alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/"); | ||
|
|
||
| try (final InputStream response = alpineCopyToContainer |
There was a problem hiding this comment.
Since it was requested a few times already, maybe you can add copyFileFromContainer() as well? :) We should also check the file content here
| try (final InputStream response = this.dockerClient | ||
| .copyArchiveFromContainerCmd(this.containerId, containerPath) | ||
| .exec()) { | ||
| try (final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(response)) { |
There was a problem hiding this comment.
no need for the nested trys, just wrap .exec() result into TarArchiveInputStream
| * @throws IOException if there will be error during getNextTarEntry | ||
| */ | ||
| private void createFileFromTarArchiveInputStream(final String destinationPath, final TarArchiveInputStream tarArchiveInputStream) throws IOException { | ||
| try (final FileOutputStream out = new FileOutputStream(destinationPath)) { |
There was a problem hiding this comment.
We have IOUtils on classpath, please use IOUtils.copy()
| @Test | ||
| public void copyToContainerTest() throws Exception { | ||
| //compare purpose | ||
| File outputFile = new File("src/test/resources/copy-from/test_copy_to_container.txt"); |
There was a problem hiding this comment.
output file should not be placed in src/test, use a temporary directory instead
| //compare purpose | ||
| File outputFile = new File("src/test/resources/copy-from/test_copy_to_container.txt"); | ||
| File currentFile = new File("src/test/resources/test_copy_to_container.txt"); | ||
| if(outputFile.exists()){ |
There was a problem hiding this comment.
temp dir will help to avoid this one as well
| private static final int RABBITMQ_PORT = 5672; | ||
| private static final int MONGO_PORT = 27017; | ||
|
|
||
| private static final File CONTENT_FOLDER = new File(System.getProperty("user.home") + "/.tmp-test-container"); |
There was a problem hiding this comment.
Why don't you use something like Files.createTempDirectory()?
|
approved, thanks! @rnorth do you have something to add? |
|
Sorry for being slow to respond - just noticed one more thing: because these methods only work when the container is created/running, we should add guards to check and log a suitable error message. I have the branch locally, so will add that. |
|
Have rebased and squashed on a separate branch, so will merge from there. |
|
Merged! Thank you for the contribution @lukidzi ! |
I am not sure if this function will be helpful. This is first concept I need to figure out how to check if path exist, how to get message if couldn't copy, and write some tests. I am tested it and I was able to copy file from my resource directory to container.