From ad49bf98ddbce20cf3f23bdf15ce7653a95a4260 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Sat, 20 Jan 2024 16:41:24 +0100 Subject: [PATCH] Only store necessary layers in Oci/DistributionRegistryDataTask --- .../gradle/oci/DistributionRegistryDataTask.kt | 16 +++++++++------- .../sgtsilvio/gradle/oci/OciRegistryDataTask.kt | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/DistributionRegistryDataTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/DistributionRegistryDataTask.kt index daaf769b..d5510e38 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/DistributionRegistryDataTask.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/DistributionRegistryDataTask.kt @@ -26,12 +26,12 @@ abstract class DistributionRegistryDataTask : OciImagesInputTask() { val registryDataDirectory = registryDataDirectory.get().asFile.toPath().ensureEmptyDirectory() val blobsDirectory = registryDataDirectory.resolve("blobs").createDirectory() val repositoriesDirectory = registryDataDirectory.resolve("repositories").createDirectory() - - for ((digest, layer) in digestToLayer) { - blobsDirectory.resolveDigestDataFile(digest).createLinkPointingTo(layer.toPath()) - } + val layerDigests = mutableSetOf() for ((resolvedComponent, imageReferences) in resolvedComponentToImageReferences) { - writeImage(resolvedComponent, imageReferences, blobsDirectory, repositoriesDirectory) + writeImage(resolvedComponent, imageReferences, blobsDirectory, repositoriesDirectory, layerDigests) + } + for (digest in layerDigests) { + blobsDirectory.resolveDigestDataFile(digest).createLinkPointingTo(digestToLayer[digest]!!.toPath()) } } @@ -40,6 +40,7 @@ abstract class DistributionRegistryDataTask : OciImagesInputTask() { imageReferences: Set, blobsDirectory: Path, repositoriesDirectory: Path, + layerDigests: MutableSet, ) { val manifests = mutableListOf>() val blobDigests = mutableSetOf() @@ -47,8 +48,9 @@ abstract class DistributionRegistryDataTask : OciImagesInputTask() { val bundlesForPlatform = resolvedComponent.collectBundlesForPlatform(platform).map { it.bundle } for (bundle in bundlesForPlatform) { for (layer in bundle.layers) { - layer.descriptor?.let { - blobDigests += it.digest + layer.descriptor?.let { (_, digest) -> + layerDigests += digest + blobDigests += digest } } } diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt index 613ca82e..e78d403f 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt @@ -27,12 +27,12 @@ abstract class OciRegistryDataTask : OciImagesInputTask() { val registryDataDirectory = registryDataDirectory.get().asFile.toPath().ensureEmptyDirectory() val blobsDirectory = registryDataDirectory.resolve("blobs").createDirectory() val repositoriesDirectory = registryDataDirectory.resolve("repositories").createDirectory() - - for ((digest, layer) in digestToLayer) { - blobsDirectory.resolveDigestFile(digest).createLinkPointingTo(layer.toPath()) - } + val layerDigests = mutableSetOf() for ((resolvedComponent, imageReferences) in resolvedComponentToImageReferences) { - writeImage(resolvedComponent, imageReferences, blobsDirectory, repositoriesDirectory) + writeImage(resolvedComponent, imageReferences, blobsDirectory, repositoriesDirectory, layerDigests) + } + for (digest in layerDigests) { + blobsDirectory.resolveDigestFile(digest).createLinkPointingTo(digestToLayer[digest]!!.toPath()) } } @@ -41,6 +41,7 @@ abstract class OciRegistryDataTask : OciImagesInputTask() { imageReferences: Set, blobsDirectory: Path, repositoriesDirectory: Path, + layerDigests: MutableSet, ) { val manifests = mutableListOf>() val blobDigests = mutableSetOf() @@ -48,8 +49,9 @@ abstract class OciRegistryDataTask : OciImagesInputTask() { val bundlesForPlatform = resolvedComponent.collectBundlesForPlatform(platform).map { it.bundle } for (bundle in bundlesForPlatform) { for (layer in bundle.layers) { - layer.descriptor?.let { - blobDigests += it.digest + layer.descriptor?.let { (_, digest) -> + layerDigests += digest + blobDigests += digest } } }