Search in sources :

Example 46 with ImageReference

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

the class JibProcessor method createContainerizer.

private Containerizer createContainerizer(ContainerImageConfig containerImageConfig, JibConfig jibConfig, ContainerImageInfoBuildItem containerImage, boolean pushRequested) {
    Containerizer containerizer;
    ImageReference imageReference = ImageReference.of(containerImage.getRegistry().orElse(null), containerImage.getRepository(), containerImage.getTag());
    if (pushRequested || containerImageConfig.isPushExplicitlyEnabled()) {
        if (!containerImageConfig.registry.isPresent()) {
            log.info("No container image registry was set, so 'docker.io' will be used");
        }
        RegistryImage registryImage = toRegistryImage(imageReference, containerImageConfig.username, containerImageConfig.password);
        containerizer = Containerizer.to(registryImage);
    } else {
        DockerDaemonImage dockerDaemonImage = DockerDaemonImage.named(imageReference);
        Optional<String> dockerConfigExecutableName = ConfigProvider.getConfig().getOptionalValue("quarkus.docker.executable-name", String.class);
        Optional<String> jibConfigExecutableName = jibConfig.dockerExecutableName;
        if (jibConfigExecutableName.isPresent()) {
            dockerDaemonImage.setDockerExecutable(Paths.get(jibConfigExecutableName.get()));
        } else if (dockerConfigExecutableName.isPresent()) {
            dockerDaemonImage.setDockerExecutable(Paths.get(dockerConfigExecutableName.get()));
        } else {
            // detect the container runtime instead of falling back to 'docker' as the default
            ContainerRuntimeUtil.ContainerRuntime detectedContainerRuntime = ContainerRuntimeUtil.detectContainerRuntime();
            log.infof("Using %s to run the native image builder", detectedContainerRuntime.getExecutableName());
            dockerDaemonImage.setDockerExecutable(Paths.get(detectedContainerRuntime.getExecutableName()));
        }
        containerizer = Containerizer.to(dockerDaemonImage);
    }
    containerizer.setToolName("Quarkus");
    containerizer.setToolVersion(Version.getVersion());
    containerizer.addEventHandler(LogEvent.class, (e) -> {
        if (!e.getMessage().isEmpty()) {
            log.log(toJBossLoggingLevel(e.getLevel()), e.getMessage());
        }
    });
    containerizer.setAllowInsecureRegistries(containerImageConfig.insecure);
    containerizer.setAlwaysCacheBaseImage(jibConfig.alwaysCacheBaseImage);
    containerizer.setOfflineMode(jibConfig.offlineMode);
    return containerizer;
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) Containerizer(com.google.cloud.tools.jib.api.Containerizer) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Aggregations

ImageReference (com.google.cloud.tools.jib.api.ImageReference)46 Test (org.junit.Test)26 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)22 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)22 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)14 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)12 Image (com.google.cloud.tools.jib.image.Image)12 Path (java.nio.file.Path)12 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)10 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)10 Containerizer (com.google.cloud.tools.jib.api.Containerizer)9 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)9 ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)8 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)7 TarImage (com.google.cloud.tools.jib.api.TarImage)6 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)6 List (java.util.List)6 Credential (com.google.cloud.tools.jib.api.Credential)4 LogEvent (com.google.cloud.tools.jib.api.LogEvent)4