diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadata.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadata.kt index 909b8c9d..eb65b1ff 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadata.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadata.kt @@ -17,7 +17,8 @@ data class OciMetadata( val user: String?, val ports: SortedSet, val environment: SortedMap, - val command: Command?, + val entryPoint: List?, // empty (no args) is different from null (not set, inherit) + val arguments: List?, // empty (no args) is different from null (not set, inherit) val volumes: SortedSet, val workingDirectory: String?, val stopSignal: String?, @@ -29,11 +30,6 @@ data class OciMetadata( val layers: List, ) : Serializable { - data class Command( - val entryPoint: List?, // empty (no args) is different from null (not set, inherit) - val arguments: List, // default empty - ) : Serializable - data class Layer( val descriptor: Descriptor?, val creationTime: Instant?, diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataBuilder.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataBuilder.kt index 18d5d080..e3228235 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataBuilder.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataBuilder.kt @@ -15,7 +15,8 @@ internal class OciMetadataBuilder : Serializable { private var user: String? = null private var ports: Set = emptySet() private var environment: Map = emptyMap() - private var command: OciMetadata.Command? = null + private var entryPoint: List? = null + private var arguments: List? = null private var volumes: Set = emptySet() private var workingDirectory: String? = null private var stopSignal: String? = null @@ -32,7 +33,8 @@ internal class OciMetadataBuilder : Serializable { fun user(v: String?) = apply { user = v } fun ports(v: Set) = apply { ports = v } fun environment(v: Map) = apply { environment = v } - fun command(v: OciMetadata.Command?) = apply { command = v } + fun entryPoint(v: List?) = apply { entryPoint = v } + fun arguments(v: List?) = apply { arguments = v } fun volumes(v: Set) = apply { volumes = v } fun workingDirectory(v: String?) = apply { workingDirectory = v } fun stopSignal(v: String?) = apply { stopSignal = v } @@ -50,7 +52,8 @@ internal class OciMetadataBuilder : Serializable { user, ports.toSortedSet(), environment.toSortedMap(), - command, + entryPoint, + arguments, volumes.toSortedSet(), workingDirectory, stopSignal, @@ -63,19 +66,6 @@ internal class OciMetadataBuilder : Serializable { ) } -internal class OciMetadataCommandBuilder : Serializable { - private var entryPoint: List? = null - private var arguments: List? = null - - fun entryPoint(v: List?) = apply { entryPoint = v } - fun arguments(v: List?) = apply { arguments = v } - - fun build() = when { - (entryPoint == null) && (arguments == null) -> null - else -> OciMetadata.Command(entryPoint, arguments ?: emptyList()) - } -} - internal class OciMetadataLayerBuilder : Serializable { private var descriptor: OciMetadata.Layer.Descriptor? = null private var creationTime: SerializableInstant? = null diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataJsonCodec.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataJsonCodec.kt index ffd0c69d..5b4a0c10 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataJsonCodec.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/component/OciMetadataJsonCodec.kt @@ -14,9 +14,8 @@ private fun JsonObjectStringBuilder.encodeOciMetadata(metadata: OciMetadata) { addStringIfNotNull("user", metadata.user) addArrayIfNotEmpty("ports", metadata.ports) addObjectIfNotEmpty("environment", metadata.environment) - metadata.command?.let { command -> - addObject("command") { encodeCommand(command) } - } + addArrayIfNotNull("entryPoint", metadata.entryPoint) + addArrayIfNotNull("arguments", metadata.arguments) addArrayIfNotEmpty("volumes", metadata.volumes) addStringIfNotNull("workingDirectory", metadata.workingDirectory) addStringIfNotNull("stopSignal", metadata.stopSignal) @@ -28,11 +27,6 @@ private fun JsonObjectStringBuilder.encodeOciMetadata(metadata: OciMetadata) { addArrayIfNotEmpty("layers", metadata.layers) { addObject { encodeLayer(it) } } } -private fun JsonObjectStringBuilder.encodeCommand(command: OciMetadata.Command) { - addArrayIfNotNull("entryPoint", command.entryPoint) - addArray("arguments", command.arguments) -} - private fun JsonObjectStringBuilder.encodeLayer(layer: OciMetadata.Layer) { layer.descriptor?.let { descriptor -> addObject("descriptor") { encodeLayerDescriptor(descriptor) } @@ -62,7 +56,8 @@ private fun JsonObject.decodeOciMetadata() = OciMetadata( getStringOrNull("user"), getStringSetOrEmpty("ports"), getStringMapOrEmpty("environment"), - getOrNull("command") { asObject().decodeCommand() }, + getStringListOrNull("entryPoint"), + getStringListOrNull("arguments"), getStringSetOrEmpty("volumes"), getStringOrNull("workingDirectory"), getStringOrNull("stopSignal"), @@ -74,11 +69,6 @@ private fun JsonObject.decodeOciMetadata() = OciMetadata( getOrNull("layers") { asArray().toList { asObject().decodeLayer() } } ?: emptyList(), ) -private fun JsonObject.decodeCommand() = OciMetadata.Command( - getStringListOrNull("entryPoint"), - getStringList("arguments"), -) - private fun JsonObject.decodeLayer() = OciMetadata.Layer( getOrNull("descriptor") { asObject().decodeLayerDescriptor() }, getInstantOrNull("creationTime"), diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt index 1ddbba7c..54b39a7b 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt @@ -280,7 +280,8 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( .zipAbsentAsNull(config.user, OciMetadataBuilder::user) .zip(config.ports.orElse(emptySet()), OciMetadataBuilder::ports) .zip(config.environment.orElse(emptyMap()), OciMetadataBuilder::environment) - .zipAbsentAsNull(createMetadataCommand(providerFactory), OciMetadataBuilder::command) + .zipAbsentAsNull(config.entryPoint, OciMetadataBuilder::entryPoint) + .zipAbsentAsNull(config.arguments, OciMetadataBuilder::arguments) .zip(config.volumes.orElse(emptySet()), OciMetadataBuilder::volumes) .zipAbsentAsNull(config.workingDirectory, OciMetadataBuilder::workingDirectory) .zipAbsentAsNull(config.stopSignal, OciMetadataBuilder::stopSignal) @@ -298,12 +299,6 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( .zip(createMetadataLayers(providerFactory), OciMetadataBuilder::layers) .map { it.build() } - private fun createMetadataCommand(providerFactory: ProviderFactory): Provider = - providerFactory.provider { OciMetadataCommandBuilder() } - .zipAbsentAsNull(config.entryPoint, OciMetadataCommandBuilder::entryPoint) - .zipAbsentAsNull(config.arguments, OciMetadataCommandBuilder::arguments) - .map { it.build() } - private fun createMetadataLayers(providerFactory: ProviderFactory): Provider> = providerFactory.provider { var listProvider = providerFactory.provider { listOf() } diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciMetadataRegistry.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciMetadataRegistry.kt index 5bb34c65..0884e474 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciMetadataRegistry.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciMetadataRegistry.kt @@ -195,7 +195,8 @@ internal class OciMetadataRegistry(val registryApi: OciRegistryApi) { // sorted for canonical json: architecture, author, config, created, history, os, os.features, os.version, rootfs, variant val architecture = configJsonObject.getString("architecture") val author = configJsonObject.getStringOrNull("author") - var command: OciMetadata.Command? = null + var arguments: List? = null + var entryPoint: List? = null var environment: SortedMap = TreeMap() var ports: SortedSet = TreeSet() var configAnnotations: SortedMap = TreeMap() @@ -206,9 +207,8 @@ internal class OciMetadataRegistry(val registryApi: OciRegistryApi) { configJsonObject.getOrNull("config") { asObject().run { // sorted for canonical json: Cmd, Entrypoint, Env, ExposedPorts, Labels, StopSignal, User, Volumes, WorkingDir - val arguments = getStringListOrNull("Cmd") - val entryPoint = getStringListOrNull("Entrypoint") - command = if ((entryPoint == null) && (arguments == null)) null else OciMetadata.Command(entryPoint, arguments ?: emptyList()) + arguments = getStringListOrNull("Cmd") + entryPoint = getStringListOrNull("Entrypoint") environment = getOrNull("Env") { asArray().toMap(TreeMap()) { val environmentString = asString() @@ -292,7 +292,8 @@ internal class OciMetadataRegistry(val registryApi: OciRegistryApi) { user, ports, environment, - command, + entryPoint, + arguments, volumes, workingDirectory, stopSignal, diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadata.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadata.kt index 55bf3675..ac86b8bc 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadata.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadata.kt @@ -28,10 +28,11 @@ internal fun createConfig(platform: Platform, variants: List): OciDa metadata.user?.let { user = it } ports.addAll(metadata.ports) environment += metadata.environment - metadata.command?.let { command -> - command.entryPoint?.let { entryPoint = it } - arguments = command.arguments + metadata.entryPoint?.let { + entryPoint = it + arguments = emptyList() } + metadata.arguments?.let { arguments = it } volumes.addAll(metadata.volumes) metadata.workingDirectory?.let { workingDirectory = it } metadata.stopSignal?.let { stopSignal = it }