Search in sources :

Example 1 with PathsUtil.findMainSourcesRoot

use of io.quarkus.container.util.PathsUtil.findMainSourcesRoot in project quarkus by quarkusio.

the class JibProcessor method handleExtraFiles.

/**
 * Allow users to have custom files in {@code src/main/jib} that will be copied into the built container's file system
 * in same manner as the Jib Maven and Gradle plugins do.
 * For example, {@code src/main/jib/foo/bar} would add {@code /foo/bar} into the container filesystem.
 *
 * See: https://github.com/GoogleContainerTools/jib/blob/v0.15.0-core/docs/faq.md#can-i-add-a-custom-directory-to-the-image
 */
private void handleExtraFiles(OutputTargetBuildItem outputTarget, JibContainerBuilder jibContainerBuilder) {
    Path outputDirectory = outputTarget.getOutputDirectory();
    PathsUtil.findMainSourcesRoot(outputTarget.getOutputDirectory());
    Map.Entry<Path, Path> mainSourcesRoot = findMainSourcesRoot(outputDirectory);
    if (mainSourcesRoot == null) {
        // this should never happen
        return;
    }
    Path jibFilesRoot = mainSourcesRoot.getKey().resolve("jib");
    if (!jibFilesRoot.toFile().exists()) {
        return;
    }
    FileEntriesLayer extraFilesLayer;
    try {
        extraFilesLayer = ContainerBuilderHelper.extraDirectoryLayerConfiguration(jibFilesRoot, AbsoluteUnixPath.get("/"), Collections.emptyMap(), (localPath, ignored2) -> {
            try {
                return Files.getLastModifiedTime(localPath).toInstant();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
        jibContainerBuilder.addFileEntriesLayer(extraFilesLayer);
    } catch (IOException e) {
        throw new UncheckedIOException("Unable to add extra files in '" + jibFilesRoot.toAbsolutePath().toString() + "' to the container", e);
    }
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) UpxCompressedBuildItem(io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem) Port(com.google.cloud.tools.jib.api.buildplan.Port) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) DirectoryStream(java.nio.file.DirectoryStream) Map(java.util.Map) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ZipUtils(io.quarkus.fs.util.ZipUtils) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) PathsUtil.findMainSourcesRoot(io.quarkus.container.util.PathsUtil.findMainSourcesRoot) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) Set(java.util.Set) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) Instant(java.time.Instant) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) NativeBinaryUtil(io.quarkus.container.image.deployment.util.NativeBinaryUtil) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) AppCDSResultBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem) AppCDSContainerImageBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSContainerImageBuildItem) ContainerRuntimeUtil(io.quarkus.runtime.util.ContainerRuntimeUtil) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Version(io.quarkus.builder.Version) Logger(org.jboss.logging.Logger) JibContainer(com.google.cloud.tools.jib.api.JibContainer) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) HashMap(java.util.HashMap) EnablementUtil.pushContainerImageNeeded(io.quarkus.container.image.deployment.util.EnablementUtil.pushContainerImageNeeded) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep) Jib(com.google.cloud.tools.jib.api.Jib) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) PathsUtil(io.quarkus.container.util.PathsUtil) EnablementUtil.buildContainerImageNeeded(io.quarkus.container.image.deployment.util.EnablementUtil.buildContainerImageNeeded) Comparator(java.util.Comparator) Collections(java.util.Collections) MainClassBuildItem(io.quarkus.deployment.builditem.MainClassBuildItem) JarResultBuildStep(io.quarkus.deployment.pkg.steps.JarResultBuildStep) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Containerizer (com.google.cloud.tools.jib.api.Containerizer)1 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)1 ImageReference (com.google.cloud.tools.jib.api.ImageReference)1 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)1 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)1 Jib (com.google.cloud.tools.jib.api.Jib)1 JibContainer (com.google.cloud.tools.jib.api.JibContainer)1 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)1 LogEvent (com.google.cloud.tools.jib.api.LogEvent)1 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)1 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)1 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)1 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)1 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)1 Port (com.google.cloud.tools.jib.api.buildplan.Port)1 CredentialRetrieverFactory (com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory)1 Version (io.quarkus.builder.Version)1 ContainerImageConfig (io.quarkus.container.image.deployment.ContainerImageConfig)1 EnablementUtil.buildContainerImageNeeded (io.quarkus.container.image.deployment.util.EnablementUtil.buildContainerImageNeeded)1 EnablementUtil.pushContainerImageNeeded (io.quarkus.container.image.deployment.util.EnablementUtil.pushContainerImageNeeded)1