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