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(":");
}
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));
}
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);
}
}
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());
}
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());
}
Aggregations