use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class DockerImageWatcher method restartContainer.
protected void restartContainer(WatchService.ImageWatcher watcher, Collection<HasMetadata> resources) {
ImageConfiguration imageConfig = watcher.getImageConfiguration();
String imageName = imageConfig.getName();
ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
try (KubernetesClient client = clusterAccess.createDefaultClient()) {
String namespace = clusterAccess.getNamespace();
String imagePrefix = getImagePrefix(imageName);
for (HasMetadata entity : resources) {
updateImageName(client, namespace, entity, imagePrefix, imageName);
}
} catch (KubernetesClientException e) {
KubernetesHelper.handleKubernetesClientException(e, this.log);
} catch (IllegalStateException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class JibBuildServiceBuildIntegrationTest method build_dockerFileMode_shouldThrowException.
@Test
public void build_dockerFileMode_shouldThrowException() {
// Given
final ImageConfiguration ic = imageConfiguration.toBuilder().build(imageConfiguration.getBuild().toBuilder().dockerFile("Dockerfile").build()).build();
// When
final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> jibBuildService.build(ic));
// Then
assertThat(result).hasMessage("Error when building JIB image").getCause().hasMessage("Dockerfile mode is not supported with JIB build strategy");
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class JibBuildServiceBuildIntegrationTest method build_withLayersAndArtifact_shouldPerformJibBuild.
@Test
public void build_withLayersAndArtifact_shouldPerformJibBuild() throws Exception {
// Given
FileUtils.touch(new File(targetDirectory, "final-artifact.jar"));
final File dlFile = new File(targetDirectory, "to-deployments.txt");
FileUtils.touch(dlFile);
final File otherFile = new File(targetDirectory, "to-other.txt");
FileUtils.touch(otherFile);
final ImageConfiguration ic = imageConfiguration.toBuilder().build(BuildConfiguration.builder().assembly(AssemblyConfiguration.builder().name("custom").targetDir("/deployments").layer(Assembly.builder().id("deployments-layer").file(AssemblyFile.builder().outputDirectory(new File(".")).source(dlFile).destName(dlFile.getName()).build()).build()).layer(Assembly.builder().id("other-layer").file(AssemblyFile.builder().outputDirectory(new File("other")).source(otherFile).destName(otherFile.getName()).build()).build()).build()).build()).build();
// When
jibBuildService.build(ic);
// Then
assertDockerFile().hasContent("FROM busybox\n" + "COPY /deployments-layer/deployments /deployments/\n" + "COPY /other-layer/deployments /deployments/\n" + "COPY /jkube-generated-layer-final-artifact/deployments /deployments/\n" + "VOLUME [\"/deployments\"]");
FileAssertions.assertThat(resolveDockerBuildDirs().resolve("build").toFile()).fileTree().containsExactlyInAnyOrder("Dockerfile", "deployments-layer", "deployments-layer/deployments", "deployments-layer/deployments/to-deployments.txt", "other-layer", "other-layer/deployments", "other-layer/deployments/other", "other-layer/deployments/other/to-other.txt", "jkube-generated-layer-final-artifact", "jkube-generated-layer-final-artifact/deployments", "jkube-generated-layer-final-artifact/deployments/final-artifact.jar", "deployments");
ArchiveAssertions.assertThat(resolveDockerBuildDirs().resolve("tmp").resolve("docker-build.tar").toFile()).fileTree().hasSize(6).contains("config.json", "manifest.json").haveExactly(4, new Condition<>(s -> s.endsWith(".tar.gz"), "Tar File layers"));
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenShiftBuildServiceUtilsTest method checkTarPackage.
@Test
public void checkTarPackage() throws Exception {
final JKubeBuildTarArchiver tarArchiver = mock(JKubeBuildTarArchiver.class);
createBuildArchive(jKubeServiceHub, imageConfiguration);
final ArgumentCaptor<ArchiverCustomizer> customizer = ArgumentCaptor.forClass(ArchiverCustomizer.class);
verify(jKubeServiceHub.getDockerServiceHub().getArchiveService(), times(1)).createDockerBuildArchive(any(ImageConfiguration.class), any(JKubeConfiguration.class), customizer.capture());
customizer.getValue().customize(tarArchiver);
final ArgumentCaptor<String> path = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<File> file = ArgumentCaptor.forClass(File.class);
verify(tarArchiver, times(1)).includeFile(file.capture(), path.capture());
assertThat(path.getAllValues()).singleElement().isEqualTo(".s2i/environment");
assertThat(file.getAllValues()).singleElement().satisfies(f -> assertThat(f).hasContent("FOO=BAR"));
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenShiftBuildServiceUtils method createS2IArchiveCustomizer.
private static ArchiverCustomizer createS2IArchiveCustomizer(BuildServiceConfig buildServiceConfig, ImageConfiguration imageConfiguration) throws JKubeServiceException {
try {
if (imageConfiguration.getBuildConfiguration() != null && imageConfiguration.getBuildConfiguration().getEnv() != null) {
String fileName = IoUtil.sanitizeFileName("s2i-env-" + imageConfiguration.getName());
final File environmentFile = new File(buildServiceConfig.getBuildDirectory(), fileName);
try (PrintWriter out = new PrintWriter(new FileWriter(environmentFile))) {
for (Map.Entry<String, String> e : imageConfiguration.getBuildConfiguration().getEnv().entrySet()) {
out.println(e.getKey() + "=" + e.getValue());
}
}
return tarArchiver -> {
tarArchiver.includeFile(environmentFile, ".s2i/environment");
return tarArchiver;
};
} else {
return null;
}
} catch (IOException e) {
throw new JKubeServiceException("Unable to add environment variables to the S2I build archive", e);
}
}
Aggregations