use of org.eclipse.jkube.kit.build.api.assembly.BuildDirs in project jkube by eclipse.
the class JibBuildService method buildSingleImage.
@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
try {
log.info("[[B]]JIB[[B]] image build started");
if (imageConfig.getBuildConfiguration().isDockerFileMode()) {
throw new JKubeServiceException("Dockerfile mode is not supported with JIB build strategy");
}
prependRegistry(imageConfig, configuration.getProperties().getProperty(PUSH_REGISTRY));
BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), configuration);
final Credential pullRegistryCredential = getRegistryCredentials(configuration.getRegistryConfig(), false, imageConfig, log);
final JibContainerBuilder containerBuilder = containerFromImageConfiguration(imageConfig, pullRegistryCredential);
final Map<Assembly, List<AssemblyFileEntry>> layers = AssemblyManager.getInstance().copyFilesToFinalTarballDirectory(configuration, buildDirs, AssemblyManager.getAssemblyConfiguration(imageConfig.getBuildConfiguration(), configuration));
JibServiceUtil.layers(buildDirs, layers).forEach(containerBuilder::addFileEntriesLayer);
// TODO: Improve Assembly Manager so that the effective assemblyFileEntries computed can be properly shared
// the call to AssemblyManager.getInstance().createDockerTarArchive should not be necessary,
// files should be added using the AssemblyFileEntry list. AssemblyManager, should provide
// a common way to achieve this so that both the tar builder and any other builder could get a hold of
// archive customizers, file entries, etc.
File dockerTarArchive = getAssemblyTarArchive(imageConfig, configuration, log);
JibServiceUtil.buildContainer(containerBuilder, TarImage.at(dockerTarArchive.toPath()).named(imageConfig.getName()), log);
log.info(" %s successfully built", dockerTarArchive.getAbsolutePath());
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (Exception ex) {
throw new JKubeServiceException("Error when building JIB image", ex);
}
}
use of org.eclipse.jkube.kit.build.api.assembly.BuildDirs in project jkube by eclipse.
the class JibServiceUtilTest method layers_withMultipleLayers_shouldReturnTransformedLayers.
@Test
public void layers_withMultipleLayers_shouldReturnTransformedLayers() throws IOException {
// Given
final BuildDirs buildDirs = new BuildDirs("layers-test", JKubeConfiguration.builder().outputDirectory("target/docker").project(JavaProject.builder().baseDirectory(temporaryFolder.getRoot()).build()).build());
final Map<Assembly, List<AssemblyFileEntry>> originalLayers = new LinkedHashMap<>();
originalLayers.put(Assembly.builder().id("layer-1").build(), Arrays.asList(AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(buildDirs.getOutputDirectory().toPath().resolve("layer-1").resolve("l1.1.txt").toFile()).build(), AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(buildDirs.getOutputDirectory().toPath().resolve("layer-1").resolve("l1.2.txt").toFile()).build()));
originalLayers.put(Assembly.builder().build(), Arrays.asList(AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(new File(buildDirs.getOutputDirectory(), "l2.1.txt")).build(), AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(new File(buildDirs.getOutputDirectory(), "l2.2.txt")).build()));
// Creates a denormalized path in JDK 8
originalLayers.put(Assembly.builder().id("jkube-generated-layer-final-artifact").build(), Collections.singletonList(AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(buildDirs.getOutputDirectory().toPath().resolve("jkube-generated-layer-final-artifact").resolve("deployments").resolve(".").resolve("edge.case").toFile()).build()));
// When
final List<FileEntriesLayer> result = JibServiceUtil.layers(buildDirs, originalLayers);
// Then
assertThat(result).hasSize(3).anySatisfy(fel -> assertThat(fel).hasFieldOrPropertyWithValue("name", "layer-1").extracting(FileEntriesLayer::getEntries).asList().extracting("extractionPath.unixPath").containsExactly("/l1.1.txt", "/l1.2.txt")).anySatisfy(fel -> assertThat(fel).hasFieldOrPropertyWithValue("name", "").extracting(FileEntriesLayer::getEntries).asList().extracting("extractionPath.unixPath").containsExactly("/l2.1.txt", "/l2.2.txt")).anySatisfy(fel -> assertThat(fel).hasFieldOrPropertyWithValue("name", "jkube-generated-layer-final-artifact").extracting(FileEntriesLayer::getEntries).asList().extracting("extractionPath.unixPath").containsExactly("/deployments/edge.case")).extracting(FileEntriesLayer::getName).containsExactly("layer-1", "", "jkube-generated-layer-final-artifact");
}
Aggregations