use of org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer 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.build.api.assembly.ArchiverCustomizer 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