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 } } }