Search in sources :

Example 6 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyManager method getAssemblyFiles.

/**
 * Extract all files with a tracking archiver. These can be used to track changes in the filesystem and triggering
 * a rebuild of the image if needed ('docker:watch')
 *
 * @param imageConfiguration the image configuration
 * @param jKubeConfiguration JKube kit configuration
 * @return assembly files
 */
public AssemblyFiles getAssemblyFiles(ImageConfiguration imageConfiguration, JKubeConfiguration jKubeConfiguration) throws IOException {
    BuildDirs buildDirs = createBuildDirs(imageConfiguration.getName(), jKubeConfiguration);
    final AssemblyConfiguration assemblyConfig = imageConfiguration.getBuildConfiguration().getAssembly().getFlattenedClone(jKubeConfiguration);
    AssemblyFiles assemblyFiles = new AssemblyFiles(buildDirs.getOutputDirectory());
    copyFilesToFinalTarballDirectory(jKubeConfiguration, buildDirs, assemblyConfig).values().stream().flatMap(List::stream).forEach(assemblyFiles::addEntry);
    return assemblyFiles;
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyConfigurationUtils.getJKubeAssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles)

Example 7 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyConfigurationSourceTest method permissionMode.

@Test
public void permissionMode() {
    try {
        AssemblyConfiguration.builder().permissionsString("blub").build();
    } catch (IllegalArgumentException exp) {
        assertTrue(exp.getMessage().contains("blub"));
    }
    AssemblyConfiguration config = AssemblyConfiguration.builder().permissionsString("ignore").build();
    assertSame(AssemblyConfiguration.PermissionMode.ignore, config.getPermissions());
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Test(org.junit.Test)

Example 8 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectoryAndAssemblyFile.

@Test
public void withDockerfileInBaseDirectoryAndAssemblyFile() throws IOException {
    // Given
    final File dockerFile = new File(baseDirectory, "Dockerfile");
    writeLineToFile(dockerFile, "FROM busybox");
    final File assemblyFile = temporaryFolder.newFile("extra-file-1.txt");
    writeLineToFile(assemblyFile, "HELLO");
    AssemblyConfiguration assemblyConfig = AssemblyConfiguration.builder().inline(Assembly.builder().file(AssemblyFile.builder().source(assemblyFile).outputDirectory(new File(".")).build()).build()).build();
    final JKubeConfiguration configuration = createJKubeConfiguration();
    final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder().dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).assembly(assemblyConfig).build();
    // When
    final File dockerArchiveFile = assemblyManager.createDockerTarArchive("dockerfile-and-assembly-file", configuration, jKubeBuildConfiguration, prefixedLogger, null);
    // Then
    assertTargetHasDockerDirectories("dockerfile-and-assembly-file");
    ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("with-dockerfile-in-base-directory-and-assembly-file"));
    assertDockerFile("dockerfile-and-assembly-file").hasContent("FROM busybox\n");
    assertBuildDirectoryFileTree("dockerfile-and-assembly-file").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/Dockerfile", "maven/test-0.1.0.jar", "maven/extra-file-1.txt", "maven/target", "maven/target/test-0.1.0.jar");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 9 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class PropertyConfigHandlerTest method validateBuildConfiguration.

private void validateBuildConfiguration(BuildConfiguration buildConfig) {
    assertEquals(CleanupMode.TRY_TO_REMOVE, buildConfig.cleanupMode());
    assertEquals("command.sh", buildConfig.getCmd().getShell());
    assertEquals("image", buildConfig.getFrom());
    assertEquals("image-ext", buildConfig.getFromExt().get("name"));
    assertEquals("8080", buildConfig.getPorts().get(0));
    assertEquals("8080", buildConfig.getPorts().get(1));
    assertEquals("/vol1", buildConfig.getVolumes().get(0));
    assertEquals("/foo", buildConfig.getVolumes().get(1));
    assertEquals("fabric8io@redhat.com", buildConfig.getMaintainer());
    assertNull(buildConfig.getNocache());
    assertEquals("Always", buildConfig.getImagePullPolicy());
    validateEnv(buildConfig.getEnv());
    validateLabels(buildConfig.getLabels());
    validateArgs(buildConfig.getArgs());
    validateBuildOptions(buildConfig.getBuildOptions());
    /*
         * validate only the descriptor is required and defaults are all used, 'testAssembly' validates
         * all options can be set
         */
    AssemblyConfiguration assemblyConfig = buildConfig.getAssembly();
    assertNull(assemblyConfig.getUser());
    assertNull(assemblyConfig.getExportTargetDir());
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration)

Example 10 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyFileSetUtils method processAssemblyFileSet.

/**
 * Will copy files from the provided <code>baseDirectory</code> into
 * <code>outputDirectory/assemblyConfiguration.targetDir[/layer.directory]</code>
 * considering the inclusion and exclusion rules defined in the provided {@link AssemblyFileSet}.
 *
 * @param baseDirectory directory from where to resolve source files.
 * @param outputDirectory directory where files should be output.
 * @param assemblyFileSet fileSet to process.
 * @param layer the layer to which fileSet belongs to.
 * @param assemblyConfiguration configuration for assembly.
 * @return List containing the copied {@link AssemblyFileEntry} for the processed {@link AssemblyFileSet}
 * @throws IOException in case something goes wrong when performing File operations.
 */
@SuppressWarnings("squid:S3864")
@Nonnull
public static List<AssemblyFileEntry> processAssemblyFileSet(File baseDirectory, File outputDirectory, AssemblyFileSet assemblyFileSet, Assembly layer, AssemblyConfiguration assemblyConfiguration) throws IOException {
    final File sourceDirectory = resolveSourceDirectory(baseDirectory, assemblyFileSet);
    Objects.requireNonNull(assemblyConfiguration.getTargetDir(), "Assembly Configuration target dir is required");
    if (!sourceDirectory.exists()) {
        return Collections.emptyList();
    }
    final File targetDirectory;
    if (StringUtils.isNotBlank(layer.getId())) {
        targetDirectory = new File(new File(outputDirectory, layer.getId()), assemblyConfiguration.getTargetDir());
    } else {
        targetDirectory = new File(outputDirectory, assemblyConfiguration.getTargetDir());
    }
    final File destinationDirectory;
    if (assemblyFileSet.getOutputDirectory() == null) {
        destinationDirectory = new File(targetDirectory, sourceDirectory.getName());
    } else if (assemblyFileSet.getOutputDirectory().isAbsolute()) {
        destinationDirectory = assemblyFileSet.getOutputDirectory();
    } else if (assemblyFileSet.getOutputDirectory().getPath().equals(PATH_TO_SELF)) {
        destinationDirectory = targetDirectory;
    } else {
        destinationDirectory = targetDirectory.toPath().resolve(assemblyFileSet.getOutputDirectory().getPath()).toFile();
    }
    final List<String> includes = Optional.ofNullable(assemblyFileSet.getIncludes()).filter(i -> !i.isEmpty()).orElse(Collections.singletonList(PATH_TO_SELF));
    final List<AssemblyFileEntry> allEntries = new ArrayList<>();
    for (String include : includes) {
        final String effectiveInclude = isSelfPath(include) ? "**" : include;
        allEntries.addAll(processInclude(sourceDirectory.toPath(), effectiveInclude, destinationDirectory.toPath(), assemblyFileSet));
    }
    return allEntries;
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) ArrayList(java.util.ArrayList) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Assembly(org.eclipse.jkube.kit.common.Assembly) PathMatcher(java.nio.file.PathMatcher) FileUtil(org.eclipse.jkube.kit.common.util.FileUtil) Optional(java.util.Optional) Path(java.nio.file.Path) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) FileSystems(java.nio.file.FileSystems) LinkedHashSet(java.util.LinkedHashSet) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) ArrayList(java.util.ArrayList) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Aggregations

AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)41 Test (org.junit.Test)32 File (java.io.File)29 Assembly (org.eclipse.jkube.kit.common.Assembly)29 AssemblyFileSet (org.eclipse.jkube.kit.common.AssemblyFileSet)22 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)19 AssemblyFileSetUtils.processAssemblyFileSet (org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet)19 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)12 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)8 List (java.util.List)6 Expectations (mockit.Expectations)6 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Nonnull (javax.annotation.Nonnull)5 AssemblyConfigurationUtils.getJKubeAssemblyFiles (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles)5 IOException (java.io.IOException)4 Map (java.util.Map)4 AssemblyConfigurationUtils.createDockerFileBuilder (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder)4 AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault)4 AssemblyConfigurationUtils.getJKubeAssemblyFileSets (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets)4