use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenshiftBuildService method buildSingleImage.
@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
initClient();
String buildName = null;
try {
final ImageConfiguration.ImageConfigurationBuilder applicableImageConfigBuilder = imageConfig.toBuilder();
if (imageConfig.getBuildConfiguration() != null && !imageConfig.getBuildConfiguration().isDockerFileMode() && imageConfig.getBuildConfiguration().getAssembly() != null) {
applicableImageConfigBuilder.build(imageConfig.getBuild().toBuilder().assembly(imageConfig.getBuildConfiguration().getAssembly().getFlattenedClone(jKubeServiceHub.getConfiguration())).build());
}
final ImageConfiguration applicableImageConfig = applicableImageConfigBuilder.build();
ImageName imageName = new ImageName(applicableImageConfig.getName());
File dockerTar = createBuildArchive(jKubeServiceHub, applicableImageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream / pullSecret and create them if necessary
String openshiftPullSecret = buildServiceConfig.getOpenshiftPullSecret();
final boolean usePullSecret = checkOrCreatePullSecret(client, builder, openshiftPullSecret, applicableImageConfig);
if (usePullSecret) {
buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, openshiftPullSecret);
} else {
buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, null);
}
if (buildServiceConfig.getBuildOutputKind() == null || IMAGE_STREAM_TAG.equals(buildServiceConfig.getBuildOutputKind())) {
checkOrCreateImageStream(buildServiceConfig, client, builder, resolveImageStreamName(imageName));
applyBuild(buildName, dockerTar, builder);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(), imageName, client);
} else {
applyBuild(buildName, dockerTar, builder);
}
} catch (JKubeServiceException e) {
throw e;
} catch (Exception ex) {
// Log additional details in case of any IOException
if (ex.getCause() instanceof IOException) {
log.error("Build for %s failed: %s", buildName, ex.getCause().getMessage());
logBuildFailure(client, buildName);
} else {
throw new JKubeServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class KubernetesResourceUtilTest method extractContainerName_withPeriodsInImageUser_shouldRemovePeriodsFromContainerName.
@Test
public void extractContainerName_withPeriodsInImageUser_shouldRemovePeriodsFromContainerName() {
// Given
final ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("org.eclipse.jkube.testing/test-image").build();
final GroupArtifactVersion gav = new GroupArtifactVersion("org.eclipse.jkube.testing", "test-image", "1.0.0");
// When
final String result = KubernetesResourceUtil.extractContainerName(gav, imageConfiguration);
// Then
assertThat(result).isEqualTo("orgeclipsejkubetesting-test-image");
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class ContainerHandlerTest method getContainerWithGroupArtifactTest.
@Test
public void getContainerWithGroupArtifactTest() {
project.setArtifactId("test-artifact");
project.setGroupId("test-group");
ports.add("8080");
ports.add("9090");
tags.add("latest");
tags.add("test");
ContainerHandler handler = new ContainerHandler(project.getProperties(), new GroupArtifactVersion("test-group", "test-artifact", "0"), probeHandler);
// container name with group id and aritact id without alias and user
final BuildConfiguration buildImageConfiguration = BuildConfiguration.builder().ports(ports).from("fabric8/").cleanup("try").tags(tags).compressionString("gzip").dockerFile("testFile").build();
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test").build(buildImageConfiguration).registry("docker.io").build();
images.clear();
images.add(imageConfiguration);
containers = handler.getContainers(config, images);
assertNotNull(containers);
assertEquals("test-group-test-artifact", containers.get(0).getName());
assertEquals("docker.io/test:latest", containers.get(0).getImage());
assertEquals("IfNotPresent", containers.get(0).getImagePullPolicy());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class ContainerHandlerTest method testGetContainersWithUserAndImageAndTagWithPeriodInImageUser.
@Test
public void testGetContainersWithUserAndImageAndTagWithPeriodInImageUser() {
// Given
ContainerHandler containerHandler = createContainerHandler(project);
List<ImageConfiguration> imageConfigurations = new ArrayList<>();
imageConfigurations.add(ImageConfiguration.builder().name("roman.gordill/customer-service-cache:latest").registry("quay.io").build(BuildConfiguration.builder().from("quay.io/jkube/jkube-java:0.0.13").assembly(AssemblyConfiguration.builder().targetDir("/deployments").build()).build()).build());
// When
List<Container> containers = containerHandler.getContainers(config, imageConfigurations);
// Then
assertNotNull(containers);
assertEquals(1, containers.size());
Container container = containers.get(0);
assertEquals("quay.io/roman.gordill/customer-service-cache:latest", container.getImage());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class PropertyConfigHandlerTest method testEnvAndLabels.
@Test
public void testEnvAndLabels() {
List<ImageConfiguration> configs = resolveImage(imageConfiguration, props(mergeArrays(getBaseTestData(), new String[] { "docker.from", "baase", "docker.name", "demo", "docker.env.HOME", "/tmp", "docker.env.root.dir", "/bla", "docker.labels.version", "1.0.0", "docker.labels.blub.bla.foobar", "yep" })));
assertEquals(1, configs.size());
ImageConfiguration calcConfig = configs.get(0);
for (Map env : new Map[] { calcConfig.getBuildConfiguration().getEnv(), calcConfig.getRunConfiguration().getEnv() }) {
assertEquals(2, env.size());
assertEquals("/tmp", env.get("HOME"));
assertEquals("/bla", env.get("root.dir"));
}
for (Map labels : new Map[] { calcConfig.getBuildConfiguration().getLabels(), calcConfig.getRunConfiguration().getLabels() }) {
assertEquals(3, labels.size());
assertEquals("1.0.0", labels.get("version"));
assertEquals("yep", labels.get("blub.bla.foobar"));
}
}
Aggregations