Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Commit daf922b

Browse files
author
Marcus Linke
committed
basic remote api v1.13 compatibility
1 parent 369cb01 commit daf922b

18 files changed

Lines changed: 475 additions & 354 deletions

src/main/java/com/github/dockerjava/client/command/BuildImgCmd.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
/**
3232
*
3333
* Build an image from Dockerfile.
34+
*
35+
* TODO: http://docs.docker.com/reference/builder/#dockerignore
3436
*
3537
*/
3638
public class BuildImgCmd extends AbstrDockerCmd<BuildImgCmd, ClientResponse> {
@@ -63,6 +65,10 @@ public BuildImgCmd withTag(String tag) {
6365
return this;
6466
}
6567

68+
public BuildImgCmd withNoCache() {
69+
return withNoCache(true);
70+
}
71+
6672
public BuildImgCmd withNoCache(boolean noCache) {
6773
this.noCache = noCache;
6874
return this;
@@ -170,7 +176,7 @@ protected File buildDockerFolderTar() {
170176

171177
String extractedResource = matcher.group(2);
172178

173-
String resource = filterForEnvironmentVars(extractedResource, environmentMap);
179+
String resource = filterForEnvironmentVars(extractedResource, environmentMap).trim();
174180

175181
if(isFileResource(resource)) {
176182
File src = new File(resource);

src/main/java/com/github/dockerjava/client/command/CommitCmd.java

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ public class CommitCmd extends AbstrDockerCmd<CommitCmd, String> {
2424

2525
private static final Logger LOGGER = LoggerFactory.getLogger(CommitCmd.class);
2626

27-
private CommitConfig commitConfig;
27+
private String containerId, repository, tag, message, author;
28+
29+
private boolean pause = true;
30+
31+
private CommitConfig commitConfig = new CommitConfig();
2832

2933
public CommitCmd(String containerId) {
3034
Preconditions.checkNotNull(containerId, "containerId was not specified");
31-
this.commitConfig = new CommitConfig(containerId);
35+
this.containerId = containerId;
3236
}
3337

3438
public CommitCmd withCommitConfig(CommitConfig commitConfig) {
@@ -37,44 +41,81 @@ public CommitCmd withCommitConfig(CommitConfig commitConfig) {
3741
return this;
3842
}
3943

40-
public CommitCmd withRepo(String repo) {
41-
Preconditions.checkNotNull(repo, "repo was not specified");
42-
this.commitConfig.setRepo(repo);
44+
public CommitCmd withAttachStderr(boolean attachStderr) {
45+
this.commitConfig.setAttachStderr(attachStderr);
4346
return this;
4447
}
4548

46-
public CommitCmd withTag(String tag) {
47-
Preconditions.checkNotNull(tag, "tag was not specified");
48-
this.commitConfig.setTag(tag);
49+
public CommitCmd withAttachStderr() {
50+
return withAttachStderr(true);
51+
}
52+
53+
public CommitCmd withAttachStdin(boolean attachStdin) {
54+
this.commitConfig.setAttachStdin(attachStdin);
4955
return this;
5056
}
57+
58+
public CommitCmd withAttachStdin() {
59+
return withAttachStdin(true);
60+
}
5161

52-
public CommitCmd withMessage(String message) {
53-
Preconditions.checkNotNull(message, "message was not specified");
54-
this.commitConfig.setMessage(message);
62+
public CommitCmd withAttachStdout(boolean attachStdout) {
63+
this.commitConfig.setAttachStdout(attachStdout);
64+
return this;
65+
}
66+
67+
public CommitCmd withAttachStdout() {
68+
return withAttachStdout(true);
69+
}
70+
71+
public CommitCmd withCmd(String... cmd) {
72+
Preconditions.checkNotNull(cmd, "cmd was not specified");
73+
this.commitConfig.setCmd(cmd);
74+
return this;
75+
}
76+
77+
public CommitCmd withDisableNetwork(boolean disableNetwork) {
78+
this.commitConfig.setDisableNetwork(disableNetwork);
5579
return this;
5680
}
5781

5882
public CommitCmd withAuthor(String author) {
5983
Preconditions.checkNotNull(author, "author was not specified");
60-
this.commitConfig.setAuthor(author);
84+
this.author = author;
85+
return this;
86+
}
87+
88+
public CommitCmd withMessage(String message) {
89+
Preconditions.checkNotNull(message, "message was not specified");
90+
this.message = message;
91+
return this;
92+
}
93+
94+
public CommitCmd withTag(String tag) {
95+
Preconditions.checkNotNull(tag, "tag was not specified");
96+
this.tag = tag;
97+
return this;
98+
}
99+
100+
public CommitCmd withRepository(String repository) {
101+
Preconditions.checkNotNull(repository, "repository was not specified");
102+
this.repository = repository;
61103
return this;
62104
}
63105

64-
public CommitCmd withRun(String run) {
65-
Preconditions.checkNotNull(run, "run was not specified");
66-
this.commitConfig.setRun(run);
106+
public CommitCmd withPause(boolean pause) {
107+
this.pause = pause;
67108
return this;
68109
}
69110

70111
@Override
71112
public String toString() {
72113
return new StringBuilder("commit ")
73-
.append(commitConfig.getAuthor() != null ? "--author " + commitConfig.getAuthor() + " " : "")
74-
.append(commitConfig.getMessage() != null ? "--message " + commitConfig.getMessage() + " " : "")
75-
.append(commitConfig.getContainerId())
76-
.append(commitConfig.getRepo() != null ? " " + commitConfig.getRepo() + ":" : " ")
77-
.append(commitConfig.getTag() != null ? commitConfig.getTag() : "")
114+
.append(author != null ? "--author " + author + " " : "")
115+
.append(message != null ? "--message " + message + " " : "")
116+
.append(containerId)
117+
.append(repository != null ? " " + repository + ":" : " ")
118+
.append(tag != null ? tag : "")
78119
.toString();
79120
}
80121

@@ -86,12 +127,12 @@ protected String impl() throws DockerException {
86127
checkCommitConfig(commitConfig);
87128

88129
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
89-
params.add("container", commitConfig.getContainerId());
90-
params.add("repo", commitConfig.getRepo());
91-
params.add("tag", commitConfig.getTag());
92-
params.add("m", commitConfig.getMessage());
93-
params.add("author", commitConfig.getAuthor());
94-
params.add("run", commitConfig.getRun());
130+
params.add("container", containerId);
131+
params.add("repo", repository);
132+
params.add("tag", tag);
133+
params.add("m", message);
134+
params.add("author", author);
135+
params.add("pause", pause ? "1" : "0");
95136

96137
WebResource webResource = baseResource.path("/commit").queryParams(params);
97138

@@ -101,7 +142,7 @@ protected String impl() throws DockerException {
101142
return ObjectNode.get("Id").asText();
102143
} catch (UniformInterfaceException exception) {
103144
if (exception.getResponse().getStatus() == 404) {
104-
throw new NotFoundException(String.format("No such container %s", commitConfig.getContainerId()));
145+
throw new NotFoundException(String.format("No such container %s", containerId));
105146
} else if (exception.getResponse().getStatus() == 500) {
106147
throw new DockerException("Server error", exception);
107148
} else {

src/main/java/com/github/dockerjava/client/command/RemoveImageCmd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public RemoveImageCmd withImageId(String imageId) {
3333
return this;
3434
}
3535

36+
public RemoveImageCmd withForce() {
37+
return withForce(true);
38+
}
39+
3640
public RemoveImageCmd withForce(boolean force) {
3741
this.force = force;
3842
return this;

src/main/java/com/github/dockerjava/client/command/StartContainerCmd.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ protected Void impl() throws DockerException {
108108
} catch (UniformInterfaceException exception) {
109109
if (exception.getResponse().getStatus() == 404) {
110110
throw new NotFoundException(String.format("No such container %s", containerId));
111+
} else if(exception.getResponse().getStatus() == 304) {
112+
//no error
113+
LOGGER.warn("Container already started {}", containerId);
111114
} else if (exception.getResponse().getStatus() == 204) {
112115
//no error
113116
LOGGER.trace("Successfully started container {}", containerId);

src/main/java/com/github/dockerjava/client/command/StopContainerCmd.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ protected Void impl() throws DockerException {
5959
} catch (UniformInterfaceException exception) {
6060
if (exception.getResponse().getStatus() == 404) {
6161
LOGGER.warn("No such container {}", containerId);
62+
} else if(exception.getResponse().getStatus() == 304) {
63+
//no error
64+
LOGGER.warn("Container already stopped {}", containerId);
6265
} else if (exception.getResponse().getStatus() == 204) {
6366
//no error
6467
LOGGER.trace("Successfully stopped container {}", containerId);

0 commit comments

Comments
 (0)