use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method updateImageName.
private void updateImageName(KubernetesClient kubernetes, String namespace, HasMetadata entity, String imagePrefix, String imageName) {
String name = KubernetesHelper.getName(entity);
if (entity instanceof Deployment) {
Deployment resource = (Deployment) entity;
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
kubernetes.extensions().deployments().inNamespace(namespace).withName(name).replace(resource);
}
}
} else if (entity instanceof ReplicaSet) {
ReplicaSet resource = (ReplicaSet) entity;
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name).replace(resource);
}
}
} else if (entity instanceof ReplicationController) {
ReplicationController resource = (ReplicationController) entity;
ReplicationControllerSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
kubernetes.replicationControllers().inNamespace(namespace).withName(name).replace(resource);
}
}
} else if (entity instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) entity;
DeploymentConfigSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
if (openshiftClient == null) {
log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
}
openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
}
}
}
}
use of io.fabric8.maven.docker.util.ImageName in project ballerina by ballerina-lang.
the class TestUtils method deleteDockerImage.
public static void deleteDockerImage(String imageName) {
if (!imageName.contains(":")) {
imageName += ":" + Constants.IMAGE_VERSION_LATEST;
}
DockerClient client = new io.fabric8.docker.client.DefaultDockerClient();
List<ImageDelete> imageDeleteList = client.image().withName(imageName).delete().force().andPrune(false);
for (ImageDelete imageDelete : imageDeleteList) {
imageDelete.getDeleted();
imageDelete.getUntagged();
}
}
use of io.fabric8.maven.docker.util.ImageName in project ballerina by ballerina-lang.
the class DefaultBallerinaDockerClient method buildImage.
/*
Execute a Docker image build using Fabric8 DSL.
*/
private void buildImage(String dockerEnv, String imageName, Path tmpDir, String buildArgs) throws InterruptedException, IOException {
DockerClient client = getDockerClient(dockerEnv);
OutputHandle buildHandle = client.image().build().withRepositoryName(imageName).withNoCache().alwaysRemovingIntermediate().withBuildArgs(buildArgs).usingListener(new DockerBuilderEventListener()).fromFolder(tmpDir.toString());
buildDone.await();
buildHandle.close();
client.close();
}
use of io.fabric8.maven.docker.util.ImageName 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.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);
}
}
Aggregations