Search in sources :

Example 1 with ContainerImageLabelBuildItem

use of io.quarkus.container.spi.ContainerImageLabelBuildItem in project quarkus by quarkusio.

the class JibProcessor method createContainerBuilderFromLegacyJar.

private JibContainerBuilder createContainerBuilderFromLegacyJar(String baseJvmImage, JibConfig jibConfig, ContainerImageConfig containerImageConfig, JarBuildItem sourceJarBuildItem, OutputTargetBuildItem outputTargetBuildItem, MainClassBuildItem mainClassBuildItem, List<ContainerImageLabelBuildItem> containerImageLabels) {
    try {
        // not ideal since this has been previously zipped - we would like to just reuse it
        Path classesDir = outputTargetBuildItem.getOutputDirectory().resolve("jib");
        ZipUtils.unzip(sourceJarBuildItem.getPath(), classesDir);
        JavaContainerBuilder javaContainerBuilder = JavaContainerBuilder.from(toRegistryImage(ImageReference.parse(baseJvmImage), jibConfig.baseRegistryUsername, jibConfig.baseRegistryPassword)).addResources(classesDir, IS_CLASS_PREDICATE.negate()).addClasses(classesDir, IS_CLASS_PREDICATE);
        // when there is no custom entry point, we just set everything up for a regular java run
        if (!jibConfig.jvmEntrypoint.isPresent()) {
            javaContainerBuilder.addJvmFlags(determineEffectiveJvmArguments(jibConfig, Optional.empty())).setMainClass(mainClassBuildItem.getClassName());
        }
        if (sourceJarBuildItem.getLibraryDir() != null) {
            try (Stream<Path> dependenciesPaths = Files.list(sourceJarBuildItem.getLibraryDir())) {
                javaContainerBuilder.addDependencies(dependenciesPaths.filter(p -> Files.isRegularFile(p) && p.getFileName().toString().endsWith(".jar")).sorted(Comparator.comparing(Path::getFileName)).collect(Collectors.toList()));
            }
        }
        JibContainerBuilder jibContainerBuilder = javaContainerBuilder.toContainerBuilder().setEnvironment(getEnvironmentVariables(jibConfig)).setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels));
        if (jibConfig.useCurrentTimestamp) {
            jibContainerBuilder.setCreationTime(Instant.now());
        }
        if (jibConfig.jvmEntrypoint.isPresent()) {
            jibContainerBuilder.setEntrypoint(jibConfig.jvmEntrypoint.get());
        }
        return jibContainerBuilder;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (InvalidImageReferenceException e) {
        throw new RuntimeException(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) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) UncheckedIOException(java.io.UncheckedIOException) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with ContainerImageLabelBuildItem

use of io.quarkus.container.spi.ContainerImageLabelBuildItem in project quarkus by quarkusio.

the class VanillaKubernetesProcessor method createLabels.

@BuildStep
public void createLabels(KubernetesConfig config, BuildProducer<KubernetesLabelBuildItem> labels, BuildProducer<ContainerImageLabelBuildItem> imageLabels) {
    config.labels.forEach((k, v) -> {
        labels.produce(new KubernetesLabelBuildItem(k, v, KUBERNETES));
        imageLabels.produce(new ContainerImageLabelBuildItem(k, v));
    });
}
Also used : KubernetesLabelBuildItem(io.quarkus.kubernetes.spi.KubernetesLabelBuildItem) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with ContainerImageLabelBuildItem

use of io.quarkus.container.spi.ContainerImageLabelBuildItem in project quarkus by quarkusio.

the class JibProcessor method allLabels.

private Map<String, String> allLabels(JibConfig jibConfig, ContainerImageConfig containerImageConfig, List<ContainerImageLabelBuildItem> containerImageLabels) {
    if (jibConfig.labels.isEmpty() && containerImageLabels.isEmpty() && containerImageConfig.labels.isEmpty()) {
        return Collections.emptyMap();
    }
    final Map<String, String> allLabels = new HashMap<>(jibConfig.labels);
    allLabels.putAll(containerImageConfig.labels);
    for (ContainerImageLabelBuildItem containerImageLabel : containerImageLabels) {
        // we want the user supplied labels to take precedence so the user can override labels generated from other extensions if desired
        allLabels.putIfAbsent(containerImageLabel.getName(), containerImageLabel.getValue());
    }
    return allLabels;
}
Also used : HashMap(java.util.HashMap) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem)

Example 4 with ContainerImageLabelBuildItem

use of io.quarkus.container.spi.ContainerImageLabelBuildItem in project quarkus by quarkusio.

the class KindProcessor method createLabels.

@BuildStep
public void createLabels(KubernetesConfig config, BuildProducer<KubernetesLabelBuildItem> labels, BuildProducer<ContainerImageLabelBuildItem> imageLabels) {
    config.getLabels().forEach((k, v) -> {
        labels.produce(new KubernetesLabelBuildItem(k, v, KIND));
        imageLabels.produce(new ContainerImageLabelBuildItem(k, v));
    });
}
Also used : KubernetesLabelBuildItem(io.quarkus.kubernetes.spi.KubernetesLabelBuildItem) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 5 with ContainerImageLabelBuildItem

use of io.quarkus.container.spi.ContainerImageLabelBuildItem in project quarkus by quarkusio.

the class MinikubeProcessor method createLabels.

@BuildStep
public void createLabels(KubernetesConfig config, BuildProducer<KubernetesLabelBuildItem> labels, BuildProducer<ContainerImageLabelBuildItem> imageLabels) {
    config.getLabels().forEach((k, v) -> {
        labels.produce(new KubernetesLabelBuildItem(k, v, MINIKUBE));
        imageLabels.produce(new ContainerImageLabelBuildItem(k, v));
    });
}
Also used : KubernetesLabelBuildItem(io.quarkus.kubernetes.spi.KubernetesLabelBuildItem) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

ContainerImageLabelBuildItem (io.quarkus.container.spi.ContainerImageLabelBuildItem)5 BuildStep (io.quarkus.deployment.annotations.BuildStep)4 KubernetesLabelBuildItem (io.quarkus.kubernetes.spi.KubernetesLabelBuildItem)3 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