Search in sources :

Example 1 with BuildDirs

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);
    }
}
Also used : Credential(com.google.cloud.tools.jib.api.Credential) List(java.util.List) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException)

Example 2 with BuildDirs

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");
}
Also used : Arrays(java.util.Arrays) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Port(com.google.cloud.tools.jib.api.buildplan.Port) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Map(java.util.Map) Arguments(org.eclipse.jkube.kit.config.image.build.Arguments) JavaProject(org.eclipse.jkube.kit.common.JavaProject) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) List(java.util.List) Rule(org.junit.Rule) Assembly(org.eclipse.jkube.kit.common.Assembly) ImageFormat(com.google.cloud.tools.jib.api.buildplan.ImageFormat) JibServiceUtil.containerFromImageConfiguration(org.eclipse.jkube.kit.service.jib.JibServiceUtil.containerFromImageConfiguration) Collections(java.util.Collections) Mocked(mockit.Mocked) Verifications(mockit.Verifications) TemporaryFolder(org.junit.rules.TemporaryFolder) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) List(java.util.List) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)2 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 BuildDirs (org.eclipse.jkube.kit.build.api.assembly.BuildDirs)2 Assembly (org.eclipse.jkube.kit.common.Assembly)2 Credential (com.google.cloud.tools.jib.api.Credential)1 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)1 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)1 ImageFormat (com.google.cloud.tools.jib.api.buildplan.ImageFormat)1 Port (com.google.cloud.tools.jib.api.buildplan.Port)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Mocked (mockit.Mocked)1 Verifications (mockit.Verifications)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1