Skip to content

Commit

Permalink
Replace type of DockerLayerTask.platform String -> Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Dec 12, 2024
1 parent 001d7d1 commit 0b1dfce
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.sgtsilvio.gradle.oci.layer

import io.github.sgtsilvio.gradle.oci.internal.copyspec.DEFAULT_MODIFICATION_TIME
import io.github.sgtsilvio.gradle.oci.platform.Platform
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
import org.gradle.api.tasks.Input
Expand All @@ -23,7 +24,7 @@ abstract class DockerLayerTask @Inject constructor(private val execOperations: E
val from = project.objects.property<String>() // TODO replace from and platform with ImageInput

@get:Input
val platform = project.objects.property<String>()
val platform = project.objects.property<Platform>()

@get:Input
val command = project.objects.property<String>()
Expand All @@ -45,8 +46,9 @@ abstract class DockerLayerTask @Inject constructor(private val execOperations: E

override fun run(tarOutputStream: TarArchiveOutputStream) {
val imageReference = UUID.randomUUID()
val platformArgument = platform.get().toPlatformArgument()
execOperations.exec {
commandLine("docker", "build", "-", "--platform", platform.get(), "-t", imageReference, "--no-cache")
commandLine("docker", "build", "-", "--platform", platformArgument, "-t", imageReference, "--no-cache")
standardInput = ByteArrayInputStream(assembleDockerfile().toByteArray())
}
val temporaryDirectory = temporaryDir
Expand Down Expand Up @@ -106,6 +108,11 @@ abstract class DockerLayerTask @Inject constructor(private val execOperations: E
appendLine("RUN $command")
}

private fun Platform.toPlatformArgument(): String {
val s = "$os/$architecture"
return if (variant.isEmpty()) s else "$s/$variant"
}

private fun TarArchiveInputStream.findEntry(path: String): Boolean {
while (nextEntry != null) {
if (currentEntry.name == path) {
Expand Down

0 comments on commit 0b1dfce

Please sign in to comment.