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");
}
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"));
}
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());
}
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);
}
}
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");
}
Aggregations