Skip to content

Commit abff5cc

Browse files
author
Marcus Linke
committed
Merge branch 'master' of https://github.com/vuminhkh/docker-java into
vuminhkh-master Conflicts: src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java src/test/java/com/github/dockerjava/client/AbstractDockerClientTest.java
2 parents c1af594 + 477f4a1 commit abff5cc

27 files changed

+848
-70
lines changed

src/main/java/com/github/dockerjava/api/DockerClient.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.github.dockerjava.api.command.BuildImageCmd;
1313
import com.github.dockerjava.api.command.CommitCmd;
1414
import com.github.dockerjava.api.command.ContainerDiffCmd;
15+
import com.github.dockerjava.api.command.CopyArchiveFromContainerCmd;
16+
import com.github.dockerjava.api.command.CopyArchiveToContainerCmd;
1517
import com.github.dockerjava.api.command.CopyFileFromContainerCmd;
1618
import com.github.dockerjava.api.command.CreateContainerCmd;
1719
import com.github.dockerjava.api.command.CreateImageCmd;
@@ -46,6 +48,7 @@
4648
import com.github.dockerjava.api.exception.DockerException;
4749
import com.github.dockerjava.api.model.AuthConfig;
4850
import com.github.dockerjava.api.model.Identifier;
51+
import com.github.dockerjava.core.RemoteApiVersion;
4952

5053
// https://godoc.org/github.com/fsouza/go-dockerclient
5154
public interface DockerClient extends Closeable {
@@ -121,8 +124,42 @@ public interface DockerClient extends Closeable {
121124

122125
public LogContainerCmd logContainerCmd(@Nonnull String containerId);
123126

127+
/**
128+
* Copy resource from container to local machine.
129+
*
130+
* @param containerId
131+
* id of the container
132+
* @param resource
133+
* path to container's resource
134+
* @return created command
135+
* @since {@link RemoteApiVersion#VERSION_1_20}
136+
*/
137+
public CopyArchiveFromContainerCmd copyArchiveFromContainerCmd(@Nonnull String containerId, @Nonnull String resource);
138+
139+
/**
140+
* Copy resource from container to local machine.
141+
*
142+
* @param containerId
143+
* id of the container
144+
* @param resource
145+
* path to container's resource
146+
* @return created command
147+
* @see #copyArchiveFromContainerCmd(String, String)
148+
* @deprecated since docker API version 1.20, replaced by {@link #copyArchiveFromContainerCmd(String, String)}
149+
*/
150+
@Deprecated
124151
public CopyFileFromContainerCmd copyFileFromContainerCmd(@Nonnull String containerId, @Nonnull String resource);
125152

153+
/**
154+
* Copy archive from local machine to remote container
155+
*
156+
* @param containerId
157+
* id of the container
158+
* @return created command
159+
* @since {@link RemoteApiVersion#VERSION_1_20}
160+
*/
161+
public CopyArchiveToContainerCmd copyArchiveToContainerCmd(@Nonnull String containerId);
162+
126163
public ContainerDiffCmd containerDiffCmd(@Nonnull String containerId);
127164

128165
public StopContainerCmd stopContainerCmd(@Nonnull String containerId);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import java.io.InputStream;
4+
5+
import javax.annotation.CheckForNull;
6+
import javax.annotation.Nonnull;
7+
8+
import com.github.dockerjava.api.exception.NotFoundException;
9+
10+
public interface CopyArchiveFromContainerCmd extends SyncDockerCmd<InputStream> {
11+
12+
@CheckForNull
13+
public String getContainerId();
14+
15+
@CheckForNull
16+
public String getHostPath();
17+
18+
@CheckForNull
19+
public String getResource();
20+
21+
public CopyArchiveFromContainerCmd withContainerId(@Nonnull String containerId);
22+
23+
public CopyArchiveFromContainerCmd withHostPath(String hostPath);
24+
25+
public CopyArchiveFromContainerCmd withResource(@Nonnull String resource);
26+
27+
/**
28+
* Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks.
29+
*
30+
* @throws NotFoundException
31+
* No such container
32+
*/
33+
@Override
34+
public InputStream exec() throws NotFoundException;
35+
36+
public static interface Exec extends DockerCmdSyncExec<CopyArchiveFromContainerCmd, InputStream> {
37+
}
38+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import java.io.InputStream;
4+
5+
import com.github.dockerjava.api.exception.NotFoundException;
6+
7+
public interface CopyArchiveToContainerCmd extends SyncDockerCmd<Void> {
8+
9+
String getContainerId();
10+
11+
String getHostResource();
12+
13+
InputStream getTarInputStream();
14+
15+
boolean isNoOverwriteDirNonDir();
16+
17+
boolean isDirChildrenOnly();
18+
19+
/**
20+
* Set container's id
21+
*
22+
* @param containerId
23+
* id of the container to copy file to
24+
*/
25+
CopyArchiveToContainerCmd withContainerId(String containerId);
26+
27+
/**
28+
* Set path to the resource on the host machine
29+
*
30+
* @param resource
31+
* path to the resource on the host machine
32+
*/
33+
CopyArchiveToContainerCmd withHostResource(String resource);
34+
35+
/**
36+
* Set the tar input stream that will be uploaded to the container. withHostResource or withTarInputStream can be
37+
* defined but not both.
38+
*
39+
* @param tarInputStream
40+
* the stream to upload to the container
41+
*/
42+
CopyArchiveToContainerCmd withTarInputStream(InputStream tarInputStream);
43+
44+
/**
45+
* If set to true then it will be an error if unpacking the given content would cause an existing directory to be
46+
* replaced with a non-directory and vice versa
47+
*
48+
* @param noOverwriteDirNonDir
49+
* flag to know if non directory can be overwritten
50+
*/
51+
CopyArchiveToContainerCmd withNoOverwriteDirNonDir(boolean noOverwriteDirNonDir);
52+
53+
/**
54+
* If this flag is set to true, all children of the local directory will be copied to the remote without the root
55+
* directory. For ex: if I have root/titi and root/tata and the remote path is /var/data. dirChildrenOnly = true
56+
* will create /var/data/titi and /var/data/tata dirChildrenOnly = false will create /var/data/root/titi and
57+
* /var/data/root/tata
58+
*
59+
* @param dirChildrenOnly
60+
* if root directory is ignored
61+
*/
62+
CopyArchiveToContainerCmd withDirChildrenOnly(boolean dirChildrenOnly);
63+
64+
String getRemotePath();
65+
66+
CopyArchiveToContainerCmd withRemotePath(String remotePath);
67+
68+
@Override
69+
Void exec() throws NotFoundException;
70+
71+
interface Exec extends DockerCmdSyncExec<CopyArchiveToContainerCmd, Void> {
72+
}
73+
74+
}

src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public interface DockerCmdExecFactory extends Closeable {
5757

5858
public CopyFileFromContainerCmd.Exec createCopyFileFromContainerCmdExec();
5959

60+
public CopyArchiveFromContainerCmd.Exec createCopyArchiveFromContainerCmdExec();
61+
62+
public CopyArchiveToContainerCmd.Exec createCopyArchiveToContainerCmdExec();
63+
6064
public StopContainerCmd.Exec createStopContainerCmdExec();
6165

6266
public ContainerDiffCmd.Exec createContainerDiffCmdExec();
@@ -83,5 +87,4 @@ public interface DockerCmdExecFactory extends Closeable {
8387

8488
@Override
8589
public void close() throws IOException;
86-
8790
}

src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ public VolumeBind[] getVolumes() {
140140
}
141141

142142
/**
143-
* @deprecated As of {@link RemoteApiVersion#VERSION_1_20}
144-
* use {@link #getMounts()} instead
143+
* @deprecated As of {@link RemoteApiVersion#VERSION_1_20} use {@link #getMounts()} instead
145144
*/
146145
@JsonIgnore
147146
@Deprecated
@@ -286,6 +285,7 @@ public class ContainerState {
286285

287286
/**
288287
* <a href="https://github.com/docker/docker/pull/18127">Unclear</a>
288+
*
289289
* @since {@link RemoteApiVersion#UNKNOWN_VERSION}
290290
*/
291291
@CheckForNull
@@ -327,7 +327,6 @@ public class ContainerState {
327327
@JsonProperty("FinishedAt")
328328
private String finishedAt;
329329

330-
331330
/**
332331
* See {@link #status}
333332
*/

src/main/java/com/github/dockerjava/api/model/PullResponseItem.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
public class PullResponseItem extends ResponseItem {
1111

1212
private static final long serialVersionUID = -2575482839766823293L;
13+
1314
private static final String LEGACY_REGISTRY = "this image was pulled from a legacy registry";
15+
1416
private static final String DOWNLOADED_NEWER_IMAGE = "Downloaded newer image";
17+
1518
private static final String IMAGE_UP_TO_DATE = "Image is up to date";
19+
1620
private static final String DOWNLOAD_COMPLETE = "Download complete";
1721

1822
/**
@@ -27,8 +31,7 @@ public boolean isPullSuccessIndicated() {
2731
}
2832

2933
return (getStatus().contains(DOWNLOAD_COMPLETE) || getStatus().contains(IMAGE_UP_TO_DATE)
30-
|| getStatus().contains(DOWNLOADED_NEWER_IMAGE)
31-
|| getStatus().contains(LEGACY_REGISTRY));
34+
|| getStatus().contains(DOWNLOADED_NEWER_IMAGE) || getStatus().contains(LEGACY_REGISTRY));
3235
}
3336

3437
}

src/main/java/com/github/dockerjava/core/DockerClientImpl.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package com.github.dockerjava.core;
22

3+
import static com.google.common.base.Preconditions.checkNotNull;
4+
5+
import java.io.Closeable;
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
310
import com.github.dockerjava.api.DockerClient;
411
import com.github.dockerjava.api.command.AttachContainerCmd;
512
import com.github.dockerjava.api.command.AuthCmd;
613
import com.github.dockerjava.api.command.BuildImageCmd;
714
import com.github.dockerjava.api.command.CommitCmd;
815
import com.github.dockerjava.api.command.ContainerDiffCmd;
16+
import com.github.dockerjava.api.command.CopyArchiveFromContainerCmd;
917
import com.github.dockerjava.api.command.CopyFileFromContainerCmd;
1018
import com.github.dockerjava.api.command.CreateContainerCmd;
1119
import com.github.dockerjava.api.command.CreateImageCmd;
@@ -45,6 +53,9 @@
4553
import com.github.dockerjava.core.command.BuildImageCmdImpl;
4654
import com.github.dockerjava.core.command.CommitCmdImpl;
4755
import com.github.dockerjava.core.command.ContainerDiffCmdImpl;
56+
import com.github.dockerjava.core.command.CopyArchiveFromContainerCmdImpl;
57+
import com.github.dockerjava.api.command.CopyArchiveToContainerCmd;
58+
import com.github.dockerjava.core.command.CopyArchiveToContainerCmdImpl;
4859
import com.github.dockerjava.core.command.CopyFileFromContainerCmdImpl;
4960
import com.github.dockerjava.core.command.CreateContainerCmdImpl;
5061
import com.github.dockerjava.core.command.CreateImageCmdImpl;
@@ -77,16 +88,8 @@
7788
import com.github.dockerjava.core.command.VersionCmdImpl;
7889
import com.github.dockerjava.core.command.WaitContainerCmdImpl;
7990

80-
import java.io.Closeable;
81-
import java.io.File;
82-
import java.io.IOException;
83-
import java.io.InputStream;
84-
85-
import static com.google.common.base.Preconditions.checkNotNull;
86-
8791
/**
8892
* @author Konstantin Pelykh (kpelykh@gmail.com)
89-
*
9093
* @see "https://github.com/docker/docker/blob/master/api/client/commands.go"
9194
*/
9295
public class DockerClientImpl implements Closeable, DockerClient {
@@ -304,6 +307,18 @@ public CopyFileFromContainerCmd copyFileFromContainerCmd(String containerId, Str
304307
containerId, resource);
305308
}
306309

310+
@Override
311+
public CopyArchiveFromContainerCmd copyArchiveFromContainerCmd(String containerId, String resource) {
312+
return new CopyArchiveFromContainerCmdImpl(getDockerCmdExecFactory().createCopyArchiveFromContainerCmdExec(),
313+
containerId, resource);
314+
}
315+
316+
@Override
317+
public CopyArchiveToContainerCmd copyArchiveToContainerCmd(String containerId) {
318+
return new CopyArchiveToContainerCmdImpl(getDockerCmdExecFactory().createCopyArchiveToContainerCmdExec(),
319+
containerId);
320+
}
321+
307322
@Override
308323
public ContainerDiffCmd containerDiffCmd(String containerId) {
309324
return new ContainerDiffCmdImpl(getDockerCmdExecFactory().createContainerDiffCmdExec(), containerId);

src/main/java/com/github/dockerjava/core/RemoteApiVersion.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import java.util.regex.Pattern;
1111

1212
/**
13-
* Bean to encapsulate the version of the
14-
* <a href="http://docs.docker.com/engine/reference/api/docker_remote_api/">Docker Remote (REST) API</a>
13+
* Bean to encapsulate the version of the <a
14+
* href="http://docs.docker.com/engine/reference/api/docker_remote_api/">Docker Remote (REST) API</a>
1515
* <p>
1616
* Contains the minor and major version of the API as well as operations to compare API versions.
1717
*
@@ -47,21 +47,20 @@ public class RemoteApiVersion implements Serializable {
4747
*/
4848
public static final RemoteApiVersion VERSION_1_20 = RemoteApiVersion.create(1, 20);
4949

50-
5150
/**
5251
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/">Docker API 1.21</a>
5352
*/
5453
public static final RemoteApiVersion VERSION_1_21 = RemoteApiVersion.create(1, 21);
5554

5655
/**
57-
* @see <a href="https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.22.md">Docker API 1.22</a>
56+
* @see <a href="https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.22.md">Docker
57+
* API 1.22</a>
5858
*/
5959
public static final RemoteApiVersion VERSION_1_22 = RemoteApiVersion.create(1, 22);
6060

61-
6261
/**
63-
* Unknown, docker doesn't reflect reality.
64-
* I.e. we implemented method, but for javadoc it not clear when it was added.
62+
* Unknown, docker doesn't reflect reality. I.e. we implemented method, but for javadoc it not clear when it was
63+
* added.
6564
*/
6665
private static final RemoteApiVersion UNKNOWN_VERSION = new RemoteApiVersion(0, 0) {
6766

0 commit comments

Comments
 (0)