use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class WebAppGeneratorTest method customize_withFromTargetDirConfiguredAndNoCmd_shouldNotInitializeInvalidCmdArgument.
@Test
public void customize_withFromTargetDirConfiguredAndNoCmd_shouldNotInitializeInvalidCmdArgument() throws IOException {
// Given
final List<ImageConfiguration> originalImageConfigurations = new ArrayList<>();
final File buildDirectory = temporaryFolder.newFolder("build");
final File artifactFile = new File(buildDirectory, "artifact.war");
assertTrue(artifactFile.createNewFile());
final Properties projectProperties = new Properties();
projectProperties.put("jkube.generator.webapp.targetDir", "/usr/local/tomcat/webapps");
projectProperties.put("jkube.generator.webapp.from", "tomcat:jdk11-openjdk-slim");
when(generatorContext.getProject().getBuildDirectory()).thenReturn(buildDirectory);
when(generatorContext.getProject().getBuildFinalName()).thenReturn("artifact");
when(generatorContext.getProject().getPackaging()).thenReturn("war");
when(generatorContext.getProject().getVersion()).thenReturn("1.33.7-SNAPSHOT");
when(generatorContext.getProject().getProperties()).thenReturn(projectProperties);
// When
final List<ImageConfiguration> result = new WebAppGenerator(generatorContext).customize(originalImageConfigurations, false);
// Then
assertThat(result).isSameAs(originalImageConfigurations).hasSize(1).first().hasFieldOrPropertyWithValue("name", "%g/%a:%l").extracting(ImageConfiguration::getBuildConfiguration).hasFieldOrPropertyWithValue("from", "tomcat:jdk11-openjdk-slim").hasFieldOrPropertyWithValue("env", Collections.singletonMap("DEPLOY_DIR", "/usr/local/tomcat/webapps")).hasFieldOrPropertyWithValue("cmd", null);
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenShiftResourceMojoTest method executeInternal_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected.
@Test
public void executeInternal_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected() throws MojoExecutionException, MojoFailureException {
// Given
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("%g/%a").build(BuildConfiguration.builder().from("test-base-image:latest").build()).build();
when(mockedImageConfigResolver.resolve(eq(imageConfiguration), any())).thenReturn(Collections.singletonList(imageConfiguration));
this.openShiftResourceMojo.images = Collections.singletonList(imageConfiguration);
this.openShiftResourceMojo.namespace = "namespace-configured-via-plugin";
// When
openShiftResourceMojo.executeInternal();
// Then
assertEquals(1, openShiftResourceMojo.resolvedImages.size());
assertEquals("namespace-configured-via-plugin/test-project", openShiftResourceMojo.resolvedImages.get(0).getName());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenShiftResourceMojoTest method executeInternal_resolvesGroupInImageNameToClusterAccessNamespace_whenNamespaceDetected.
@Test
public void executeInternal_resolvesGroupInImageNameToClusterAccessNamespace_whenNamespaceDetected() throws MojoExecutionException, MojoFailureException {
// Given
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("%g/%a").build(BuildConfiguration.builder().from("test-base-image:latest").build()).build();
when(mockedClusterAccess.getNamespace()).thenReturn("test-custom-namespace");
when(mockedImageConfigResolver.resolve(eq(imageConfiguration), any())).thenReturn(Collections.singletonList(imageConfiguration));
this.openShiftResourceMojo.images = Collections.singletonList(imageConfiguration);
// When
openShiftResourceMojo.executeInternal();
// Then
assertEquals(1, openShiftResourceMojo.resolvedImages.size());
assertEquals("test-custom-namespace/test-project", openShiftResourceMojo.resolvedImages.get(0).getName());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class ConfigHelper method validateExternalPropertyActivation.
public static void validateExternalPropertyActivation(JavaProject project, List<ImageConfiguration> images) {
String prop = getExternalConfigActivationProperty(project);
if (prop == null) {
return;
}
if (images.size() == 1) {
return;
}
// With more than one image, externally activating propertyConfig get's tricky. We can only allow it to affect
// one single image. Go through each image and check if they will be controlled by default properties.
// If more than one image matches, fail.
int imagesWithoutExternalConfig = 0;
for (ImageConfiguration image : images) {
if (PropertyConfigHandler.canCoexistWithOtherPropertyConfiguredImages(image.getExternalConfig())) {
continue;
}
// else, it will be affected by the external property.
imagesWithoutExternalConfig++;
}
if (imagesWithoutExternalConfig > 1) {
throw new IllegalStateException("Configuration error: Cannot use property " + EXTERNALCONFIG_ACTIVATION_PROPERTY + " on projects with multiple images without explicit image external configuration.");
}
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class ConfigHelper method initImageConfiguration.
public static List<ImageConfiguration> initImageConfiguration(String apiVersion, Date buildTimeStamp, List<ImageConfiguration> images, ImageConfigResolver imageConfigResolver, KitLogger log, String filter, ConfigHelper.Customizer customizer, JKubeConfiguration jKubeConfiguration) {
List<ImageConfiguration> resolvedImages;
ImageNameFormatter imageNameFormatter = new ImageNameFormatter(jKubeConfiguration.getProject(), buildTimeStamp);
// Resolve images
resolvedImages = ConfigHelper.resolveImages(log, // Unresolved images
images, (ImageConfiguration image) -> imageConfigResolver.resolve(image, jKubeConfiguration.getProject()), // A filter which image to process
filter, // customizer (can be overwritten by a subclass)
customizer);
// Check for simple Dockerfile mode
if (isSimpleDockerFileMode(jKubeConfiguration.getBasedir())) {
File topDockerfile = getTopLevelDockerfile(jKubeConfiguration.getBasedir());
String defaultImageName = imageNameFormatter.format(getValueFromProperties(jKubeConfiguration.getProject().getProperties(), "jkube.image.name", "jkube.generator.name"));
if (resolvedImages.isEmpty()) {
resolvedImages.add(createSimpleDockerfileConfig(topDockerfile, defaultImageName));
} else if (resolvedImages.size() == 1 && resolvedImages.get(0).getBuildConfiguration() == null) {
resolvedImages.set(0, addSimpleDockerfileConfig(resolvedImages.get(0), topDockerfile));
}
}
// Initialize configuration and detect minimal API version
ConfigHelper.initAndValidate(resolvedImages, apiVersion, imageNameFormatter);
for (ImageConfiguration image : resolvedImages) {
BuildConfiguration buildConfiguration = image.getBuildConfiguration();
if (buildConfiguration != null && buildConfiguration.isDockerFileMode()) {
log.info("Using Dockerfile: %s", buildConfiguration.getDockerFile().getAbsolutePath());
log.info("Using Docker Context Directory: %s", buildConfiguration.getAbsoluteContextDirPath(jKubeConfiguration.getSourceDirectory(), jKubeConfiguration.getBasedir().getAbsolutePath()));
}
}
return resolvedImages;
}
Aggregations