use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class BuildUtilTest method extractBaseFromConfiguration_withBuildConfigurationAssemblyAndFrom_shouldReturnFrom.
@Test
public void extractBaseFromConfiguration_withBuildConfigurationAssemblyAndFrom_shouldReturnFrom() {
// Given
final BuildConfiguration buildConfiguration = BuildConfiguration.builder().from("alpine:latest").assembly(new AssemblyConfiguration()).build();
// When
final String result = extractBaseFromConfiguration(buildConfiguration);
// Then
assertThat(result).isEqualTo("alpine:latest");
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyManager method createDockerTarArchive.
/**
* Create a docker tar archive from the given configuration which can be sent to the Docker host for
* creating the image.
*
* @param imageName Name of the image to create (used for creating build directories)
* @param configuration Mojos parameters (used for finding the directories)
* @param buildConfig configuration for how to build the image
* @param log KitLogger used to display warning if permissions are to be normalized
* @param finalCustomizer finalCustomizer to be applied to the tar archive
* @return file holding the path to the created assembly tar file
* @throws IOException IO exception
*/
public File createDockerTarArchive(String imageName, final JKubeConfiguration configuration, final BuildConfiguration buildConfig, KitLogger log, ArchiverCustomizer finalCustomizer) throws IOException {
final BuildDirs buildDirs = createBuildDirs(imageName, configuration);
final List<ArchiverCustomizer> archiveCustomizers = new ArrayList<>();
final AssemblyConfiguration assemblyConfig = getAssemblyConfiguration(buildConfig, configuration);
final Map<Assembly, List<AssemblyFileEntry>> layers = copyFilesToFinalTarballDirectory(configuration, buildDirs, assemblyConfig);
try {
if (buildConfig.isDockerFileMode()) {
createDockerTarArchiveForDockerFile(buildConfig, assemblyConfig, configuration, buildDirs, log, archiveCustomizers);
} else {
createAssemblyArchive(assemblyConfig, configuration, buildDirs, buildConfig.getCompression(), layers);
createDockerTarArchiveForGeneratorMode(buildConfig, buildDirs, archiveCustomizers, assemblyConfig, layers);
}
archiveCustomizers.addAll(getDefaultCustomizers(configuration, assemblyConfig, finalCustomizer, layers));
return createBuildTarBall(configuration, buildDirs, archiveCustomizers, assemblyConfig, buildConfig.getCompression());
} catch (IOException e) {
throw new IOException(String.format("Cannot create %s in %s", DOCKERFILE_NAME, buildDirs.getOutputDirectory()), e);
}
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyManager method getAssemblyConfigurationForDockerfileMode.
@Nonnull
private static AssemblyConfiguration getAssemblyConfigurationForDockerfileMode(JKubeConfiguration configuration, BuildConfiguration buildConfiguration, JKubeConfiguration params) throws IOException {
AssemblyConfiguration assemblyConfig = getAssemblyConfigurationOrCreateDefault(buildConfiguration);
final AssemblyConfiguration.AssemblyConfigurationBuilder builder = assemblyConfig.toBuilder();
File contextDir = buildConfiguration.getAbsoluteContextDirPath(params.getSourceDirectory(), params.getBasedir().getAbsolutePath());
final AssemblyFileSet assemblyFileSet = AssemblyFileSet.builder().directory(contextDir).outputDirectory(new File(".")).directoryMode("0775").excludes(createDockerExcludesList(contextDir, params.getOutputDirectory())).includes(createDockerIncludesList(contextDir)).build();
builder.layer(Assembly.builder().fileSet(assemblyFileSet).build());
return builder.build().getFlattenedClone(configuration);
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyManager method createAssemblyArchive.
private void createAssemblyArchive(AssemblyConfiguration assemblyConfig, JKubeConfiguration params, BuildDirs buildDirs, ArchiveCompression compression, Map<Assembly, List<AssemblyFileEntry>> layers) throws IOException {
if (layers.isEmpty()) {
return;
}
AssemblyConfigurationSource source = new AssemblyConfigurationSource(params, buildDirs, assemblyConfig);
JKubeBuildTarArchiver jkubeTarArchiver = new JKubeBuildTarArchiver();
AssemblyMode buildMode = assemblyConfig.getMode();
try {
layers.values().stream().flatMap(List::stream).filter(afe -> StringUtils.isNotBlank(afe.getFileMode())).forEach(jkubeTarArchiver::setFileMode);
jkubeTarArchiver.createArchive(source.getOutputDirectory(), buildDirs, compression);
} catch (IOException e) {
String error = "Failed to create assembly for docker image " + " (with mode '" + buildMode + "'): " + e.getMessage() + ".";
if (params.getProject().getArtifact() == null) {
error += " If you include the build artifact please ensure that you have " + "built the artifact before with 'mvn package' (should be available in the target/ dir). " + "Please see the documentation (section \"Assembly\") for more information.";
}
throw new IOException(error, e);
}
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyManager method copyFilesToFinalTarballDirectory.
public Map<Assembly, List<AssemblyFileEntry>> copyFilesToFinalTarballDirectory(JKubeConfiguration configuration, BuildDirs buildDirs, AssemblyConfiguration assemblyConfiguration) throws IOException {
final Map<Assembly, List<AssemblyFileEntry>> entries = new LinkedHashMap<>();
FileUtil.createDirectory(new File(buildDirs.getOutputDirectory(), assemblyConfiguration.getTargetDir()));
final List<Assembly> layers = assemblyConfiguration.getProcessedLayers(configuration);
if (layers.size() > 1 && layers.stream().anyMatch(l -> StringUtils.isBlank(l.getId()))) {
throw new IllegalStateException("Assemblies with more than one layer require a proper id for each layer");
}
for (Assembly layer : layers) {
entries.put(layer, copyLayerFilesToFinalTarballDirectory(configuration.getProject(), buildDirs, assemblyConfiguration, layer));
}
return entries;
}
Aggregations