Search in sources :

Example 56 with Image

use of io.fabric8.docker.api.model.Image in project fabric8 by fabric8io.

the class SessionListener method hasRegistry.

/**
 * Checks to see if there's a registry name already provided in the image name
 *
 * Code influenced from <a href="https://github.com/rhuss/docker-maven-plugin/blob/master/src/main/java/org/jolokia/docker/maven/util/ImageName.java">docker-maven-plugin</a>
 * @param imageName
 * @return true if the image name contains a registry
 */
public static boolean hasRegistry(String imageName) {
    if (imageName == null) {
        throw new NullPointerException("Image name must not be null");
    }
    Pattern tagPattern = Pattern.compile("^(.+?)(?::([^:/]+))?$");
    Matcher matcher = tagPattern.matcher(imageName);
    if (!matcher.matches()) {
        throw new IllegalArgumentException(imageName + " is not a proper image name ([registry/][repo][:port]");
    }
    String rest = matcher.group(1);
    String[] parts = rest.split("\\s*/\\s*");
    String part = parts[0];
    return part.contains(".") || part.contains(":");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString)

Example 57 with Image

use of io.fabric8.docker.api.model.Image in project che by eclipse.

the class OpenShiftConnector method pull.

/**
     * Creates an ImageStream that tracks the repository.
     *
     * <p>Note: This method does not cause the relevant image to actually be pulled to the local
     * repository, but creating the ImageStream is necessary as it is used to obtain
     * the address of the internal Docker registry later.
     *
     * @see DockerConnector#pull(PullParams, ProgressMonitor)
     */
@Override
public void pull(final PullParams params, final ProgressMonitor progressMonitor) throws IOException {
    // image to be pulled
    String repo = params.getFullRepo();
    // e.g. latest, usually
    String tag = params.getTag();
    String imageStreamName = KubernetesStringUtils.convertPullSpecToImageStreamName(repo);
    ImageStream existingImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
    if (existingImageStream == null) {
        openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).createNew().withNewMetadata().withName(// imagestream id
        imageStreamName).endMetadata().withNewSpec().addNewTag().withName(tag).endTag().withDockerImageRepository(// tracking repo
        repo).endSpec().withNewStatus().withDockerImageRepository("").endStatus().done();
    }
    // Wait for Image metadata to be obtained.
    ImageStream createdImageStream;
    for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
        try {
            Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        createdImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
        if (createdImageStream != null && createdImageStream.getStatus().getDockerImageRepository() != null) {
            LOG.info(String.format("Created ImageStream %s.", imageStreamName));
            return;
        }
    }
    throw new OpenShiftException(String.format("Failed to create ImageStream %s.", imageStreamName));
}
Also used : OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException) ImageStream(io.fabric8.openshift.api.model.ImageStream)

Example 58 with Image

use of io.fabric8.docker.api.model.Image in project che by eclipse.

the class OpenShiftConnector method createImageStreamTag.

/**
     * Creates a new ImageStreamTag
     *
     * @param sourceImageWithTag the image that the ImageStreamTag will track
     * @param imageStreamTagName the name of the imageStream tag (e.g. {@code <ImageStream name>:<Tag name>})
     * @return the created ImageStreamTag
     * @throws IOException When {@code sourceImageWithTag} metadata cannot be found
     */
private ImageStreamTag createImageStreamTag(String sourceImageWithTag, String imageStreamTagName) throws IOException {
    try {
        openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).createOrReplaceWithNew().withNewMetadata().withName(imageStreamTagName).endMetadata().withNewTag().withNewFrom().withKind("DockerImage").withName(sourceImageWithTag).endFrom().endTag().done();
        // Wait for image metadata to be pulled
        for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
            Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
            ImageStreamTag createdTag = openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).withName(imageStreamTagName).get();
            if (createdTag != null) {
                LOG.info(String.format("Created ImageStreamTag %s in namespace %s", createdTag.getMetadata().getName(), openShiftCheProjectName));
                return createdTag;
            }
        }
        throw new ImageNotFoundException(String.format("Image %s not found.", sourceImageWithTag));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException(e.getLocalizedMessage(), e);
    }
}
Also used : ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) IOException(java.io.IOException) ImageNotFoundException(org.eclipse.che.plugin.docker.client.exception.ImageNotFoundException)

Example 59 with Image

use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testDockerFile.

@Test
public void testDockerFile() {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.DOCKER_FILE), "file" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    assertNotNull(config.getBuildConfiguration());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 60 with Image

use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testDockerArchive.

@Test
public void testDockerArchive() {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.DOCKER_ARCHIVE), "dockerLoad.tar", k(ConfigKey.FROM), "busybox" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    config.initAndValidate(ConfigHelper.NameFormatter.IDENTITY, null);
    assertFalse(config.getBuildConfiguration().isDockerFileMode());
    assertEquals(new File("dockerLoad.tar"), config.getBuildConfiguration().getDockerArchive());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) File(java.io.File) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Aggregations

Test (org.junit.Test)35 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)28 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)20 IOException (java.io.IOException)16 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 File (java.io.File)13 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)12 ImageStream (io.fabric8.openshift.api.model.ImageStream)10 Arguments (io.fabric8.maven.docker.config.Arguments)8 Service (io.fabric8.kubernetes.api.model.Service)7 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)7 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)6 BuildService (io.fabric8.maven.core.service.BuildService)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 HashMap (java.util.HashMap)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)5 ImageName (io.fabric8.maven.docker.util.ImageName)5 ImageStreamTag (io.fabric8.openshift.api.model.ImageStreamTag)5