Search in sources :

Example 21 with AssemblyFileEntry

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

the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent.

@Test
public void createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent() {
    // Given
    final BuildConfiguration buildConfig = BuildConfiguration.builder().putEnv("ENV_VAR", "VALUE").label("LABEL", "LABEL_VALUE").port("8080").user("1000").volume("VOLUME").runCmd("chown -R 1000:1000 /opt").maintainer("Alex").cmd(Arguments.builder().execArgument("sh").execArgument("-c").execArgument("server").build()).build();
    final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(Assembly.builder().build()).build();
    final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
    // When
    final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
    // Then
    assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "ENV ENV_VAR=VALUE\n" + "LABEL LABEL=LABEL_VALUE\n" + "EXPOSE 8080\n" + "COPY /layer-with-id/deployments /deployments/\n" + "COPY /deployments /deployments/\n" + "RUN chown -R 1000:1000 /opt\n" + "VOLUME [\"/deployments\"]\n" + "VOLUME [\"VOLUME\"]\n" + "CMD [\"sh\",\"-c\",\"server\"]\n" + "USER 1000\n");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) Expectations(mockit.Expectations) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) Test(org.junit.Test) AssemblyConfigurationUtils.createDockerFileBuilder(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder) AssemblyConfigurationUtils.getJKubeAssemblyFileSets(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault) List(java.util.List) AssemblyConfigurationUtils.getJKubeAssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles) Assembly(org.eclipse.jkube.kit.common.Assembly) Map(java.util.Map) Arguments(org.eclipse.jkube.kit.config.image.build.Arguments) Injectable(mockit.Injectable) Collections(java.util.Collections) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) List(java.util.List) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Example 22 with AssemblyFileEntry

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

the class AssemblyManagerCreateDockerTarArchiveTest method createChangedFilesArchive.

@Test
public void createChangedFilesArchive() throws IOException {
    // Given
    final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();
    final List<AssemblyFileEntry> entries = new ArrayList<>();
    final File assemblyDirectory = temporaryFolder.getRoot().toPath().resolve("target").resolve("docker").toFile();
    entries.add(AssemblyFileEntry.builder().source(temporaryFolder.getRoot().toPath().resolve("target").resolve("test-0.1.0.jar").toFile()).dest(temporaryFolder.getRoot().toPath().resolve("target").resolve("docker").resolve("test-0.1.0.jar").toFile()).fileMode("0655").build());
    // When
    final File result = assemblyManager.createChangedFilesArchive(entries, assemblyDirectory, "image-name", jKubeConfiguration);
    // Then
    ArchiveAssertions.assertThat(result).isFile().hasName("changed-files.tar").hasSameContentAsDirectory(getExpectedDirectory("changed-files.tar"));
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) ArrayList(java.util.ArrayList) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 23 with AssemblyFileEntry

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

the class AssemblyManager method processJKubeProjectAssemblyFile.

private AssemblyFileEntry processJKubeProjectAssemblyFile(JavaProject project, AssemblyFile assemblyFile, BuildDirs buildDirs, Assembly layer, AssemblyConfiguration assemblyConfiguration) throws IOException {
    final File sourceFile = resolveSourceFile(project.getBaseDirectory(), assemblyFile);
    final File outputDirectory = getAssemblyFileOutputDirectory(assemblyFile, buildDirs.getOutputDirectory(), layer, assemblyConfiguration);
    FileUtil.createDirectory(outputDirectory);
    final String destinationFilename = Optional.ofNullable(assemblyFile.getDestName()).orElse(sourceFile.getName());
    final File destinationFile = new File(outputDirectory, destinationFilename);
    FileUtil.copy(sourceFile, destinationFile);
    return new AssemblyFileEntry(sourceFile, destinationFile, assemblyFile.getFileMode());
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File)

Example 24 with AssemblyFileEntry

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

the class AssemblyManager method createChangedFilesArchive.

public File createChangedFilesArchive(List<AssemblyFileEntry> entries, File assemblyDirectory, String imageName, JKubeConfiguration jKubeConfiguration) throws IOException {
    BuildDirs dirs = createBuildDirs(imageName, jKubeConfiguration);
    try {
        File archive = new File(dirs.getTemporaryRootDirectory(), "changed-files.tar");
        File archiveDir = createArchiveDir(dirs);
        for (AssemblyFileEntry entry : entries) {
            File dest = prepareChangedFilesArchivePath(archiveDir, entry.getDest(), assemblyDirectory);
            Files.createDirectories(dest.getParentFile().toPath());
            Files.copy(Paths.get(entry.getSource().getAbsolutePath()), Paths.get(dest.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
        }
        return JKubeTarArchiver.createTarBallOfDirectory(archive, archiveDir, ArchiveCompression.none);
    } catch (IOException exp) {
        throw new IOException("Error while creating " + dirs.getTemporaryRootDirectory() + "/changed-files.tar: " + exp);
    }
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) IOException(java.io.IOException) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File)

Example 25 with AssemblyFileEntry

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

the class AssemblyFileSetUtilsProcessAssemblyFileSetTest method fileSetDirectoryAndOutputDirectoryResolvingToSelf.

/**
 * Has AssemblyFileSet with directory and outputDirectory relative path resolving to self.
 * Has AssemblyConfiguration targetDir.
 *
 * Should copy <b>contents</b> of AssemblyFileSet#directory to the outputDirectory in a subdirectory named as the
 * AssemblyConfiguration#targetDir.
 */
@Test
public void fileSetDirectoryAndOutputDirectoryResolvingToSelf() throws Exception {
    // Given
    final AssemblyFileSet afs = AssemblyFileSet.builder().directory(sourceDirectory).outputDirectory(new File(".")).build();
    final Assembly layer = new Assembly();
    final AssemblyConfiguration ac = AssemblyConfiguration.builder().name("NotImportant").targetDir("deployments").build();
    // When
    final List<AssemblyFileEntry> result = processAssemblyFileSet(baseDirectory, outputDirectory, afs, layer, ac);
    // Then
    assertThat(result).hasSize(16);
    FileAssertions.assertThat(new File(outputDirectory, "deployments")).exists().fileTree().containsExactlyInAnyOrder("1.txt", "3.other", "37", "one", "one/1.txt", "one/3.other", "one/37", "two", "two/1.txt", "two/3.other", "two/37", "three", "three/1.txt", "three/3.other", "three/37").doesNotContainSequence("source-directory");
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Aggregations

File (java.io.File)32 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)32 AssemblyFileSet (org.eclipse.jkube.kit.common.AssemblyFileSet)25 Test (org.junit.Test)24 Assembly (org.eclipse.jkube.kit.common.Assembly)21 AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)20 AssemblyFileSetUtils.processAssemblyFileSet (org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet)16 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)8 List (java.util.List)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 IOException (java.io.IOException)5 Collectors (java.util.stream.Collectors)5 Nonnull (javax.annotation.Nonnull)5 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)5 Collections (java.util.Collections)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 AssemblyConfigurationUtils.getJKubeAssemblyFiles (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles)4