|
1 | | -package dev.codebandits.container.gradle.tasks |
| 1 | +package dev.codebandits.container.gradle.image |
2 | 2 |
|
3 | 3 | import org.gradle.api.Task |
| 4 | +import org.gradle.api.file.RegularFile |
| 5 | +import org.gradle.api.provider.Provider |
| 6 | +import java.net.URLEncoder |
| 7 | +import java.nio.charset.StandardCharsets |
4 | 8 |
|
5 | 9 | public fun Task.inputLocalImage( |
6 | 10 | imageReference: String, |
@@ -54,3 +58,35 @@ public fun Task.outputRegistryImage( |
54 | 58 | } |
55 | 59 | } |
56 | 60 | } |
| 61 | + |
| 62 | +private fun Task.getLocalImageTrackingFile( |
| 63 | + imageReference: String, |
| 64 | +): Provider<RegularFile> { |
| 65 | + val fileName = URLEncoder.encode(imageReference, StandardCharsets.UTF_8) |
| 66 | + return project.layout.buildDirectory.file("images/local/$fileName") |
| 67 | +} |
| 68 | + |
| 69 | +private fun Task.getRegistryImageTrackingFile( |
| 70 | + imageReference: String, |
| 71 | +): Provider<RegularFile> { |
| 72 | + val fileName = URLEncoder.encode(imageReference, StandardCharsets.UTF_8) |
| 73 | + return project.layout.buildDirectory.file("images/registry/$fileName") |
| 74 | +} |
| 75 | + |
| 76 | +private fun writeLocalImageId(imageReference: String, regularFile: RegularFile) { |
| 77 | + val file = regularFile.asFile |
| 78 | + if (!file.parentFile.exists()) { |
| 79 | + file.parentFile.mkdirs() |
| 80 | + } |
| 81 | + val imageId = Local.getImageId(imageReference) |
| 82 | + file.writeText(imageId ?: "") |
| 83 | +} |
| 84 | + |
| 85 | +private fun writeRegistryImageDigest(imageReference: String, regularFile: RegularFile) { |
| 86 | + val file = regularFile.asFile |
| 87 | + if (!file.parentFile.exists()) { |
| 88 | + file.parentFile.mkdirs() |
| 89 | + } |
| 90 | + val imageDigest = Registry.getImageDigest(imageReference) |
| 91 | + file.writeText(imageDigest ?: "") |
| 92 | +} |
0 commit comments