函式
目錄
當您需要以比單純串連或插值更複雜的方式操作建置設定中的值時,HCL 函式非常有用。
標準函式庫
Bake 內建支援 go-cty
標準函式庫函式
當您需要以比單純串連或插值更複雜的方式操作建置設定中的值時,HCL 函式非常有用。
Bake 內建支援 go-cty
標準函式庫函式
$ docker buildx bake --print webapp
{
"group": {
"default": {
"targets": ["webapp"]
}
},
"target": {
"webapp": {
"context": ".",
"dockerfile": "Dockerfile",
"args": {
"buildno": "124"
}
}
}
}
$ docker buildx bake --print webapp
{
"group": {
"default": {
"targets": ["webapp"]
}
},
"target": {
"webapp": {
"context": ".",
"dockerfile": "Dockerfile",
"args": {
"buildno": "124"
}
}
}
}
您可以在函式內參考 變數 和標準函式庫函式。
您無法從其他函式參考使用者定義函式。
以下範例在自訂函式中使用全域變數 (REPO
)。
# docker-bake.hcl
variable "REPO" {
default = "user/repo"
}
function "tag" {
params = [tag]
result = ["${REPO}:${tag}"]
}
target "webapp" {
tags = tag("v1")
}
使用 --print
旗標列印 Bake 檔案會顯示 tag
函式使用 REPO
的值來設定標籤的前綴。
$ docker buildx bake --print webapp
{
"group": {
"default": {
"targets": ["webapp"]
}
},
"target": {
"webapp": {
"context": ".",
"dockerfile": "Dockerfile",
"tags": ["user/repo:v1"]
}
}
}