mirror of https://github.com/apache/jclouds.git
[JCLOUDS-1017] add tagImage() method to ImageApi
This commit is contained in:
parent
9271c11b67
commit
3342e88f80
|
@ -26,6 +26,7 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
|
||||
|
@ -102,4 +103,21 @@ public interface ImageApi {
|
|||
@Path("/images/{name}")
|
||||
InputStream deleteImage(@PathParam("name") String name, DeleteImageOptions options);
|
||||
|
||||
/**
|
||||
* Tag the image name into a repository.
|
||||
*
|
||||
* @param name
|
||||
* the name of the image to be tagged
|
||||
* @param repoName
|
||||
* the repository to tag in
|
||||
* @param tag
|
||||
* the new tag name
|
||||
* @param force
|
||||
* force create if tag already exists
|
||||
*/
|
||||
@Named("image:tag")
|
||||
@POST
|
||||
@Path("/images/{name}/tag")
|
||||
void tagImage(@PathParam("name") String name, @QueryParam("repo") String repoName,
|
||||
@QueryParam("tag") String tag, @QueryParam("force") boolean force);
|
||||
}
|
||||
|
|
|
@ -16,20 +16,30 @@
|
|||
*/
|
||||
package org.jclouds.docker.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.docker.compute.BaseDockerApiLiveTest;
|
||||
import org.jclouds.docker.domain.Image;
|
||||
import org.jclouds.docker.domain.ImageSummary;
|
||||
import org.jclouds.docker.options.CreateImageOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "live", testName = "RemoteApiLiveTest", singleThreaded = true)
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Test(groups = "live", testName = "ImageApiLiveTest", singleThreaded = true)
|
||||
public class ImageApiLiveTest extends BaseDockerApiLiveTest {
|
||||
|
||||
private static final String DEFAULT_IMAGE = "busybox";
|
||||
private static final String DEFAULT_TAG = "ubuntu-14.04";
|
||||
|
||||
private Image image;
|
||||
|
||||
@Test
|
||||
public void testCreateImage() {
|
||||
InputStream createImageStream = api().createImage(CreateImageOptions.Builder.fromImage(DEFAULT_IMAGE).tag(DEFAULT_TAG));
|
||||
|
@ -38,18 +48,38 @@ public class ImageApiLiveTest extends BaseDockerApiLiveTest {
|
|||
|
||||
@Test(dependsOnMethods = "testCreateImage")
|
||||
public void testInspectImage() {
|
||||
assertNotNull(api.getImageApi().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG)));
|
||||
image = api.getImageApi().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG));
|
||||
assertNotNull(image);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testInspectImage")
|
||||
public void testListImages() {
|
||||
assertNotNull(api().listImages());
|
||||
public void testTagImage() {
|
||||
api.getImageApi().tagImage(image.id(), "jclouds", "testTag", true);
|
||||
Image taggedImage = api.getImageApi().inspectImage("jclouds:testTag");
|
||||
assertEquals(taggedImage.id(), image.id(), "Newly added image tag should point to the same image ID.");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testListImages")
|
||||
@Test(dependsOnMethods = "testTagImage")
|
||||
public void testListImages() {
|
||||
List<ImageSummary> listImages = api().listImages();
|
||||
assertNotNull(listImages);
|
||||
|
||||
Iterables.find(listImages, new Predicate<ImageSummary>() {
|
||||
@Override
|
||||
public boolean apply(ImageSummary input) {
|
||||
return input.repoTags().contains("jclouds:testTag");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testListImages", alwaysRun = true)
|
||||
public void testDeleteImage() {
|
||||
consumeStream(api().deleteImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG)));
|
||||
assertNull(api().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG)));
|
||||
|
||||
assertNotNull(api().inspectImage(image.id()), "Image should should still exist after removing original tag. There is a newly added tag referencing it.");
|
||||
consumeStream(api().deleteImage("jclouds:testTag"));
|
||||
assertNull(api().inspectImage("jclouds:testTag"));
|
||||
}
|
||||
|
||||
private ImageApi api() {
|
||||
|
|
|
@ -69,6 +69,18 @@ public class ImageApiMockTest extends BaseDockerMockTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testTagImage() throws Exception {
|
||||
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201));
|
||||
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
|
||||
try {
|
||||
api.tagImage("633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6", "jclouds", "testTag", true);
|
||||
assertSent(server, "POST",
|
||||
"/images/633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6/tag?repo=jclouds&tag=testTag&force=true");
|
||||
} finally {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteImage() throws Exception {
|
||||
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204));
|
||||
ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi();
|
||||
|
|
|
@ -39,30 +39,30 @@ public class ImagesParseTest extends BaseDockerParseTest<List<ImageSummary>> {
|
|||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public List<ImageSummary> expected() {
|
||||
return ImmutableList.of(
|
||||
ImageSummary.create("cbba6639a342646deed70d7ea6162fa2a0acea9300f911f4e014555fe37d3456",
|
||||
1416827360,
|
||||
"05794515afd5724df1cdf0e674ae932455fce7dea3c70a94d77119ad1fa954ba",
|
||||
0,
|
||||
808709069,
|
||||
ImmutableList.of("test:latest")),
|
||||
ImageSummary.create("e1e548b03259ae30ba12232b6c16ef5205cf71b0363848e78b0394e1ecba4f57",
|
||||
1416826851,
|
||||
"6f36bec79c7f184ceebf7000cfb7244c4bc9b397b6659ac7f420a53d114250d9",
|
||||
0,
|
||||
5609404,
|
||||
ImmutableList.of("<none>:<none>")),
|
||||
ImageSummary.create("8201388d2b288539aab6aabf5d3b15ec269eba95c6baa9d6771f16540abf3a3f",
|
||||
1414247273,
|
||||
"4671e2c549c5b60063e349f520c801dc73b53d2226a5a8e5501845ebe94761ca",
|
||||
0,
|
||||
755313702,
|
||||
ImmutableList.of("dockerfile/java:openjdk-7-jdk")),
|
||||
ImageSummary.create("5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5",
|
||||
1414108439,
|
||||
"22093c35d77bb609b9257ffb2640845ec05018e3d96cb939f68d0e19127f1723",
|
||||
0,
|
||||
199257566,
|
||||
ImmutableList.of("ubuntu:14.04"))
|
||||
ImageSummary.create("d7057cb020844f245031d27b76cb18af05db1cc3a96a29fa7777af75f5ac91a3",
|
||||
1442866547,
|
||||
"cfa753dfea5e68a24366dfba16e6edf573daa447abf65bc11619c1a98a3aff54",
|
||||
0,
|
||||
1095501,
|
||||
ImmutableList.of("docker.io/busybox:1.23.2", "docker.io/busybox:latest")),
|
||||
ImageSummary.create("633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6",
|
||||
1442598293,
|
||||
"b65c936b5fb601d680ed656b1ccf8ab857c0e5cb521043a005405c194e9a69f3",
|
||||
0,
|
||||
5607885,
|
||||
ImmutableList.of("docker.io/busybox:ubuntu-14.04", "jclouds:testTag")),
|
||||
ImageSummary.create("f4fddc471ec22fc1f7d37768132f1753bc171121e30ac2af7fcb0302588197c0",
|
||||
1442260874,
|
||||
"",
|
||||
5244426,
|
||||
5244426,
|
||||
ImmutableList.of("docker.io/alpine:3.2")),
|
||||
ImageSummary.create("91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c",
|
||||
1440102075,
|
||||
"d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82",
|
||||
0,
|
||||
188333286,
|
||||
ImmutableList.of("docker.io/ubuntu:14.04", "docker.io/ubuntu:latest"))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +1,53 @@
|
|||
[
|
||||
{
|
||||
"Created": 1416827360,
|
||||
"Id": "cbba6639a342646deed70d7ea6162fa2a0acea9300f911f4e014555fe37d3456",
|
||||
"ParentId": "05794515afd5724df1cdf0e674ae932455fce7dea3c70a94d77119ad1fa954ba",
|
||||
"RepoTags": [
|
||||
"test:latest"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 808709069
|
||||
},
|
||||
{
|
||||
"Created": 1416826851,
|
||||
"Id": "e1e548b03259ae30ba12232b6c16ef5205cf71b0363848e78b0394e1ecba4f57",
|
||||
"ParentId": "6f36bec79c7f184ceebf7000cfb7244c4bc9b397b6659ac7f420a53d114250d9",
|
||||
"RepoTags": [
|
||||
"<none>:<none>"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 5609404
|
||||
},
|
||||
{
|
||||
"Created": 1414247273,
|
||||
"Id": "8201388d2b288539aab6aabf5d3b15ec269eba95c6baa9d6771f16540abf3a3f",
|
||||
"ParentId": "4671e2c549c5b60063e349f520c801dc73b53d2226a5a8e5501845ebe94761ca",
|
||||
"RepoTags": [
|
||||
"dockerfile/java:openjdk-7-jdk"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 755313702
|
||||
},
|
||||
{
|
||||
"Created": 1414108439,
|
||||
"Id": "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5",
|
||||
"ParentId": "22093c35d77bb609b9257ffb2640845ec05018e3d96cb939f68d0e19127f1723",
|
||||
"RepoTags": [
|
||||
"ubuntu:14.04"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 199257566
|
||||
}
|
||||
{
|
||||
"Created": 1442866547,
|
||||
"Id": "d7057cb020844f245031d27b76cb18af05db1cc3a96a29fa7777af75f5ac91a3",
|
||||
"Labels": null,
|
||||
"ParentId": "cfa753dfea5e68a24366dfba16e6edf573daa447abf65bc11619c1a98a3aff54",
|
||||
"RepoDigests": [],
|
||||
"RepoTags": [
|
||||
"docker.io/busybox:1.23.2",
|
||||
"docker.io/busybox:latest"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 1095501
|
||||
},
|
||||
{
|
||||
"Created": 1442598293,
|
||||
"Id": "633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6",
|
||||
"Labels": null,
|
||||
"ParentId": "b65c936b5fb601d680ed656b1ccf8ab857c0e5cb521043a005405c194e9a69f3",
|
||||
"RepoDigests": [],
|
||||
"RepoTags": [
|
||||
"docker.io/busybox:ubuntu-14.04",
|
||||
"jclouds:testTag"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 5607885
|
||||
},
|
||||
{
|
||||
"Created": 1442260874,
|
||||
"Id": "f4fddc471ec22fc1f7d37768132f1753bc171121e30ac2af7fcb0302588197c0",
|
||||
"Labels": null,
|
||||
"ParentId": "",
|
||||
"RepoDigests": [],
|
||||
"RepoTags": [
|
||||
"docker.io/alpine:3.2"
|
||||
],
|
||||
"Size": 5244426,
|
||||
"VirtualSize": 5244426
|
||||
},
|
||||
{
|
||||
"Created": 1440102075,
|
||||
"Id": "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c",
|
||||
"Labels": {},
|
||||
"ParentId": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82",
|
||||
"RepoDigests": [],
|
||||
"RepoTags": [
|
||||
"docker.io/ubuntu:14.04",
|
||||
"docker.io/ubuntu:latest"
|
||||
],
|
||||
"Size": 0,
|
||||
"VirtualSize": 188333286
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue