use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.
the class UrlBuilderTest method tagContainer.
@Test
public void tagContainer() throws URISyntaxException {
UrlBuilder builder = new UrlBuilder("", "1.0");
assertEquals(new URI("/1.0/images/t1%3Alatest/tag?force=1&repo=new&tag=tag1"), new URI(builder.tagContainer(new ImageName("t1:latest"), new ImageName("new:tag1"), true)));
}
use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.
the class UrlBuilderTest method pullImage.
@Test
public void pullImage() throws URISyntaxException {
UrlBuilder builder = new UrlBuilder("", "1.0");
assertEquals(new URI("/1.0/images/create?fromImage=reg%2Ft1&tag=latest"), new URI(builder.pullImage(new ImageName("t1:latest"), "reg")));
assertEquals(new URI("/1.0/images/create?fromImage=reg%2Ft1&tag=latest"), new URI(builder.pullImage(new ImageName("t1"), "reg")));
}
use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.
the class LogsMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException {
QueryService queryService = hub.getQueryService();
LogDispatcher logDispatcher = getLogDispatcher(hub);
for (ImageConfiguration image : getResolvedImages()) {
String imageName = image.getName();
if (logAll) {
for (Container container : queryService.getContainersForImage(imageName)) {
doLogging(logDispatcher, image, container.getId());
}
} else {
Container container = queryService.getLatestContainerForImage(imageName);
if (container != null) {
doLogging(logDispatcher, image, container.getId());
}
}
}
if (follow) {
// Block forever ....
waitForEver();
}
}
use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class ImageStreamService method appendImageStreamResource.
/**
* Save the images stream to a file
* @param imageName name of the image for which the stream should be extracted
* @param target file to store the image stream
*/
public void appendImageStreamResource(ImageName imageName, File target) throws MojoExecutionException {
String tag = Strings.isNullOrBlank(imageName.getTag()) ? "latest" : imageName.getTag();
try {
ImageStream is = new ImageStreamBuilder().withNewMetadata().withName(imageName.getSimpleName()).endMetadata().withNewSpec().addNewTag().withName(tag).withNewFrom().withKind("ImageStreamImage").endFrom().endTag().endSpec().build();
createOrUpdateImageStreamTag(client, imageName, is);
File fullTargetFile = appendImageStreamToFile(is, target);
log.info("ImageStream %s written to %s", imageName.getSimpleName(), fullTargetFile);
} catch (KubernetesClientException e) {
KubernetesResourceUtil.handleKubernetesClientException(e, this.log);
} catch (IOException e) {
throw new MojoExecutionException(String.format("Cannot write ImageStream descriptor for %s to %s : %s", imageName.getFullName(), target.getAbsoluteFile(), e.getMessage()), e);
}
}
use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class ImageStreamServiceTest method simple.
@Test
public void simple() throws IOException, MojoExecutionException {
ImageStreamService service = new ImageStreamService(client, log);
final ImageStream lookedUpIs = lookupImageStream("ab12cd");
setupClientMock(lookedUpIs, "test");
ImageName name = new ImageName("test:1.0");
File target = File.createTempFile("ImageStreamServiceTest", ".yml");
service.appendImageStreamResource(name, target);
assertTrue(target.exists());
Map result = readImageStreamDescriptor(target);
Yaml yaml;
System.out.println(result.toString());
assertNotNull(result);
List<Map> items = getItemsList(result);
assertEquals(1, items.size());
Map isRead = (Map<String, Object>) items.get(0);
assertNotNull(isRead);
assertEquals("ImageStream", isRead.get("kind"));
Map spec = (Map<String, Object>) isRead.get("spec");
assertNotNull(spec);
List tags = (List) spec.get("tags");
assertNotNull(tags);
assertEquals(1, tags.size());
Map tag = (Map) tags.get(0);
Map from = (Map) tag.get("from");
assertEquals("ImageStreamImage", from.get("kind"));
assertEquals("test@ab12cd", from.get("name"));
assertEquals("default", from.get("namespace"));
// Add a second image stream
ImageStream secondIs = lookupImageStream("secondIS");
setupClientMock(secondIs, "second-test");
ImageName name2 = new ImageName("second-test:1.0");
service.appendImageStreamResource(name2, target);
result = readImageStreamDescriptor(target);
System.out.println(result.toString());
items = getItemsList(result);
assertEquals(2, items.size());
Set<String> names = new HashSet<>(Arrays.asList("second-test", "test"));
for (Map item : items) {
assertTrue(names.remove(((Map) item.get("metadata")).get("name")));
}
assertTrue(names.isEmpty());
}
Aggregations