Skip to content

Instantly share code, notes, and snippets.

@guilhem
Created February 19, 2025 14:34
Show Gist options
  • Save guilhem/c0cfec9a0163ee7f2d2e18b84f5d8dcc to your computer and use it in GitHub Desktop.
Save guilhem/c0cfec9a0163ee7f2d2e18b84f5d8dcc to your computer and use it in GitHub Desktop.
sample of bake config
group "default" {
targets = ["app", "editor"]
}
variable "TAG" {
default = "test"
}
variable "APP_VERSION" {
default = "2"
}
variable "GITHUB_ACTIONS" {
default = ""
}
variable "REGISTRY" {
default = "my.registry"
}
function "tags" {
params = [name]
result = "${REGISTRY}/${name}:${TAG}"
}
function "buildtag" {
params = [name]
result = "my.registry/${name}:${TAG}-build"
}
function "ghaexport" {
params = [name]
result = notequal("", GITHUB_ACTIONS) ? "${regex_replace("type=gha,mode=max,scope=buildkit${name}", "\\.", "_")}" : ""
}
function "ghaimport" {
params = [name]
result = notequal("", GITHUB_ACTIONS) ? "${regex_replace("type=gha,scope=buildkit${name}", "\\.", "_")}" : ""
}
target "_base" {
context = "./app"
contexts = {
dep1-src = "./dep1"
dep2-src = "./dep2"
}
cache-from = [
"type=registry,ref=my.registry/dep1:latest-build",
]
cache-to = [
"type=registry,ref=my.registry/build-dep1:latest-build,mode=max",
]
target = "dep1"
platforms = ["linux/amd64"]
}
target "app" {
name = versions.name
inherits = ["_base74"]
matrix = {
versions = [
{
version = "1"
name = "app1"
},
{
version = "2"
name = "app2"
},
{
version = "3"
name = "app3"
},
{
version = "4"
name = "app4"
},
{
version = "5"
name = "app5"
}
]
}
args = {
APP_VERSION = versions.version
}
cache-from = [
"type=registry,ref=my.registry/${versions.name}:latest-build",
"type=registry,ref=${buildtag(versions.name)}",
]
tags = [tags(versions.name)]
cache-to = [
"type=registry,ref=${buildtag(versions.name)},mode=max",
]
target = "app"
}
target "editor" {
name = "editor-${versions.name}"
matrix = {
versions = [
{
version = "1"
name = "editor1"
},
{
version = "2"
name = "editor2"
},
{
version = "3"
name = "editor3"
},
{
version = "4"
name = "editor4"
},
{
version = "5"
name = "editor5"
}
]
}
context = "./editor"
ARGS = {
REGISTRY = "my.registry/editor"
APP_VERSION = versions.version
}
cache-from = [
"type=registry,ref=my.registry/editor-${versions.name}:latest-build",
"type=registry,ref=${buildtag("editor-${versions.name}")}",
]
tags = ["my.registry/editor/${versions.name}:${TAG}"]
cache-to = [
"type=registry,ref=${buildtag("editor-${versions.name}")},mode=max",
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment