Search in sources :

Example 21 with Containerizer

use of com.google.cloud.tools.jib.api.Containerizer in project quarkus by quarkusio.

the class JibProcessor method containerize.

private JibContainer containerize(ContainerImageConfig containerImageConfig, JibConfig jibConfig, ContainerImageInfoBuildItem containerImage, JibContainerBuilder jibContainerBuilder, boolean pushRequested) {
    Containerizer containerizer = createContainerizer(containerImageConfig, jibConfig, containerImage, pushRequested);
    for (String additionalTag : containerImage.getAdditionalTags()) {
        containerizer.withAdditionalTag(additionalTag);
    }
    String previousContextStorageSysProp = null;
    try {
        // Jib uses the Google HTTP Client under the hood which attempts to record traces via OpenCensus which is wired
        // to delegate to OpenTelemetry.
        // This can lead to problems with the Quarkus OpenTelemetry extension which expects Vert.x to be running,
        // something that is not the case at build time, see https://github.com/quarkusio/quarkus/issues/22864.
        previousContextStorageSysProp = System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP, "default");
        JibContainer container = jibContainerBuilder.containerize(containerizer);
        log.infof("%s container image %s (%s)\n", containerImageConfig.isPushExplicitlyEnabled() ? "Pushed" : "Created", container.getTargetImage(), container.getDigest());
        return container;
    } catch (Exception e) {
        throw new RuntimeException("Unable to create container image", e);
    } finally {
        if (previousContextStorageSysProp == null) {
            System.clearProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP);
        } else {
            System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP, previousContextStorageSysProp);
        }
    }
}
Also used : JibContainer(com.google.cloud.tools.jib.api.JibContainer) Containerizer(com.google.cloud.tools.jib.api.Containerizer) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 22 with Containerizer

use of com.google.cloud.tools.jib.api.Containerizer in project geronimo-arthur by apache.

the class JibMojo method execute.

@Override
public void execute() {
    final JibContainerBuilder prepared = prepare();
    withExecutor(es -> {
        try {
            final Containerizer containerizer = createContainer();
            final JibContainer container = prepared.containerize(configure(containerizer, es));
            if (propertiesPrefix != null) {
                project.getProperties().setProperty(propertiesPrefix + "image.imageId", container.getImageId().getHash());
                project.getProperties().setProperty(propertiesPrefix + "image.digest", container.getDigest().getHash());
            }
            getLog().info("Built '" + to + "'");
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (final RegistryException | IOException | CacheDirectoryCreationException | ExecutionException | InvalidImageReferenceException e) {
            throw new IllegalStateException(e);
        }
    });
}
Also used : CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) JibContainer(com.google.cloud.tools.jib.api.JibContainer) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Containerizer(com.google.cloud.tools.jib.api.Containerizer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RegistryException(com.google.cloud.tools.jib.api.RegistryException)

Aggregations

Containerizer (com.google.cloud.tools.jib.api.Containerizer)22 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)16 LogEvent (com.google.cloud.tools.jib.api.LogEvent)11 Path (java.nio.file.Path)11 ImageReference (com.google.cloud.tools.jib.api.ImageReference)10 Files (java.nio.file.Files)9 Optional (java.util.Optional)9 JibContainer (com.google.cloud.tools.jib.api.JibContainer)8 ConsoleLogger (com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger)8 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)7 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)7 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)7 List (java.util.List)7 Future (java.util.concurrent.Future)7 CliLogger (com.google.cloud.tools.jib.cli.logging.CliLogger)6 GlobalConfig (com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig)6 SingleThreadedExecutor (com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Multimaps (com.google.common.collect.Multimaps)6 Futures (com.google.common.util.concurrent.Futures)6