use of com.google.cloud.tools.jib.image.Image 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;
}
}
use of com.google.cloud.tools.jib.image.Image in project jib by google.
the class BuildImageSteps method run.
public void run() throws InterruptedException, ExecutionException, CacheMetadataCorruptedException, IOException, CacheDirectoryNotOwnedException {
List<String> entrypoint = EntrypointBuilder.makeEntrypoint(sourceFilesConfiguration, buildConfiguration.getJvmFlags(), buildConfiguration.getMainClass());
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
try (Timer timer2 = timer.subTimer("Initializing cache")) {
ListeningExecutorService listeningExecutorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
try (Caches caches = cachesInitializer.init()) {
Cache baseLayersCache = caches.getBaseCache();
Cache applicationLayersCache = caches.getApplicationCache();
timer2.lap("Setting up credential retrieval");
ListenableFuture<Authorization> retrieveTargetRegistryCredentialsFuture = listeningExecutorService.submit(new RetrieveRegistryCredentialsStep(buildConfiguration, buildConfiguration.getTargetRegistry()));
ListenableFuture<Authorization> retrieveBaseImageRegistryCredentialsFuture = listeningExecutorService.submit(new RetrieveRegistryCredentialsStep(buildConfiguration, buildConfiguration.getBaseImageRegistry()));
timer2.lap("Setting up image push authentication");
// Authenticates push.
ListenableFuture<Authorization> authenticatePushFuture = Futures.whenAllSucceed(retrieveTargetRegistryCredentialsFuture).call(new AuthenticatePushStep(buildConfiguration, retrieveTargetRegistryCredentialsFuture), listeningExecutorService);
timer2.lap("Setting up image pull authentication");
// Authenticates base image pull.
ListenableFuture<Authorization> authenticatePullFuture = Futures.whenAllSucceed(retrieveBaseImageRegistryCredentialsFuture).call(new AuthenticatePullStep(buildConfiguration, retrieveBaseImageRegistryCredentialsFuture), listeningExecutorService);
timer2.lap("Setting up base image pull");
// Pulls the base image.
ListenableFuture<Image> pullBaseImageFuture = Futures.whenAllSucceed(authenticatePullFuture).call(new PullBaseImageStep(buildConfiguration, authenticatePullFuture), listeningExecutorService);
timer2.lap("Setting up base image layer pull");
// Pulls and caches the base image layers.
ListenableFuture<List<ListenableFuture<CachedLayer>>> pullBaseImageLayerFuturesFuture = Futures.whenAllSucceed(pullBaseImageFuture).call(new PullAndCacheBaseImageLayersStep(buildConfiguration, baseLayersCache, listeningExecutorService, authenticatePullFuture, pullBaseImageFuture), listeningExecutorService);
timer2.lap("Setting up base image layer push");
// Pushes the base image layers.
ListenableFuture<List<ListenableFuture<Void>>> pushBaseImageLayerFuturesFuture = Futures.whenAllSucceed(pullBaseImageLayerFuturesFuture).call(new PushLayersStep(buildConfiguration, listeningExecutorService, authenticatePushFuture, pullBaseImageLayerFuturesFuture), listeningExecutorService);
timer2.lap("Setting up build application layers");
// Builds the application layers.
List<ListenableFuture<CachedLayer>> buildAndCacheApplicationLayerFutures = new BuildAndCacheApplicationLayersStep(buildConfiguration, sourceFilesConfiguration, applicationLayersCache, listeningExecutorService).call();
timer2.lap("Setting up container configuration push");
// Builds and pushes the container configuration.
ListenableFuture<ListenableFuture<BlobDescriptor>> buildAndPushContainerConfigurationFutureFuture = Futures.whenAllSucceed(pullBaseImageLayerFuturesFuture).call(new BuildAndPushContainerConfigurationStep(buildConfiguration, listeningExecutorService, authenticatePushFuture, pullBaseImageLayerFuturesFuture, buildAndCacheApplicationLayerFutures, entrypoint), listeningExecutorService);
timer2.lap("Setting up application layer push");
// Pushes the application layers.
List<ListenableFuture<Void>> pushApplicationLayersFuture = new PushLayersStep(buildConfiguration, listeningExecutorService, authenticatePushFuture, Futures.immediateFuture(buildAndCacheApplicationLayerFutures)).call();
timer2.lap("Setting up image manifest push");
// Pushes the new image manifest.
ListenableFuture<Void> pushImageFuture = Futures.whenAllSucceed(pushBaseImageLayerFuturesFuture, buildAndPushContainerConfigurationFutureFuture).call(new PushImageStep(buildConfiguration, listeningExecutorService, authenticatePushFuture, pullBaseImageLayerFuturesFuture, buildAndCacheApplicationLayerFutures, pushBaseImageLayerFuturesFuture, pushApplicationLayersFuture, buildAndPushContainerConfigurationFutureFuture), listeningExecutorService);
timer2.lap("Running push new image");
pushImageFuture.get();
}
}
}
buildConfiguration.getBuildLogger().lifecycle("");
buildConfiguration.getBuildLogger().lifecycle("Container entrypoint set to " + entrypoint);
}
use of com.google.cloud.tools.jib.image.Image 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;
}
Aggregations