-
Notifications
You must be signed in to change notification settings - Fork 573
Description
Let's take the following definition with repeated and almost similar targets:
group "validate" {
targets = ["validate-lint", "validate-vendor", "validate-docs", "validate-authors"]
}
target "validate-lint" {
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
output = ["type=cacheonly"]
}
target "validate-vendor" {
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "validate-docs" {
dockerfile = "./hack/dockerfiles/docs.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "validate-authors" {
dockerfile = "./hack/dockerfiles/authors.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
A common pattern with bake is the ability to group and run targets in parallel. Atm we don't have a nice way of defining implicit target by using a pattern rule like GNU Make.
A target pattern contains the character %
(exactly one of them) in the target; otherwise, it looks exactly like an ordinary target. The %
matches any nonempty substring, while other characters match only themselves. A target pattern is composed of a %
between a prefix and a suffix, either or both of which may be empty. The text between the prefix and the suffix is called the stem. Thus, when the pattern validate-%
matches the target name validate-vendor
, the stem is vendor
.
Like GNU Make automatic vairables we can also have values computed afresh for each rule that is executed, based on the target and prerequisites of the rule within its own recipe. By taking the example above we could then write:
group "validate" {
targets = ["validate-lint", "validate-vendor", "validate-docs", "validate-authors"]
}
target "validate-%" {
dockerfile = "./hack/dockerfiles/${*}.Dockerfile"
target = "${*}" != "lint" ? "validate" : ""
output = ["type=cacheonly"]
}
${*}
defines the stem with which an implicit rule matches as explained above. (e.g. forvalidate-vendor
would bevendor
)${@}
defines the target name. (e.g. forvalidate-vendor
would bevalidate-vendor
)