Search in sources :

Example 41 with EventHandlers

use of com.google.cloud.tools.jib.event.EventHandlers in project jib by GoogleContainerTools.

the class PlatformChecker method checkManifestPlatform.

/**
 * Assuming the base image is not a manifest list, checks and warns misconfigured platforms.
 *
 * @param buildContext the {@link BuildContext}
 * @param containerConfig container configuration JSON of the base image
 */
static void checkManifestPlatform(BuildContext buildContext, ContainerConfigurationTemplate containerConfig) {
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    Optional<Path> path = buildContext.getBaseImageConfiguration().getTarPath();
    String baseImageName = path.map(Path::toString).orElse(buildContext.getBaseImageConfiguration().getImage().toString());
    Set<Platform> platforms = buildContext.getContainerConfiguration().getPlatforms();
    Verify.verify(!platforms.isEmpty());
    if (platforms.size() != 1) {
        eventHandlers.dispatch(LogEvent.warn("platforms configured, but '" + baseImageName + "' is not a manifest list"));
    } else {
        Platform platform = platforms.iterator().next();
        if (!platform.getArchitecture().equals(containerConfig.getArchitecture()) || !platform.getOs().equals(containerConfig.getOs())) {
            // configure it. Skip reporting to suppress false alarm.
            if (!(platform.getArchitecture().equals("amd64") && platform.getOs().equals("linux"))) {
                String warning = "the configured platform (%s/%s) doesn't match the platform (%s/%s) of the base " + "image (%s)";
                eventHandlers.dispatch(LogEvent.warn(String.format(warning, platform.getArchitecture(), platform.getOs(), containerConfig.getArchitecture(), containerConfig.getOs(), baseImageName)));
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Example 42 with EventHandlers

use of com.google.cloud.tools.jib.event.EventHandlers in project jib by GoogleContainerTools.

the class PushImageStep method call.

@Override
public BuildResult call() throws IOException, RegistryException {
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION);
        ProgressEventDispatcher ignored2 = progressEventDispatcherFactory.create("pushing manifest for " + imageQualifier, 1)) {
        eventHandlers.dispatch(LogEvent.info("Pushing manifest for " + imageQualifier + "..."));
        registryClient.pushManifest(manifestTemplate, imageQualifier);
        return new BuildResult(imageDigest, imageId);
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Aggregations

EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)42 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)24 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)22 Test (org.junit.Test)14 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)10 Image (com.google.cloud.tools.jib.image.Image)10 IOException (java.io.IOException)10 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)8 ImmutableList (com.google.common.collect.ImmutableList)8 Map (java.util.Map)8 RegistryException (com.google.cloud.tools.jib.api.RegistryException)6 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)6 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)6 Cache (com.google.cloud.tools.jib.cache.Cache)6 Allocation (com.google.cloud.tools.jib.event.progress.Allocation)6 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)6 ImageToJsonTranslator (com.google.cloud.tools.jib.image.json.ImageToJsonTranslator)6 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6