use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project quarkus by quarkusio.
the class ContainerBuilderHelper method extraDirectoryLayerConfiguration.
/**
* Returns a {@link FileEntriesLayer} for adding the extra directory to the container.
*
* @param sourceDirectory the source extra directory path
* @param targetDirectory the root directory on the container to place the files in
* @param extraDirectoryPermissions map from path on container to file permissions
* @param modificationTimeProvider file modification time provider
* @return a {@link FileEntriesLayer} for adding the extra directory to the container
* @throws IOException if walking the extra directory fails
*/
public static FileEntriesLayer extraDirectoryLayerConfiguration(Path sourceDirectory, AbsoluteUnixPath targetDirectory, Map<String, FilePermissions> extraDirectoryPermissions, BiFunction<Path, AbsoluteUnixPath, Instant> modificationTimeProvider) throws IOException {
FileEntriesLayer.Builder builder = FileEntriesLayer.builder().setName(JavaContainerBuilder.LayerType.EXTRA_FILES.getName());
Map<PathMatcher, FilePermissions> pathMatchers = new LinkedHashMap<>();
for (Map.Entry<String, FilePermissions> entry : extraDirectoryPermissions.entrySet()) {
pathMatchers.put(FileSystems.getDefault().getPathMatcher("glob:" + entry.getKey()), entry.getValue());
}
new DirectoryWalker(sourceDirectory).filterRoot().walk(localPath -> {
AbsoluteUnixPath pathOnContainer = targetDirectory.resolve(sourceDirectory.relativize(localPath));
Instant modificationTime = modificationTimeProvider.apply(localPath, pathOnContainer);
FilePermissions permissions = extraDirectoryPermissions.get(pathOnContainer.toString());
if (permissions == null) {
// Check for matching globs
Path containerPath = Paths.get(pathOnContainer.toString());
for (Map.Entry<PathMatcher, FilePermissions> entry : pathMatchers.entrySet()) {
if (entry.getKey().matches(containerPath)) {
builder.addEntry(localPath, pathOnContainer, entry.getValue(), modificationTime);
return;
}
}
// Add with default permissions
if (localPath.toFile().canExecute()) {
// make sure the file or directory can be executed
builder.addEntry(localPath, pathOnContainer, FilePermissions.fromOctalString("755"), modificationTime);
} else {
builder.addEntry(localPath, pathOnContainer, modificationTime);
}
} else {
// Add with explicit permissions
builder.addEntry(localPath, pathOnContainer, permissions, modificationTime);
}
});
return builder.build();
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class PluginConfigurationProcessor method getVolumesSet.
/**
* Parses the list of raw volumes directories to a set of {@link AbsoluteUnixPath}.
*
* @param rawConfiguration raw configuration data
* @return the set of parsed volumes.
* @throws InvalidContainerVolumeException if {@code volumes} are not valid absolute Unix paths
*/
@VisibleForTesting
static Set<AbsoluteUnixPath> getVolumesSet(RawConfiguration rawConfiguration) throws InvalidContainerVolumeException {
Set<AbsoluteUnixPath> volumes = new HashSet<>();
for (String path : rawConfiguration.getVolumes()) {
try {
AbsoluteUnixPath absoluteUnixPath = AbsoluteUnixPath.get(path);
volumes.add(absoluteUnixPath);
} catch (IllegalArgumentException exception) {
throw new InvalidContainerVolumeException(path, path, exception);
}
}
return volumes;
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class PluginConfigurationProcessor method addJvmArgFilesLayer.
@VisibleForTesting
static void addJvmArgFilesLayer(RawConfiguration rawConfiguration, ProjectProperties projectProperties, JibContainerBuilder jibContainerBuilder, String classpath, String mainClass) throws IOException, InvalidAppRootException {
Path projectCache = projectProperties.getDefaultCacheDirectory();
Path classpathFile = projectCache.resolve(JIB_CLASSPATH_FILE);
Path mainClassFile = projectCache.resolve(JIB_MAIN_CLASS_FILE);
// It's perfectly fine to always generate a new temp file or rewrite an existing file. However,
// fixing the source file path and preserving the file timestamp prevents polluting the Jib
// layer cache space by not creating new cache selectors every time. (Note, however, creating
// new selectors does not affect correctness at all.)
writeFileConservatively(classpathFile, classpath);
writeFileConservatively(mainClassFile, mainClass);
AbsoluteUnixPath appRoot = getAppRootChecked(rawConfiguration, projectProperties);
jibContainerBuilder.addFileEntriesLayer(FileEntriesLayer.builder().setName(LayerType.JVM_ARG_FILES.getName()).addEntry(classpathFile, appRoot.resolve(JIB_CLASSPATH_FILE)).addEntry(mainClassFile, appRoot.resolve(JIB_MAIN_CLASS_FILE)).build());
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project geronimo-arthur by apache.
the class JibMojo method createOthersLayer.
private FileEntriesLayer createOthersLayer() {
final FileEntriesLayer.Builder builder = FileEntriesLayer.builder().setName("Others");
otherFiles.stream().map(File::toPath).forEach(f -> {
final AbsoluteUnixPath containerPath = AbsoluteUnixPath.get(project.getBasedir().toPath().relativize(f).toString());
if (containerPath.toString().contains("..")) {
throw new IllegalArgumentException("You can only include files included in basedir");
}
try {
if (Files.isDirectory(f)) {
builder.addEntryRecursive(f, containerPath, (l, c) -> FilePermissions.DEFAULT_FILE_PERMISSIONS, (l, c) -> {
try {
return getTimestamp(l);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
} else {
builder.addEntry(f, containerPath, FilePermissions.DEFAULT_FILE_PERMISSIONS, getTimestamp(f));
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
return builder.build();
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jkube by eclipse.
the class JibServiceUtil method layers.
@Nonnull
public static List<FileEntriesLayer> layers(BuildDirs buildDirs, Map<Assembly, List<AssemblyFileEntry>> layers) {
final List<FileEntriesLayer> fileEntriesLayers = new ArrayList<>();
for (Map.Entry<Assembly, List<AssemblyFileEntry>> layer : layers.entrySet()) {
final FileEntriesLayer.Builder fel = FileEntriesLayer.builder();
final String layerId = layer.getKey().getId();
final Path outputPath;
if (StringUtils.isBlank(layerId)) {
outputPath = buildDirs.getOutputDirectory().toPath();
} else {
fel.setName(layerId);
outputPath = new File(buildDirs.getOutputDirectory(), layerId).toPath();
}
for (AssemblyFileEntry afe : layer.getValue()) {
final Path source = afe.getSource().toPath();
final AbsoluteUnixPath target = AbsoluteUnixPath.get(StringUtils.prependIfMissing(FilenameUtils.separatorsToUnix(outputPath.relativize(afe.getDest().toPath()).normalize().toString()), "/"));
final FilePermissions permissions = StringUtils.isNotBlank(afe.getFileMode()) ? FilePermissions.fromOctalString(StringUtils.right(afe.getFileMode(), 3)) : DEFAULT_FILE_PERMISSIONS_PROVIDER.get(source, target);
fel.addEntry(source, target, permissions);
}
fileEntriesLayers.add(fel.build());
}
return fileEntriesLayers;
}
Aggregations