Search in sources :

Example 21 with ImageName

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)));
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) UrlBuilder(io.fabric8.maven.docker.access.UrlBuilder) Test(org.junit.Test)

Example 22 with ImageName

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")));
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) UrlBuilder(io.fabric8.maven.docker.access.UrlBuilder) Test(org.junit.Test)

Example 23 with ImageName

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();
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) QueryService(io.fabric8.maven.docker.service.QueryService) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 24 with ImageName

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 25 with ImageName

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());
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Aggregations

ImageName (io.fabric8.maven.docker.util.ImageName)13 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 Test (org.junit.Test)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)4 File (java.io.File)4 DockerClient (io.fabric8.docker.client.DockerClient)3 Container (io.fabric8.kubernetes.api.model.Container)3 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)3 UrlBuilder (io.fabric8.maven.docker.access.UrlBuilder)3 IOException (java.io.IOException)3 Controller (io.fabric8.kubernetes.api.Controller)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2