Skip to content

Instantly share code, notes, and snippets.

View ArturSkowronski's full-sized avatar

Artur Skowronski ArturSkowronski

View GitHub Profile
class PushLayersStep
implements AsyncStep<ImmutableList<AsyncStep<PushBlobStep>>>,
Callable<ImmutableList<AsyncStep<PushBlobStep>>> {
/*(...)*/
public ImmutableList<AsyncStep<PushBlobStep>> call() throws ExecutionException {
/*(...)*/
ImmutableList<? extends AsyncStep<? extends CachedLayer>> cachedLayerSteps =
NonBlockingSteps.get(cachedLayerStepsStep);
// Constructs a PushBlobStep for each layer.
public class RegistryClient {
/*(...)*/
public Void pullBlob(DescriptorDigest blobDigest, OutputStream destinationOutputStream)
throws RegistryException, IOException {
BlobPuller blobPuller =
new BlobPuller(registryEndpointRequestProperties, blobDigest, destinationOutputStream);
return callRegistryEndpoint(blobPuller);
}
/*(...)*/
}
class PullAndCacheBaseImageLayerStep implements AsyncStep<CachedLayer>, Callable<CachedLayer> {
/*(...)*/
public CachedLayer call() throws IOException, RegistryException {
/*(...)*/
RegistryClient registryClient = /*(...)*/;
// Checks if the layer already exists in the cache.
CachedLayer cachedLayer = new CacheReader(cache).getLayer(layerDigest);
if (cachedLayer != null) {
return cachedLayer;
@Override
public ImmutableList<PullAndCacheBaseImageLayerStep> call()/*(...)*/ {
BaseImageWithAuthorization pullBaseImageStepResult = NonBlockingSteps.get(pullBaseImageStep);
/*(...)*/
ImmutableList.Builder<PullAndCacheBaseImageLayerStep> pullAndCacheBaseImageLayerStepsBuilder =
ImmutableList.builderWithExpectedSize(baseImageLayers.size());
for (Layer layer : baseImageLayers) {
pullAndCacheBaseImageLayerStepsBuilder.add(
new PullAndCacheBaseImageLayerStep(
listeningExecutorService,
@Override
public ImmutableList<PullAndCacheBaseImageLayerStep> call() /*(...)*/ {
/*(...)*/
ImmutableList<Layer> baseImageLayers = pullBaseImageStepResult.getBaseImage().getLayers();
/*(...)*/
}
}
public static Image<Layer> toImage(/*(...)*/) /*(...)*/ {
/*(...)*/
if (containerConfigurationTemplate.getContainerEntrypoint() != null) {
imageBuilder.setEntrypoint(containerConfigurationTemplate.getContainerEntrypoint());
}
if (containerConfigurationTemplate.getContainerCmd() != null) {
imageBuilder.setJavaArguments(containerConfigurationTemplate.getContainerCmd());
}
public static Image<Layer> toImage(/*(...)*/) /*(...)*/ {
/*(...)*/
List<DescriptorDigest> diffIds = containerConfigurationTemplate.getDiffIds();
if (layers.size() != diffIds.size()) {
throw new LayerCountMismatchException(
"Mismatch between image manifest and container configuration");
}
Image.Builder<Layer> imageBuilder = Image.builder();
public static Image<Layer> toImage(
BuildableManifestTemplate manifestTemplate,
ContainerConfigurationTemplate containerConfigurationTemplate) /*(...)*/ {
List<ReferenceNoDiffIdLayer> layers = new ArrayList<>();
for (BuildableManifestTemplate.ContentDescriptorTemplate layerObjectTemplate :
manifestTemplate.getLayers()) {
/*(...)*/
layers.add(
new ReferenceNoDiffIdLayer(
new BlobDescriptor(layerObjectTemplate.getSize(), layerObjectTemplate.getDigest())));
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
{
"mediaType": "application/vnd.docker.image.manifest.v2+json",
"size": 7143,
"digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f",
"platform": {
"architecture": "ppc64le",
private Image<Layer> pullBaseImage(@Nullable Authorization registryCredentials)/*(...)*/ {
/*(...)*/
// TODO: Make schema version be enum.
switch (manifestTemplate.getSchemaVersion()) {
/*(...)*/
case 2:
V22ManifestTemplate v22ManifestTemplate = (V22ManifestTemplate) manifestTemplate;
/*(...)*/
ByteArrayOutputStream containerConfigurationOutputStream = new ByteArrayOutputStream();