use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class DockerBuildServiceTest method testSuccessfulBuild.
@Test
public void testSuccessfulBuild() throws Exception {
new Expectations() {
{
hub.getBuildService();
result = buildService;
}
};
final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).build();
final String imageName = "image-name";
final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
DockerBuildService service = new DockerBuildService(hub, config);
service.build(image);
new FullVerificationsInOrder() {
{
buildService.buildImage(image, context);
buildService.tagImage(imageName, image);
}
};
}
use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class KubernetesClientUtil method deleteEntities.
public static void deleteEntities(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, String s2iBuildNameSuffix, Logger log) {
List<HasMetadata> list = new ArrayList<>(entities);
// For OpenShift cluster, also delete s2i buildconfig
OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
if (openshiftClient != null) {
for (HasMetadata entity : list) {
if ("ImageStream".equals(getKind(entity))) {
ImageName imageName = new ImageName(entity.getMetadata().getName());
String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
log.info("Deleting resource BuildConfig " + namespace + "/" + buildName);
openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
}
}
}
// lets delete in reverse order
Collections.reverse(list);
for (HasMetadata entity : list) {
log.info("Deleting resource " + getKind(entity) + " " + namespace + "/" + getName(entity));
kubernetes.resource(entity).inNamespace(namespace).cascading(true).delete();
}
}
use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method extractImageUser.
private static String extractImageUser(String image, MavenProject project) {
ImageName name = new ImageName(image);
String imageUser = name.getUser();
return imageUser != null ? imageUser : project.getGroupId();
}
use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method updateOrCreateBuildConfig.
private String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, ImageConfiguration imageConfig) {
ImageName imageName = new ImageName(imageConfig.getName());
String buildName = getS2IBuildName(config, imageName);
String imageStreamName = getImageStreamName(imageName);
String outputImageStreamTag = imageStreamName + ":" + (imageName.getTag() != null ? imageName.getTag() : "latest");
BuildStrategy buildStrategyResource = createBuildStrategy(imageConfig, config.getOpenshiftBuildStrategy());
BuildOutput buildOutput = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(outputImageStreamTag).endTo().build();
// Fetch exsting build config
BuildConfig buildConfig = client.buildConfigs().withName(buildName).get();
if (buildConfig != null) {
// lets verify the BC
BuildConfigSpec spec = getBuildConfigSpec(buildConfig);
validateSourceType(buildName, spec);
if (config.getBuildRecreateMode().isBuildConfig()) {
// Delete and recreate afresh
client.buildConfigs().withName(buildName).delete();
return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
} else {
// Update & return
return updateBuildConfig(client, buildName, buildStrategyResource, buildOutput, spec);
}
} else {
// Create afresh
return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
}
}
use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method build.
@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
try {
ImageName imageName = new ImageName(imageConfig.getName());
File dockerTar = createBuildArchive(imageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream and create them if necessary
String buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig);
checkOrCreateImageStream(config, client, builder, getImageStreamName(imageName));
applyResourceObjects(config, client, builder);
// Start the actual build
Build build = startBuild(client, dockerTar, buildName);
// Wait until the build finishes
waitForOpenShiftBuildToComplete(client, build);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(config), imageName, client);
} catch (Fabric8ServiceException e) {
throw e;
} catch (Exception ex) {
throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
Aggregations