Skip to content

Commit 8ce12d6

Browse files
committed
Merge pull request docker-java#2 from kpelykh/master
Merge
2 parents 620e456 + 8f49622 commit 8ce12d6

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ Developer forum for [docker-java](https://groups.google.com/forum/?hl=de#!forum/
1414
* Maven 3.0.5
1515
* Docker daemon running
1616

17-
Maven will run tests during build process. Tests are using localhost instance of Docker, make sure that
18-
you have Docker running for tests to work or just turn off tests.
19-
20-
If you don't have Docker running locally, you can skip tests with -DskipTests flag set to true:
21-
22-
$ mvn clean install -DskipTests=true
17+
Maven may run tests during build process but tests are disabled by default. The tests are using a localhost instance of Docker, make sure that you have Docker running for tests to work. To run the tests you have to provide your https://www.docker.io/account/login/ information:
2318

19+
$ mvn clean install -DskipTests=false -Ddocker.io.username=... -Ddocker.io.password=... -Ddocker.io.email=...
2420

2521
By default Docker server is using UNIX sockets for communication with the Docker client, however docker-java
2622
client uses TCP/IP to connect to the Docker server, so you will need to make sure that your Docker server is

src/main/java/com/kpelykh/docker/client/DockerClient.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ public Version version() throws DockerException {
190190
}
191191
}
192192
}
193+
194+
195+
public int ping() throws DockerException {
196+
WebResource webResource = client.resource(restEndpointUrl + "/_ping");
197+
198+
try {
199+
LOGGER.trace("GET: {}", webResource);
200+
ClientResponse resp = webResource.get(ClientResponse.class);
201+
return resp.getStatus();
202+
} catch (UniformInterfaceException exception) {
203+
throw new DockerException(exception);
204+
}
205+
}
193206

194207

195208
/**
@@ -280,6 +293,36 @@ private String name(String name) {
280293
return name.contains("/") ? name : authConfig.getUsername();
281294
}
282295

296+
/**
297+
* Tag an image into a repository
298+
*
299+
* @param image the local image to tag (either a name or an id)
300+
* @param repository the repository to tag in
301+
* @param tag any tag for this image
302+
* @param force (not documented)
303+
* @return the HTTP status code (201 for success)
304+
*/
305+
public int tag(String image, String repository, String tag, boolean force) throws DockerException {
306+
Preconditions.checkNotNull(image, "image was not specified");
307+
Preconditions.checkNotNull(repository, "repository was not specified");
308+
Preconditions.checkNotNull(tag, " tag was not provided");
309+
310+
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
311+
params.add("repo", repository);
312+
params.add("tag", tag);
313+
params.add("force", String.valueOf(force));
314+
315+
WebResource webResource = client.resource(restEndpointUrl + "/images/" + image + "/tag").queryParams(params);
316+
317+
try {
318+
LOGGER.trace("POST: {}", webResource);
319+
ClientResponse resp = webResource.post(ClientResponse.class);
320+
return resp.getStatus();
321+
} catch (UniformInterfaceException exception) {
322+
throw new DockerException(exception);
323+
}
324+
}
325+
283326
/**
284327
* Create an image by importing the given stream of a tar file.
285328
*

src/test/java/com/kpelykh/docker/client/test/DockerClientTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import java.net.DatagramSocket;
2626
import java.net.ServerSocket;
2727
import java.util.List;
28+
import java.util.Random;
2829

2930
import org.apache.commons.io.IOUtils;
3031
import org.apache.commons.io.LineIterator;
3132
import org.apache.commons.lang.StringUtils;
33+
import org.apache.commons.lang.math.RandomUtils;
3234
import org.hamcrest.Matcher;
3335
import org.slf4j.Logger;
3436
import org.slf4j.LoggerFactory;
@@ -569,6 +571,16 @@ public void testRemoveImage() throws DockerException, InterruptedException {
569571
assertThat(containers, matcher);
570572
}
571573

574+
@Test
575+
public void testTagImage() throws DockerException, InterruptedException {
576+
String tag = String.valueOf(RandomUtils.nextInt(Integer.MAX_VALUE));
577+
578+
Integer result = dockerClient.tag("busybox:latest", "docker-java/busybox", tag, false);
579+
assertThat(result, equalTo(Integer.valueOf(201)));
580+
581+
dockerClient.removeImage("docker-java/busybox:" + tag);
582+
}
583+
572584
/*
573585
*
574586
* ################ ## MISC TESTS ## ################

0 commit comments

Comments
 (0)