From 455325cd2328523ae38e7914fd4eb43bfc71c2aa Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Sat, 20 Jan 2024 17:40:08 +0100 Subject: [PATCH] Revert default OciRegistryStorage to DistributionRegistryStorage reason: the amount of directories is not the important part for efficiency --- .../sgtsilvio/gradle/oci/TestProject.kt | 141 ++++++++++-------- .../oci/DistributionRegistryDataTask.kt | 8 + .../gradle/oci/OciRegistryDataTask.kt | 119 --------------- .../sgtsilvio/gradle/oci/dsl/OciExtension.kt | 4 +- .../oci/internal/dsl/OciExtensionImpl.kt | 6 +- .../internal/dsl/OciTestArgumentProvider.kt | 4 +- 6 files changed, 93 insertions(+), 189 deletions(-) delete mode 100644 src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt diff --git a/src/functionalTest/kotlin/io/github/sgtsilvio/gradle/oci/TestProject.kt b/src/functionalTest/kotlin/io/github/sgtsilvio/gradle/oci/TestProject.kt index 5bf34857..51a6cc64 100644 --- a/src/functionalTest/kotlin/io/github/sgtsilvio/gradle/oci/TestProject.kt +++ b/src/functionalTest/kotlin/io/github/sgtsilvio/gradle/oci/TestProject.kt @@ -165,82 +165,97 @@ internal class TestProject(projectDir: File) { val registryDir = buildDir.resolve("oci/registries/test") val blobsDir = registryDir.resolve("blobs") // @formatter:off - assertTrue(blobsDir.resolve("sha256/1d511796a8d527cf68165c8b95d6606d03c6a30a624d781f8f3682ae14797078").exists()) - assertTrue(blobsDir.resolve("sha256/1efc276f4ff952c055dea726cfc96ec6a4fdb8b62d9eed816bd2b788f2860ad7").exists()) - assertTrue(blobsDir.resolve("sha256/3ba62f2fe51e3304e4c26340567f70a8dfbd4e0c608a2154e174575544aaa3d9").exists()) - assertTrue(blobsDir.resolve("sha256/3e37770490d98f2164cf29b50c7dc209a877d58182ae415540dc99d625e922b0").exists()) - assertTrue(blobsDir.resolve("sha256/4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1").exists()) - assertTrue(blobsDir.resolve("sha256/8b3654c299169c0f815629af51518c775817d09dd04da9a3bfa510cfa63f12bc").exists()) - assertTrue(blobsDir.resolve("sha256/9d19ee268e0d7bcf6716e6658ee1b0384a71d6f2f9aa1ae2085610cf7c7b316f").exists()) - assertTrue(blobsDir.resolve("sha256/12cca292b13cb58fadde25af113ddc4ac3b0c5e39ab3f1290a6ba62ec8237afd").exists()) - assertTrue(blobsDir.resolve("sha256/18c6d4ab63429acdae46f5bc76e27378afaa44b40a746ae2465b3b4684846ef3").exists()) - assertTrue(blobsDir.resolve("sha256/33f5df018e7461c12a9942a1765d92002ac415ceb4cec48020e693c5b9022207").exists()) - assertTrue(blobsDir.resolve("sha256/3573c1225d462a8047deb540a10daffee48c949958f8b8842eaebe050daf48bb").exists()) - assertTrue(blobsDir.resolve("sha256/45953d25a53f34169be70bf8fc143e66c68cc46d47629b1b76b28be22647c9a9").exists()) - assertTrue(blobsDir.resolve("sha256/66b08230f25a80ecfea7a229a734049fc0d9abe01f756f11f922d39357dc487f").exists()) - assertTrue(blobsDir.resolve("sha256/92f85d89e7da0f3af0f527e7300cced784d0ba64249b8c376690599d313cb056").exists()) - assertTrue(blobsDir.resolve("sha256/a2f2f93da48276873890ac821b3c991d53a7e864791aaf82c39b7863c908b93b").exists()) - assertTrue(blobsDir.resolve("sha256/ac9c5946be2a99aca3f2643a8a98f230414662e4ea47e482ccad6bf6b0517657").exists()) - assertTrue(blobsDir.resolve("sha256/ac34a2e0269ced3acc355be706239ee0f3f1e73a035c40dd2fac74827164ee53").exists()) - assertTrue(blobsDir.resolve("sha256/c18c4e0236f2e8bec242432a19cff1d93bbd422b305e6900809fa4fcf0e07e48").exists()) - assertTrue(blobsDir.resolve("sha256/d498448faeaf83b9fa66defd14b2cadc168e211bcb78fb36c748c19b5580b699").exists()) - assertTrue(blobsDir.resolve("sha256/d6ae466d10fc5d00afc56a152620df8477ecd22369053f2514d2ea38ad5ed1fb").exists()) - assertTrue(blobsDir.resolve("sha256/d73cf48caaac2e45ad76a2a9eb3b311d0e4eb1d804e3d2b9cf075a1fa31e6f92").exists()) - assertTrue(blobsDir.resolve("sha256/f2b566cb887b5c06e04f5cd97660a99e73bd52ceb9d72c6db6383ae8470cc4cf").exists()) - assertTrue(blobsDir.resolve("sha256/$expectedJarLayerDigest").exists()) - assertTrue(blobsDir.resolve("sha256/$expectedConfig1Digest").exists()) - assertTrue(blobsDir.resolve("sha256/$expectedConfig2Digest").exists()) - assertTrue(blobsDir.resolve("sha256/$expectedManifest1Digest").exists()) - assertTrue(blobsDir.resolve("sha256/$expectedManifest2Digest").exists()) - assertTrue(blobsDir.resolve("sha256/$expectedIndexDigest").exists()) + assertTrue(blobsDir.resolve("sha256/1d/1d511796a8d527cf68165c8b95d6606d03c6a30a624d781f8f3682ae14797078/data").exists()) + assertTrue(blobsDir.resolve("sha256/1e/1efc276f4ff952c055dea726cfc96ec6a4fdb8b62d9eed816bd2b788f2860ad7/data").exists()) + assertTrue(blobsDir.resolve("sha256/3b/3ba62f2fe51e3304e4c26340567f70a8dfbd4e0c608a2154e174575544aaa3d9/data").exists()) + assertTrue(blobsDir.resolve("sha256/3e/3e37770490d98f2164cf29b50c7dc209a877d58182ae415540dc99d625e922b0/data").exists()) + assertTrue(blobsDir.resolve("sha256/4f/4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1/data").exists()) + assertTrue(blobsDir.resolve("sha256/8b/8b3654c299169c0f815629af51518c775817d09dd04da9a3bfa510cfa63f12bc/data").exists()) + assertTrue(blobsDir.resolve("sha256/9d/9d19ee268e0d7bcf6716e6658ee1b0384a71d6f2f9aa1ae2085610cf7c7b316f/data").exists()) + assertTrue(blobsDir.resolve("sha256/12/12cca292b13cb58fadde25af113ddc4ac3b0c5e39ab3f1290a6ba62ec8237afd/data").exists()) + assertTrue(blobsDir.resolve("sha256/18/18c6d4ab63429acdae46f5bc76e27378afaa44b40a746ae2465b3b4684846ef3/data").exists()) + assertTrue(blobsDir.resolve("sha256/33/33f5df018e7461c12a9942a1765d92002ac415ceb4cec48020e693c5b9022207/data").exists()) + assertTrue(blobsDir.resolve("sha256/35/3573c1225d462a8047deb540a10daffee48c949958f8b8842eaebe050daf48bb/data").exists()) + assertTrue(blobsDir.resolve("sha256/45/45953d25a53f34169be70bf8fc143e66c68cc46d47629b1b76b28be22647c9a9/data").exists()) + assertTrue(blobsDir.resolve("sha256/66/66b08230f25a80ecfea7a229a734049fc0d9abe01f756f11f922d39357dc487f/data").exists()) + assertTrue(blobsDir.resolve("sha256/92/92f85d89e7da0f3af0f527e7300cced784d0ba64249b8c376690599d313cb056/data").exists()) + assertTrue(blobsDir.resolve("sha256/a2/a2f2f93da48276873890ac821b3c991d53a7e864791aaf82c39b7863c908b93b/data").exists()) + assertTrue(blobsDir.resolve("sha256/ac/ac9c5946be2a99aca3f2643a8a98f230414662e4ea47e482ccad6bf6b0517657/data").exists()) + assertTrue(blobsDir.resolve("sha256/ac/ac34a2e0269ced3acc355be706239ee0f3f1e73a035c40dd2fac74827164ee53/data").exists()) + assertTrue(blobsDir.resolve("sha256/c1/c18c4e0236f2e8bec242432a19cff1d93bbd422b305e6900809fa4fcf0e07e48/data").exists()) + assertTrue(blobsDir.resolve("sha256/d4/d498448faeaf83b9fa66defd14b2cadc168e211bcb78fb36c748c19b5580b699/data").exists()) + assertTrue(blobsDir.resolve("sha256/d6/d6ae466d10fc5d00afc56a152620df8477ecd22369053f2514d2ea38ad5ed1fb/data").exists()) + assertTrue(blobsDir.resolve("sha256/d7/d73cf48caaac2e45ad76a2a9eb3b311d0e4eb1d804e3d2b9cf075a1fa31e6f92/data").exists()) + assertTrue(blobsDir.resolve("sha256/f2/f2b566cb887b5c06e04f5cd97660a99e73bd52ceb9d72c6db6383ae8470cc4cf/data").exists()) + assertTrue(blobsDir.resolve("sha256/${expectedJarLayerDigest.substring(0, 2)}/$expectedJarLayerDigest/data").exists()) + assertTrue(blobsDir.resolve("sha256/${expectedConfig1Digest.substring(0, 2)}/$expectedConfig1Digest/data").exists()) + assertTrue(blobsDir.resolve("sha256/${expectedConfig2Digest.substring(0, 2)}/$expectedConfig2Digest/data").exists()) + assertTrue(blobsDir.resolve("sha256/${expectedManifest1Digest.substring(0, 2)}/$expectedManifest1Digest/data").exists()) + assertTrue(blobsDir.resolve("sha256/${expectedManifest2Digest.substring(0, 2)}/$expectedManifest2Digest/data").exists()) + assertTrue(blobsDir.resolve("sha256/${expectedIndexDigest.substring(0, 2)}/$expectedIndexDigest/data").exists()) // @formatter:on val repositoriesDir = registryDir.resolve("repositories") val testRepositoryDir = repositoriesDir.resolve("example/test") - val testLayersDir = testRepositoryDir.resolve("blobs") + val testLayersDir = testRepositoryDir.resolve("_layers") // @formatter:off - assertTrue(testLayersDir.resolve("sha256/8b3654c299169c0f815629af51518c775817d09dd04da9a3bfa510cfa63f12bc").exists()) - assertTrue(testLayersDir.resolve("sha256/9d19ee268e0d7bcf6716e6658ee1b0384a71d6f2f9aa1ae2085610cf7c7b316f").exists()) - assertTrue(testLayersDir.resolve("sha256/92f85d89e7da0f3af0f527e7300cced784d0ba64249b8c376690599d313cb056").exists()) - assertTrue(testLayersDir.resolve("sha256/3573c1225d462a8047deb540a10daffee48c949958f8b8842eaebe050daf48bb").exists()) - assertTrue(testLayersDir.resolve("sha256/45953d25a53f34169be70bf8fc143e66c68cc46d47629b1b76b28be22647c9a9").exists()) - assertTrue(testLayersDir.resolve("sha256/ac9c5946be2a99aca3f2643a8a98f230414662e4ea47e482ccad6bf6b0517657").exists()) - assertTrue(testLayersDir.resolve("sha256/ac34a2e0269ced3acc355be706239ee0f3f1e73a035c40dd2fac74827164ee53").exists()) - assertTrue(testLayersDir.resolve("sha256/f2b566cb887b5c06e04f5cd97660a99e73bd52ceb9d72c6db6383ae8470cc4cf").exists()) - assertTrue(testLayersDir.resolve("sha256/$expectedJarLayerDigest").exists()) - assertTrue(testLayersDir.resolve("sha256/$expectedConfig1Digest").exists()) - assertTrue(testLayersDir.resolve("sha256/$expectedConfig2Digest").exists()) + assertTrue(testLayersDir.resolve("sha256/8b3654c299169c0f815629af51518c775817d09dd04da9a3bfa510cfa63f12bc/link").exists()) + assertTrue(testLayersDir.resolve("sha256/9d19ee268e0d7bcf6716e6658ee1b0384a71d6f2f9aa1ae2085610cf7c7b316f/link").exists()) + assertTrue(testLayersDir.resolve("sha256/92f85d89e7da0f3af0f527e7300cced784d0ba64249b8c376690599d313cb056/link").exists()) + assertTrue(testLayersDir.resolve("sha256/3573c1225d462a8047deb540a10daffee48c949958f8b8842eaebe050daf48bb/link").exists()) + assertTrue(testLayersDir.resolve("sha256/45953d25a53f34169be70bf8fc143e66c68cc46d47629b1b76b28be22647c9a9/link").exists()) + assertTrue(testLayersDir.resolve("sha256/ac9c5946be2a99aca3f2643a8a98f230414662e4ea47e482ccad6bf6b0517657/link").exists()) + assertTrue(testLayersDir.resolve("sha256/ac34a2e0269ced3acc355be706239ee0f3f1e73a035c40dd2fac74827164ee53/link").exists()) + assertTrue(testLayersDir.resolve("sha256/f2b566cb887b5c06e04f5cd97660a99e73bd52ceb9d72c6db6383ae8470cc4cf/link").exists()) + assertTrue(testLayersDir.resolve("sha256/$expectedJarLayerDigest/link").exists()) + assertTrue(testLayersDir.resolve("sha256/$expectedConfig1Digest/link").exists()) + assertTrue(testLayersDir.resolve("sha256/$expectedConfig2Digest/link").exists()) // @formatter:on - val testManifestsDir = testRepositoryDir.resolve("manifests") + val testManifestsDir = testRepositoryDir.resolve("_manifests") + val testManifestRevisionsDir = testManifestsDir.resolve("revisions") // @formatter:off - assertTrue(testManifestsDir.resolve("sha256/$expectedIndexDigest").exists()) - assertTrue(testManifestsDir.resolve("sha256/$expectedManifest1Digest").exists()) - assertTrue(testManifestsDir.resolve("sha256/$expectedManifest2Digest").exists()) - assertTrue(testManifestsDir.resolve("1.0.0").exists()) - assertTrue(testManifestsDir.resolve("latest").exists()) + assertTrue(testManifestRevisionsDir.resolve("sha256/$expectedIndexDigest/link").exists()) + assertTrue(testManifestRevisionsDir.resolve("sha256/$expectedManifest1Digest/link").exists()) + assertTrue(testManifestRevisionsDir.resolve("sha256/$expectedManifest2Digest/link").exists()) + // @formatter:on + val testTagsDir = testManifestsDir.resolve("tags") + val test1TagDir = testTagsDir.resolve("1.0.0") + // @formatter:off + assertTrue(test1TagDir.resolve("current/link").exists()) + assertTrue(test1TagDir.resolve("index/sha256/$expectedIndexDigest/link").exists()) + // @formatter:on + val testLatestTagDir = testTagsDir.resolve("latest") + // @formatter:off + assertTrue(testLatestTagDir.resolve("current/link").exists()) + assertTrue(testLatestTagDir.resolve("index/sha256/$expectedIndexDigest/link").exists()) // @formatter:on val hivemqRepositoryDir = repositoriesDir.resolve("hivemq/hivemq4") - val hivemqLayersDir = hivemqRepositoryDir.resolve("blobs") + val hivemqLayersDir = hivemqRepositoryDir.resolve("_layers") + // @formatter:off + assertTrue(hivemqLayersDir.resolve("sha256/1d511796a8d527cf68165c8b95d6606d03c6a30a624d781f8f3682ae14797078/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/1efc276f4ff952c055dea726cfc96ec6a4fdb8b62d9eed816bd2b788f2860ad7/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/3ba62f2fe51e3304e4c26340567f70a8dfbd4e0c608a2154e174575544aaa3d9/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/3e37770490d98f2164cf29b50c7dc209a877d58182ae415540dc99d625e922b0/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/12cca292b13cb58fadde25af113ddc4ac3b0c5e39ab3f1290a6ba62ec8237afd/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/18c6d4ab63429acdae46f5bc76e27378afaa44b40a746ae2465b3b4684846ef3/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/33f5df018e7461c12a9942a1765d92002ac415ceb4cec48020e693c5b9022207/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/66b08230f25a80ecfea7a229a734049fc0d9abe01f756f11f922d39357dc487f/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/a2f2f93da48276873890ac821b3c991d53a7e864791aaf82c39b7863c908b93b/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/d6ae466d10fc5d00afc56a152620df8477ecd22369053f2514d2ea38ad5ed1fb/link").exists()) + assertTrue(hivemqLayersDir.resolve("sha256/d73cf48caaac2e45ad76a2a9eb3b311d0e4eb1d804e3d2b9cf075a1fa31e6f92/link").exists()) + // @formatter:on + val hivemqManifestsDir = hivemqRepositoryDir.resolve("_manifests") + val hivemqManifestRevisionsDir = hivemqManifestsDir.resolve("revisions") // @formatter:off - assertTrue(hivemqLayersDir.resolve("sha256/1d511796a8d527cf68165c8b95d6606d03c6a30a624d781f8f3682ae14797078").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/1efc276f4ff952c055dea726cfc96ec6a4fdb8b62d9eed816bd2b788f2860ad7").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/3ba62f2fe51e3304e4c26340567f70a8dfbd4e0c608a2154e174575544aaa3d9").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/3e37770490d98f2164cf29b50c7dc209a877d58182ae415540dc99d625e922b0").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/12cca292b13cb58fadde25af113ddc4ac3b0c5e39ab3f1290a6ba62ec8237afd").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/18c6d4ab63429acdae46f5bc76e27378afaa44b40a746ae2465b3b4684846ef3").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/33f5df018e7461c12a9942a1765d92002ac415ceb4cec48020e693c5b9022207").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/66b08230f25a80ecfea7a229a734049fc0d9abe01f756f11f922d39357dc487f").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/a2f2f93da48276873890ac821b3c991d53a7e864791aaf82c39b7863c908b93b").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/d6ae466d10fc5d00afc56a152620df8477ecd22369053f2514d2ea38ad5ed1fb").exists()) - assertTrue(hivemqLayersDir.resolve("sha256/d73cf48caaac2e45ad76a2a9eb3b311d0e4eb1d804e3d2b9cf075a1fa31e6f92").exists()) + assertTrue(hivemqManifestRevisionsDir.resolve("sha256/c18c4e0236f2e8bec242432a19cff1d93bbd422b305e6900809fa4fcf0e07e48/link").exists()) + assertTrue(hivemqManifestRevisionsDir.resolve("sha256/d498448faeaf83b9fa66defd14b2cadc168e211bcb78fb36c748c19b5580b699/link").exists()) // @formatter:on - val hivemqManifestsDir = hivemqRepositoryDir.resolve("manifests") + val hivemqTagDir = hivemqManifestsDir.resolve("tags/4.16.0") // @formatter:off - assertTrue(hivemqManifestsDir.resolve("sha256/c18c4e0236f2e8bec242432a19cff1d93bbd422b305e6900809fa4fcf0e07e48").exists()) - assertTrue(hivemqManifestsDir.resolve("sha256/d498448faeaf83b9fa66defd14b2cadc168e211bcb78fb36c748c19b5580b699").exists()) - assertTrue(hivemqManifestsDir.resolve("4.16.0").exists()) + assertTrue(hivemqTagDir.resolve("current/link").exists()) + assertTrue(hivemqTagDir.resolve("index/sha256/d498448faeaf83b9fa66defd14b2cadc168e211bcb78fb36c748c19b5580b699/link").exists()) // @formatter:on } } 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 d5510e38..285ff389 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/DistributionRegistryDataTask.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/DistributionRegistryDataTask.kt @@ -6,6 +6,7 @@ import io.github.sgtsilvio.gradle.oci.platform.Platform import org.gradle.api.file.DirectoryProperty import org.gradle.api.tasks.OutputDirectory import java.io.File +import java.io.IOException import java.nio.file.FileAlreadyExistsException import java.nio.file.Path import java.nio.file.StandardOpenOption @@ -121,3 +122,10 @@ abstract class DistributionRegistryDataTask : OciImagesInputTask() { } } } + +internal fun Path.ensureEmptyDirectory(): Path { + if (!toFile().deleteRecursively()) { + throw IOException("$this could not be deleted") + } + return createDirectories() +} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt deleted file mode 100644 index e78d403f..00000000 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciRegistryDataTask.kt +++ /dev/null @@ -1,119 +0,0 @@ -package io.github.sgtsilvio.gradle.oci - -import io.github.sgtsilvio.gradle.oci.component.ResolvedOciComponent -import io.github.sgtsilvio.gradle.oci.metadata.* -import io.github.sgtsilvio.gradle.oci.platform.Platform -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.tasks.OutputDirectory -import java.io.File -import java.io.IOException -import java.nio.file.FileAlreadyExistsException -import java.nio.file.Path -import java.nio.file.StandardOpenOption -import kotlin.io.path.* - -/** - * @author Silvio Giebl - */ -abstract class OciRegistryDataTask : OciImagesInputTask() { - - @get:OutputDirectory - val registryDataDirectory: DirectoryProperty = project.objects.directoryProperty() - - override fun run( - resolvedComponentToImageReferences: Map>, - digestToLayer: Map, - ) { - val registryDataDirectory = registryDataDirectory.get().asFile.toPath().ensureEmptyDirectory() - val blobsDirectory = registryDataDirectory.resolve("blobs").createDirectory() - val repositoriesDirectory = registryDataDirectory.resolve("repositories").createDirectory() - val layerDigests = mutableSetOf() - for ((resolvedComponent, imageReferences) in resolvedComponentToImageReferences) { - writeImage(resolvedComponent, imageReferences, blobsDirectory, repositoriesDirectory, layerDigests) - } - for (digest in layerDigests) { - blobsDirectory.resolveDigestFile(digest).createLinkPointingTo(digestToLayer[digest]!!.toPath()) - } - } - - private fun writeImage( - resolvedComponent: ResolvedOciComponent, - imageReferences: Set, - blobsDirectory: Path, - repositoriesDirectory: Path, - layerDigests: MutableSet, - ) { - val manifests = mutableListOf>() - val blobDigests = mutableSetOf() - for (platform in resolvedComponent.platforms) { - val bundlesForPlatform = resolvedComponent.collectBundlesForPlatform(platform).map { it.bundle } - for (bundle in bundlesForPlatform) { - for (layer in bundle.layers) { - layer.descriptor?.let { (_, digest) -> - layerDigests += digest - blobDigests += digest - } - } - } - val config = createConfig(platform, bundlesForPlatform) - blobsDirectory.writeDigestData(config) - blobDigests += config.digest - val manifest = createManifest(config, bundlesForPlatform) - blobsDirectory.writeDigestData(manifest) - manifests += Pair(platform, manifest) - } - val index = createIndex(manifests, resolvedComponent.component) - blobsDirectory.writeDigestData(index) - val indexDigest = index.digest - - for (imageReference in imageReferences) { - val repositoryDirectory = repositoriesDirectory.resolve(imageReference.name).createDirectories() - val repositoryBlobsDirectory = repositoryDirectory.resolve("blobs").createDirectories() - for (blobDigest in blobDigests) { - repositoryBlobsDirectory.writeDigestLink(blobDigest) - } - val manifestsDirectory = repositoryDirectory.resolve("manifests").createDirectories() - for ((_, manifestDescriptor) in manifests) { - manifestsDirectory.writeDigestLink(manifestDescriptor.digest) - } - manifestsDirectory.writeDigestLink(indexDigest) - manifestsDirectory.resolve(imageReference.tag).writeTagLink(indexDigest) - } - } - - private fun Path.resolveDigestFile(digest: OciDigest): Path = - resolve(digest.algorithm.ociPrefix).createDirectories().resolve(digest.encodedHash) - - private fun Path.writeDigestData(dataDescriptor: OciDataDescriptor) { - val digestDataFile = resolveDigestFile(dataDescriptor.digest) - try { - digestDataFile.writeBytes(dataDescriptor.data, StandardOpenOption.CREATE_NEW) - } catch (e: FileAlreadyExistsException) { - if (!dataDescriptor.data.contentEquals(digestDataFile.readBytes())) { - throw IllegalStateException("hash collision for digest ${dataDescriptor.digest}: expected file content of $digestDataFile to be the same as ${dataDescriptor.data.contentToString()}") - } - } - } - - private fun Path.writeDigestLink(digest: OciDigest) { - resolveDigestFile(digest).writeBytes(digest.toString().toByteArray()) - } - - private fun Path.writeTagLink(digest: OciDigest) { - val digestBytes = digest.toString().toByteArray() - try { - writeBytes(digestBytes, StandardOpenOption.CREATE_NEW) - } catch (e: FileAlreadyExistsException) { - if (!digestBytes.contentEquals(readBytes())) { - throw IllegalStateException("tried to link the same image name/tag to different images") - } - } - } -} - -internal fun Path.ensureEmptyDirectory(): Path { - if (!toFile().deleteRecursively()) { - throw IOException("$this could not be deleted") - } - return createDirectories() -} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciExtension.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciExtension.kt index e8ed6be4..536207c4 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciExtension.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciExtension.kt @@ -1,8 +1,8 @@ package io.github.sgtsilvio.gradle.oci.dsl +import io.github.sgtsilvio.gradle.oci.DistributionRegistryDataTask import io.github.sgtsilvio.gradle.oci.OciLayerTask import io.github.sgtsilvio.gradle.oci.OciPushTask -import io.github.sgtsilvio.gradle.oci.OciRegistryDataTask import io.github.sgtsilvio.gradle.oci.mapping.OciImageMapping import io.github.sgtsilvio.gradle.oci.platform.Platform import io.github.sgtsilvio.gradle.oci.platform.PlatformFilter @@ -18,7 +18,7 @@ import org.gradle.api.tasks.testing.Test interface OciExtension { val layerTaskClass get() = OciLayerTask::class val pushTaskClass get() = OciPushTask::class - val registryDataTaskClass get() = OciRegistryDataTask::class + val registryDataTaskClass get() = DistributionRegistryDataTask::class val registries: OciRegistries val imageMapping: OciImageMapping diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciExtensionImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciExtensionImpl.kt index fd9cbbb3..4af8f6b7 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciExtensionImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciExtensionImpl.kt @@ -1,6 +1,6 @@ package io.github.sgtsilvio.gradle.oci.internal.dsl -import io.github.sgtsilvio.gradle.oci.OciRegistryDataTask +import io.github.sgtsilvio.gradle.oci.DistributionRegistryDataTask import io.github.sgtsilvio.gradle.oci.TASK_GROUP_NAME import io.github.sgtsilvio.gradle.oci.dsl.OciExtension import io.github.sgtsilvio.gradle.oci.dsl.OciImageDefinition @@ -89,9 +89,9 @@ internal abstract class OciExtensionImpl @Inject constructor( val testTaskName = testTask.name val registryDataTaskName = "${testTaskName}OciRegistryData" val registryDataTask = if (registryDataTaskName in taskContainer.names) { - taskContainer.named(registryDataTaskName) + taskContainer.named(registryDataTaskName) } else { - val registryDataTask = taskContainer.register(registryDataTaskName) { + val registryDataTask = taskContainer.register(registryDataTaskName) { group = TASK_GROUP_NAME description = "Creates a Docker registry data directory to be used by the $testTaskName task." registryDataDirectory.set(projectLayout.buildDirectory.dir("oci/registries/$testTaskName")) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciTestArgumentProvider.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciTestArgumentProvider.kt index 21b16d93..2eac4ea1 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciTestArgumentProvider.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciTestArgumentProvider.kt @@ -1,6 +1,6 @@ package io.github.sgtsilvio.gradle.oci.internal.dsl -import io.github.sgtsilvio.gradle.oci.OciRegistryDataTask +import io.github.sgtsilvio.gradle.oci.DistributionRegistryDataTask import org.gradle.api.file.FileTree import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Provider @@ -15,7 +15,7 @@ import org.gradle.process.CommandLineArgumentProvider */ internal class OciTestArgumentProvider( objectFactory: ObjectFactory, - registryDataTask: TaskProvider, + registryDataTask: TaskProvider, ) : CommandLineArgumentProvider { @get:InputFiles