-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implementation of copy archive to/from container commands #347
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cae2924
Implementations of Copy file to container command
vuminhkh 89bb406
Use new try syntax for Java to free resources
vuminhkh 90f4aba
Use java 7 to close stream
vuminhkh 28c6f94
Merge branch 'master' into master-vuminhkh
vuminhkh 7a6ef52
Merge branch 'master' into master-vuminhkh
vuminhkh 1eb06f5
Merge branch 'master' into master-vuminhkh
vuminhkh f44ee8f
Rename CopyFileFromContainerCmd and CopyFileToContainerCmd to CopyArc…
vuminhkh 6124775
Reset CopyFileFromContainerCmd for compatibility purpose
vuminhkh 0f65469
Fix formatting rules
vuminhkh 8232049
Merge branch 'master' into master-vuminhkh
vuminhkh fca2ea5
Re-design API to accept both a path and a tar input stream
vuminhkh 2144d2b
Merge branch 'master' into master-vuminhkh
vuminhkh 0871b9d
Minor fix API doc
vuminhkh a72355f
Rollback unrelated changes due to code formatter
vuminhkh 477f4a1
Use remote api version constant
vuminhkh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/dockerjava/api/command/CopyArchiveFromContainerCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.github.dockerjava.api.command; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import javax.annotation.CheckForNull; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| import com.github.dockerjava.api.exception.NotFoundException; | ||
|
|
||
| public interface CopyArchiveFromContainerCmd extends SyncDockerCmd<InputStream> { | ||
|
|
||
| @CheckForNull | ||
| public String getContainerId(); | ||
|
|
||
| @CheckForNull | ||
| public String getHostPath(); | ||
|
|
||
| @CheckForNull | ||
| public String getResource(); | ||
|
|
||
| public CopyArchiveFromContainerCmd withContainerId(@Nonnull String containerId); | ||
|
|
||
| public CopyArchiveFromContainerCmd withHostPath(String hostPath); | ||
|
|
||
| public CopyArchiveFromContainerCmd withResource(@Nonnull String resource); | ||
|
|
||
| /** | ||
| * Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks. | ||
| * | ||
| * @throws NotFoundException | ||
| * No such container | ||
| */ | ||
| @Override | ||
| public InputStream exec() throws NotFoundException; | ||
|
|
||
| public static interface Exec extends DockerCmdSyncExec<CopyArchiveFromContainerCmd, InputStream> { | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/github/dockerjava/api/command/CopyArchiveToContainerCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package com.github.dockerjava.api.command; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import com.github.dockerjava.api.exception.NotFoundException; | ||
|
|
||
| public interface CopyArchiveToContainerCmd extends SyncDockerCmd<Void> { | ||
|
|
||
| String getContainerId(); | ||
|
|
||
| String getHostResource(); | ||
|
|
||
| InputStream getTarInputStream(); | ||
|
|
||
| boolean isNoOverwriteDirNonDir(); | ||
|
|
||
| boolean isDirChildrenOnly(); | ||
|
|
||
| /** | ||
| * Set container's id | ||
| * | ||
| * @param containerId id of the container to copy file to | ||
| */ | ||
| CopyArchiveToContainerCmd withContainerId(String containerId); | ||
|
|
||
| /** | ||
| * Set path to the resource on the host machine | ||
| * | ||
| * @param resource path to the resource on the host machine | ||
| */ | ||
| CopyArchiveToContainerCmd withHostResource(String resource); | ||
|
|
||
| /** | ||
| * Set the tar input stream that will be uploaded to the container. withHostResource or withTarInputStream can be defined but not both. | ||
| * | ||
| * @param tarInputStream the stream to upload to the container | ||
| */ | ||
| CopyArchiveToContainerCmd withTarInputStream(InputStream tarInputStream); | ||
|
|
||
| /** | ||
| * If set to true then it will be an error if unpacking the given content would cause an existing directory to be replaced with a non-directory and vice versa | ||
| * | ||
| * @param noOverwriteDirNonDir flag to know if non directory can be overwritten | ||
| */ | ||
| CopyArchiveToContainerCmd withNoOverwriteDirNonDir(boolean noOverwriteDirNonDir); | ||
|
|
||
| /** | ||
| * If this flag is set to true, all children of the local directory will be copied to the remote without the root directory. | ||
| * For ex: if I have root/titi and root/tata and the remote path is /var/data. | ||
| * dirChildrenOnly = true will create /var/data/titi and /var/data/tata | ||
| * dirChildrenOnly = false will create /var/data/root/titi and /var/data/root/tata | ||
| * | ||
| * @param dirChildrenOnly if root directory is ignored | ||
| */ | ||
| CopyArchiveToContainerCmd withDirChildrenOnly(boolean dirChildrenOnly); | ||
|
|
||
| String getRemotePath(); | ||
|
|
||
| CopyArchiveToContainerCmd withRemotePath(String remotePath); | ||
|
|
||
| @Override | ||
| Void exec() throws NotFoundException; | ||
|
|
||
| interface Exec extends DockerCmdSyncExec<CopyArchiveToContainerCmd, Void> { | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| package com.github.dockerjava.core; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static usually imported after all imports
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using Intellij, it's re-arranged automatically like that by default. Please feel free to re-organize. |
||
|
|
||
| import java.io.Closeable; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
|
|
||
| import com.github.dockerjava.api.DockerClient; | ||
| import com.github.dockerjava.api.command.AttachContainerCmd; | ||
| import com.github.dockerjava.api.command.AuthCmd; | ||
| import com.github.dockerjava.api.command.BuildImageCmd; | ||
| import com.github.dockerjava.api.command.CommitCmd; | ||
| import com.github.dockerjava.api.command.ContainerDiffCmd; | ||
| import com.github.dockerjava.api.command.CopyArchiveFromContainerCmd; | ||
| import com.github.dockerjava.api.command.CopyFileFromContainerCmd; | ||
| import com.github.dockerjava.api.command.CreateContainerCmd; | ||
| import com.github.dockerjava.api.command.CreateImageCmd; | ||
|
|
@@ -45,6 +53,9 @@ | |
| import com.github.dockerjava.core.command.BuildImageCmdImpl; | ||
| import com.github.dockerjava.core.command.CommitCmdImpl; | ||
| import com.github.dockerjava.core.command.ContainerDiffCmdImpl; | ||
| import com.github.dockerjava.core.command.CopyArchiveFromContainerCmdImpl; | ||
| import com.github.dockerjava.api.command.CopyArchiveToContainerCmd; | ||
| import com.github.dockerjava.core.command.CopyArchiveToContainerCmdImpl; | ||
| import com.github.dockerjava.core.command.CopyFileFromContainerCmdImpl; | ||
| import com.github.dockerjava.core.command.CreateContainerCmdImpl; | ||
| import com.github.dockerjava.core.command.CreateImageCmdImpl; | ||
|
|
@@ -77,16 +88,8 @@ | |
| import com.github.dockerjava.core.command.VersionCmdImpl; | ||
| import com.github.dockerjava.core.command.WaitContainerCmdImpl; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| /** | ||
| * @author Konstantin Pelykh ([email protected]) | ||
| * | ||
| * @see "https://github.com/docker/docker/blob/master/api/client/commands.go" | ||
| */ | ||
| public class DockerClientImpl implements Closeable, DockerClient { | ||
|
|
@@ -304,6 +307,18 @@ public CopyFileFromContainerCmd copyFileFromContainerCmd(String containerId, Str | |
| containerId, resource); | ||
| } | ||
|
|
||
| @Override | ||
| public CopyArchiveFromContainerCmd copyArchiveFromContainerCmd(String containerId, String resource) { | ||
| return new CopyArchiveFromContainerCmdImpl(getDockerCmdExecFactory().createCopyArchiveFromContainerCmdExec(), | ||
| containerId, resource); | ||
| } | ||
|
|
||
| @Override | ||
| public CopyArchiveToContainerCmd copyArchiveToContainerCmd(String containerId) { | ||
| return new CopyArchiveToContainerCmdImpl(getDockerCmdExecFactory().createCopyArchiveToContainerCmdExec(), | ||
| containerId); | ||
| } | ||
|
|
||
| @Override | ||
| public ContainerDiffCmd containerDiffCmd(String containerId) { | ||
| return new ContainerDiffCmdImpl(getDockerCmdExecFactory().createContainerDiffCmdExec(), containerId); | ||
|
|
||
71 changes: 71 additions & 0 deletions
71
src/main/java/com/github/dockerjava/core/command/CopyArchiveFromContainerCmdImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package com.github.dockerjava.core.command; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import com.github.dockerjava.api.command.CopyArchiveFromContainerCmd; | ||
| import com.github.dockerjava.api.exception.NotFoundException; | ||
|
|
||
| /** | ||
| * Copy files or folders from a container. | ||
| */ | ||
| public class CopyArchiveFromContainerCmdImpl extends AbstrDockerCmd<CopyArchiveFromContainerCmd, InputStream> implements | ||
| CopyArchiveFromContainerCmd { | ||
|
|
||
| private String containerId; | ||
|
|
||
| private String hostPath = "."; | ||
|
|
||
| private String resource; | ||
|
|
||
| public CopyArchiveFromContainerCmdImpl(CopyArchiveFromContainerCmd.Exec exec, String containerId, String resource) { | ||
| super(exec); | ||
| withContainerId(containerId); | ||
| withResource(resource); | ||
| } | ||
|
|
||
| @Override | ||
| public String getContainerId() { | ||
| return containerId; | ||
| } | ||
|
|
||
| @Override | ||
| public String getResource() { | ||
| return resource; | ||
| } | ||
|
|
||
| @Override | ||
| public CopyArchiveFromContainerCmdImpl withContainerId(String containerId) { | ||
| checkNotNull(containerId, "containerId was not specified"); | ||
| this.containerId = containerId; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CopyArchiveFromContainerCmdImpl withResource(String resource) { | ||
| checkNotNull(resource, "resource was not specified"); | ||
| this.resource = resource; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public String getHostPath() { | ||
| return hostPath; | ||
| } | ||
|
|
||
| @Override | ||
| public CopyArchiveFromContainerCmdImpl withHostPath(String hostPath) { | ||
| checkNotNull(hostPath, "hostPath was not specified"); | ||
| this.hostPath = hostPath; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * @throws NotFoundException No such container | ||
| */ | ||
| @Override | ||
| public InputStream exec() throws NotFoundException { | ||
| return super.exec(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not critical, but for simplification there are API versions for linking javadocs. Example
docker-java/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java
Line 234 in 58d9407
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try change link to version here also