fix(build): fix local quickstart builds (#13445)

This commit is contained in:
Chakru 2025-05-07 20:13:52 +05:30 committed by GitHub
parent b48774c1ec
commit 2679e75071
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 79 additions and 72 deletions

View File

@ -203,7 +203,8 @@ quickstart_configs.each { taskName, config ->
bakeSpec = [:]
}
group = 'quickstart-ci'
dependsOn(config.modules.collect { it + ':generateBakeSnippet' })
def taskSuffix = config.isDebug? 'debug' : ''
dependsOn(config.modules.collect { it + ":generateBakeSnippet${taskSuffix}" })
dependsOn(tasks.getByName("prepareAll${taskName}"))
def jsonFile = new File(rootProject.buildDir, "bake-spec-${taskName}.json")
@ -230,8 +231,7 @@ quickstart_configs.each { taskName, config ->
config.modules.each { module ->
def moduleProject = project.project(module)
project.ext.isDebug = config.isDebug
def generateBakeSnippetsTask = moduleProject.tasks.getByName("generateBakeSnippet")
def generateBakeSnippetsTask = moduleProject.tasks.getByName("generateBakeSnippet${taskSuffix}")
bakeSnippets.putAll(generateBakeSnippetsTask.bakeSpec.target)
targets.addAll(generateBakeSnippetsTask.bakeSpec.target.keySet())
}

View File

@ -247,81 +247,88 @@ project.afterEvaluate {
}
}
project.tasks.register("generateBakeSnippet") {
ext.bakeSpec = []
group "docker"
description "Generates bake snippets for the project"
// Generate two instances of this task -- one with debug and one without.
// Since this is a dependency to quickstart* tasks, quickstart* task cannot change the behaviour of its dependencies
// so instead, quickstart* tasks will depend on the correct task variant based on whether it is a debug task or not.
// For debug builds have specific additional build args so the the presence of debug tag is triggers their inclusion.
["", "debug"].forEach { taskSuffix ->
project.tasks.register("generateBakeSnippet${taskSuffix}") {
ext.bakeSpec = []
ext.isDebug = (taskSuffix == 'debug')
group "docker"
description "Generates bake snippets for the project"
doLast {
// if matrixBuild is true, this is to publish images, so all variants must be built.
def matrixBuild = project.getProperties().getOrDefault("matrixBuild", false)
doLast {
// if matrixBuild is true, this is to publish images, so all variants must be built.
def matrixBuild = project.getProperties().getOrDefault("matrixBuild", false)
def bake_spec_target = [
context: "${buildContext}",
dockerfile: "${extension.dockerfile.get().toPath()}",
]
def bake_spec_target = [
context: "${buildContext}",
dockerfile: "${extension.dockerfile.get().toPath()}",
]
if (project.hasProperty("tag")) {
def dockerTag = project.property("tag")
bake_spec_target.tags = extension.tags.get().values().findAll({ tag -> tag.contains(dockerTag) }).toList()
} else {
bake_spec_target.tags = extension.tags.get().values().findAll({tag ->
project.ext.isDebug || !tag.contains("debug") //Add the debug tag only if this is this is a debug build.
}).toList()
}
if (extension.buildArgs.get()) {
bake_spec_target.args = extension.buildArgs.get()
} else {
bake_spec_target.args = [:]
}
if (extension.debugBuildArgs.get() && bake_spec_target.tags.findAll { tag -> tag.contains("debug") }.size() > 0) {
bake_spec_target.args.putAll(extension.debugBuildArgs.get())
}
if (matrixBuild) {
if (extension.platforms.get()) {
bake_spec_target.platforms = extension.platforms.get()
if (project.hasProperty("tag")) {
def dockerTag = project.property("tag")
bake_spec_target.tags = extension.tags.get().values().findAll({ tag -> tag.contains(dockerTag) }).toList()
} else {
bake_spec_target.platforms = extension.defaultPlatforms
bake_spec_target.tags = extension.tags.get().values().findAll({tag ->
ext.isDebug || !tag.contains("debug") //Add the debug tag only if this is this is a debug build.
}).toList()
}
if (extension.buildArgs.get()) {
bake_spec_target.args = extension.buildArgs.get()
} else {
bake_spec_target.args = [:]
}
if (extension.debugBuildArgs.get() && bake_spec_target.tags.findAll { tag -> tag.contains("debug") }.size() > 0) {
bake_spec_target.args.putAll(extension.debugBuildArgs.get())
}
if (matrixBuild) {
if (extension.platforms.get()) {
bake_spec_target.platforms = extension.platforms.get()
} else {
bake_spec_target.platforms = extension.defaultPlatforms
}
}
if (extension.variants.get()) {
bake_spec_target.name = "${project.name}-\${variants.tagSuffix}"
bake_spec_target.matrix = [variants: []]
extension.variants.get().each { variant, variantSpec ->
if (matrixBuild || variant == extension.defaultVariant.get()) {
// Its not easy to merge common buildArgs and variant buildArgs with json format.
// So, we just add common buildArgs to matrix.
bake_spec_target.matrix.variants.add([ 'tagSuffix': "${variantSpec.suffix}", 'args': variantSpec.args + bake_spec_target.args])
}
}
// When variants are present, fix up tags to include the variant suffix
// A bit of a hack that for quickstart builds, we need a tag named debug that contains the default variant without suffixes
bake_spec_target.tags = bake_spec_target.tags.collect(
{ tag -> tag + (tag.contains("debug") ? "" : "\${variants.tagSuffix}") }
).toList()
if (project.hasProperty("shaTag")) {
def shaTag = project.property("shaTag")
def dockerRepo = extension.tags.get().get("").split(":")[0] //Extract the repo name from the default tag
bake_spec_target.tags.add("${dockerRepo}:${shaTag}\${variants.tagSuffix}")
}
bake_spec_target.args = "\${variants.args}"
} else {
if (project.hasProperty("shaTag")) {
def shaTag = project.property("shaTag")
def dockerRepo = extension.tags.get().get("").split(":")[0]
bake_spec_target.tags.add("${dockerRepo}:${shaTag}")
}
}
ext.bakeSpec = [
target: [ "${project.name}": bake_spec_target]
]
}
if (extension.variants.get()) {
bake_spec_target.name = "${project.name}-\${variants.tagSuffix}"
bake_spec_target.matrix = [variants: []]
extension.variants.get().each { variant, variantSpec ->
if (matrixBuild || variant == extension.defaultVariant.get()) {
// Its not easy to merge common buildArgs and variant buildArgs with json format.
// So, we just add common buildArgs to matrix.
bake_spec_target.matrix.variants.add([ 'tagSuffix': "${variantSpec.suffix}", 'args': variantSpec.args + bake_spec_target.args])
}
}
// When variants are present, fix up tags to include the variant suffix
// A bit of a hack that for quickstart builds, we need a tag named debug that contains the default variant without suffixes
bake_spec_target.tags = bake_spec_target.tags.collect(
{ tag -> tag + (tag.contains("debug") ? "" : "\${variants.tagSuffix}") }
).toList()
if (project.hasProperty("shaTag")) {
def shaTag = project.property("shaTag")
def dockerRepo = extension.tags.get().get("").split(":")[0] //Extract the repo name from the default tag
bake_spec_target.tags.add("${dockerRepo}:${shaTag}\${variants.tagSuffix}")
}
bake_spec_target.args = "\${variants.args}"
} else {
if (project.hasProperty("shaTag")) {
def shaTag = project.property("shaTag")
def dockerRepo = extension.tags.get().get("").split(":")[0]
bake_spec_target.tags.add("${dockerRepo}:${shaTag}")
}
}
ext.bakeSpec = [
target: [ "${project.name}": bake_spec_target]
]
}
}