From 35cc063a5e4ecc7f8c62cf1e92177e3713cc9a59 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 26 May 2020 13:12:27 +0100 Subject: [PATCH 1/2] Fix build dependencies when building with buildkit. --- build.gradle.kts | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index df109087..c75e1e0e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -184,27 +184,32 @@ subprojects { } } +inline fun getBuildDependencies(childTask: T) = childTask.project.run { + val contents = projectDir.resolve("Dockerfile").readText() + // Extract the image name without the prefix 'local' it should match an existing project. + val matches = extractProjectDependenciesFromDockerfileRegex.findAll(contents) + + // If the project is found and it has a build task, it is a dependency. + matches.mapNotNull { + rootProject.findProject(it.groupValues[2])?.tasks?.withType() + }.flatten() +} + +// This used to replace the FROM statements such that the referred to the Image ID rather +// than "latest". Though this is currently broken when BuildKit is enabled: +// https://github.com/moby/moby/issues/39769 +// Now it uses whatever repository we're building / latest since that is variable. subprojects { tasks.withType { - val contents = projectDir.resolve("Dockerfile").readText() - // Extract the image name without the prefix 'local' it should match an existing project. - val matches = extractProjectDependenciesFromDockerfileRegex.findAll(contents) - - // If the project is found and it has a build task, link the dependency. - matches.forEach { - rootProject.findProject(it.groupValues[2]) - ?.tasks - ?.withType() - ?.first() - ?.let { buildTask -> - // If generated image id changes, rebuild. - inputs.file(buildTask.imageIdFile.asFile) - dependsOn(buildTask) - // This used to replace the FROM statements such that the referred to the Image ID rather - // than "latest". Though this is currently broken when BuildKit is enabled: - // https://github.com/moby/moby/issues/39769 - // Now it uses whatever repository we're building / latest since that is variable. - } + getBuildDependencies(this).forEach { parentTask -> + inputs.file(parentTask.imageIdFile.asFile) // If generated image id changes, rebuild. + dependsOn(parentTask) + } + } + tasks.withType { + getBuildDependencies(this).forEach { parentTask -> + inputs.file(parentTask.imageIdFile.asFile) // If generated image id changes, rebuild. + dependsOn(parentTask) } } } From cae6cc20a09820d2ea1ba27348f8722ac1d60ae4 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 27 May 2020 20:42:11 +0100 Subject: [PATCH 2/2] Remove dead code. --- build.gradle.kts | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c75e1e0e..970ffb46 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -57,9 +57,6 @@ data class BindMount(val from: String, val source: String, val target: String) { fun toCopyInstruction() = GenericInstruction("COPY --from=${from} $source $target") } -fun extractBindMountFlagFromInstruction() { - -} //--mount=type=bind,from=imagemagick,source=/home/builder/packages/x86_64,target=/packages // Generate a list of image tages for the given image, using the project, version and tag properties. fun imagesTags(image: String, project: Project): Set {