From 1967ccc2f70c8e04c7f95fec09bf0251daecb475 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Thu, 19 Dec 2024 00:06:52 +0100 Subject: [PATCH] Add OciImageTask interface --- .../gradle/oci/image/LoadOciImagesTask.kt | 21 +----------- .../gradle/oci/image/OciImagesTask.kt | 19 +++++++++++ .../gradle/oci/image/PushOciImageTask.kt | 32 ------------------- .../gradle/oci/image/PushOciImagesTask.kt | 5 +++ 4 files changed, 25 insertions(+), 52 deletions(-) delete mode 100644 src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImageTask.kt diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/LoadOciImagesTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/LoadOciImagesTask.kt index d79c4f23..365439df 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/LoadOciImagesTask.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/LoadOciImagesTask.kt @@ -6,10 +6,6 @@ import io.github.sgtsilvio.gradle.oci.metadata.OciImageReference import io.github.sgtsilvio.oci.registry.DistributionRegistryStorage import io.github.sgtsilvio.oci.registry.OciRegistryHandler import org.apache.commons.lang3.SystemUtils -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.options.Option -import org.gradle.kotlin.dsl.property -import org.gradle.kotlin.dsl.setProperty import org.gradle.process.ExecOperations import org.gradle.work.DisableCachingByDefault import reactor.netty.http.server.HttpServer @@ -65,19 +61,4 @@ abstract class LoadOciImagesTask @Inject constructor(private val execOperations: @DisableCachingByDefault(because = "Loading to an external Docker daemon") abstract class LoadOciImageTask @Inject constructor( execOperations: ExecOperations -) : LoadOciImagesTask(execOperations) { - - @get:Internal - @get:Option( - option = "name", - description = "Names the image. If not specified, the imageName defined in the image definition is used.", - ) - val imageName = project.objects.property() - - @get:Internal - @get:Option( - option = "tag", - description = "Tags the image. Option can be specified multiple times. The value '.' translates to the imageTag defined in the image definition. If not specified, the imageTag defined in the image definition is used.", - ) - val imageTags = project.objects.setProperty() -} +) : LoadOciImagesTask(execOperations), OciImageTask diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/OciImagesTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/OciImagesTask.kt index 2ad49822..4f836ebb 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/OciImagesTask.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/OciImagesTask.kt @@ -7,7 +7,9 @@ import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector import io.github.sgtsilvio.gradle.oci.platform.toPlatform import org.apache.commons.io.FileUtils import org.gradle.api.DefaultTask +import org.gradle.api.provider.Property import org.gradle.api.provider.Provider +import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.* import org.gradle.api.tasks.options.Option import org.gradle.kotlin.dsl.listProperty @@ -185,3 +187,20 @@ private val EMPTY_LAYER_DIFF_IDS = setOf( "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef".toOciDigest(), "sha512:8efb4f73c5655351c444eb109230c556d39e2c7624e9c11abc9e3fb4b9b9254218cc5085b454a9698d085cfa92198491f07a723be4574adc70617b73eb0b6461".toOciDigest(), ) + +interface OciImageTask { + + @get:Internal + @get:Option( + option = "name", + description = "Names the image. If not specified, the imageName defined in the image definition is used.", + ) + val imageName: Property + + @get:Internal + @get:Option( + option = "tag", + description = "Tags the image. Option can be specified multiple times. The value '.' translates to the imageTag defined in the image definition. If not specified, the imageTag defined in the image definition is used.", + ) + val imageTags: SetProperty +} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImageTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImageTask.kt deleted file mode 100644 index 3ef0aa37..00000000 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImageTask.kt +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.sgtsilvio.gradle.oci.image - -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.options.Option -import org.gradle.kotlin.dsl.property -import org.gradle.kotlin.dsl.setProperty -import org.gradle.work.DisableCachingByDefault -import org.gradle.workers.WorkerExecutor -import javax.inject.Inject - -/** - * @author Silvio Giebl - */ -@DisableCachingByDefault(because = "Pushing to an external registry") -abstract class PushOciImageTask @Inject constructor( - workerExecutor: WorkerExecutor, -) : PushOciImagesTask(workerExecutor) { - - @get:Internal - @get:Option( - option = "name", - description = "Names the image. If not specified, the imageName defined in the image definition is used.", - ) - val imageName = project.objects.property() - - @get:Internal - @get:Option( - option = "tag", - description = "Tags the image. Option can be specified multiple times. The value '.' translates to the imageTag defined in the image definition. If not specified, the imageTag defined in the image definition is used.", - ) - val imageTags = project.objects.setProperty() -} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImagesTask.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImagesTask.kt index f9876ebd..b197fb99 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImagesTask.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/image/PushOciImagesTask.kt @@ -324,3 +324,8 @@ private fun formatBytesString(bytes: Long): String = when { if (tenthMegaBytes == 0L) "$megaBytes MB" else "$megaBytes.$tenthMegaBytes MB" } } + +@DisableCachingByDefault(because = "Pushing to an external registry") +abstract class PushOciImageTask @Inject constructor( + workerExecutor: WorkerExecutor, +) : PushOciImagesTask(workerExecutor), OciImageTask