Search in sources :

Example 1 with ImageToJsonTranslator

use of com.google.cloud.tools.jib.image.json.ImageToJsonTranslator in project jib by google.

the class BuildAndPushContainerConfigurationStep method afterBaseImageLayerFuturesFuture.

/**
 * Depends on {@code pushAuthorizationFuture}, {@code pullBaseImageLayerFuturesFuture.get()}, and
 * {@code buildApplicationLayerFutures}.
 */
private BlobDescriptor afterBaseImageLayerFuturesFuture() throws ExecutionException, InterruptedException, LayerPropertyNotFoundException, IOException, RegistryException {
    try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
        RegistryClient registryClient = new RegistryClient(NonBlockingFutures.get(pushAuthorizationFuture), buildConfiguration.getTargetRegistry(), buildConfiguration.getTargetRepository()).setTimer(timer);
        // Constructs the image.
        Image image = new Image();
        for (Future<CachedLayer> cachedLayerFuture : NonBlockingFutures.get(pullBaseImageLayerFuturesFuture)) {
            image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
        }
        for (Future<CachedLayer> cachedLayerFuture : buildApplicationLayerFutures) {
            image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
        }
        image.setEnvironment(buildConfiguration.getEnvironment());
        image.setEntrypoint(entrypoint);
        ImageToJsonTranslator imageToJsonTranslator = new ImageToJsonTranslator(image);
        // Gets the container configuration content descriptor.
        Blob containerConfigurationBlob = imageToJsonTranslator.getContainerConfigurationBlob();
        CountingDigestOutputStream digestOutputStream = new CountingDigestOutputStream(ByteStreams.nullOutputStream());
        containerConfigurationBlob.writeTo(digestOutputStream);
        BlobDescriptor containerConfigurationBlobDescriptor = digestOutputStream.toBlobDescriptor();
        timer.lap("Pushing container configuration " + containerConfigurationBlobDescriptor.getDigest());
        // TODO: Use PushBlobStep.
        // Pushes the container configuration.
        registryClient.pushBlob(containerConfigurationBlobDescriptor.getDigest(), containerConfigurationBlob);
        return containerConfigurationBlobDescriptor;
    }
}
Also used : CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) Blob(com.google.cloud.tools.jib.blob.Blob) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) Timer(com.google.cloud.tools.jib.Timer) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) Image(com.google.cloud.tools.jib.image.Image)

Example 2 with ImageToJsonTranslator

use of com.google.cloud.tools.jib.image.json.ImageToJsonTranslator in project jib by google.

the class PushImageStep method afterPushBaseImageLayerFuturesFuture.

/**
 * Depends on {@code pushAuthorizationFuture}, {@code pushBaseImageLayerFuturesFuture.get()},
 * {@code pushApplicationLayerFutures}, and (@code
 * containerConfigurationBlobDescriptorFutureFuture.get()}.
 */
private Void afterPushBaseImageLayerFuturesFuture() throws IOException, RegistryException, ExecutionException, InterruptedException, LayerPropertyNotFoundException {
    try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
        RegistryClient registryClient = new RegistryClient(NonBlockingFutures.get(pushAuthorizationFuture), buildConfiguration.getTargetRegistry(), buildConfiguration.getTargetRepository());
        // TODO: Consolidate with BuildAndPushContainerConfigurationStep.
        // Constructs the image.
        Image image = new Image();
        for (Future<CachedLayer> cachedLayerFuture : NonBlockingFutures.get(pullBaseImageLayerFuturesFuture)) {
            image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
        }
        for (Future<CachedLayer> cachedLayerFuture : buildApplicationLayerFutures) {
            image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
        }
        ImageToJsonTranslator imageToJsonTranslator = new ImageToJsonTranslator(image);
        // Pushes the image manifest.
        BuildableManifestTemplate manifestTemplate = imageToJsonTranslator.getManifestTemplate(buildConfiguration.getTargetFormat(), NonBlockingFutures.get(NonBlockingFutures.get(containerConfigurationBlobDescriptorFutureFuture)));
        registryClient.pushManifest(manifestTemplate, buildConfiguration.getTargetTag());
    }
    return null;
}
Also used : Timer(com.google.cloud.tools.jib.Timer) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) Image(com.google.cloud.tools.jib.image.Image) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)

Aggregations

Timer (com.google.cloud.tools.jib.Timer)2 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)2 Image (com.google.cloud.tools.jib.image.Image)2 ImageToJsonTranslator (com.google.cloud.tools.jib.image.json.ImageToJsonTranslator)2 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)2 Blob (com.google.cloud.tools.jib.blob.Blob)1 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)1 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)1 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)1