Skip to content

Commit 5569825

Browse files
authored
Merge pull request #3287 from crazy-max/bake-stdlib-docs
docs: generate docs for bake standard library functions
2 parents 758ea75 + 6997d61 commit 5569825

File tree

5 files changed

+231
-12
lines changed

5 files changed

+231
-12
lines changed

bake/hclparser/stdlib.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var stdlibFunctions = []funcDef{
132132
// value in a list.
133133
func indexOfFunc() function.Function {
134134
return function.New(&function.Spec{
135+
Description: `Finds the element index for a given value in a list.`,
135136
Params: []function.Parameter{
136137
{
137138
Name: "list",
@@ -177,6 +178,7 @@ func indexOfFunc() function.Function {
177178
// basenameFunc constructs a function that returns the last element of a path.
178179
func basenameFunc() function.Function {
179180
return function.New(&function.Spec{
181+
Description: `Returns the last element of a path.`,
180182
Params: []function.Parameter{
181183
{
182184
Name: "path",
@@ -194,6 +196,7 @@ func basenameFunc() function.Function {
194196
// dirnameFunc constructs a function that returns the directory of a path.
195197
func dirnameFunc() function.Function {
196198
return function.New(&function.Spec{
199+
Description: `Returns the directory of a path.`,
197200
Params: []function.Parameter{
198201
{
199202
Name: "path",
@@ -212,6 +215,7 @@ func dirnameFunc() function.Function {
212215
// leaving only characters that are valid for a Bake target name.
213216
func sanitizeFunc() function.Function {
214217
return function.New(&function.Spec{
218+
Description: `Replaces all non-alphanumeric characters with a underscore, leaving only characters that are valid for a Bake target name.`,
215219
Params: []function.Parameter{
216220
{
217221
Name: "name",
@@ -240,8 +244,9 @@ func sanitizeFunc() function.Function {
240244
// This function was imported from terraform's datetime utilities.
241245
func timestampFunc() function.Function {
242246
return function.New(&function.Spec{
243-
Params: []function.Parameter{},
244-
Type: function.StaticReturnType(cty.String),
247+
Description: `Returns a string representation of the current date and time.`,
248+
Params: []function.Parameter{},
249+
Type: function.StaticReturnType(cty.String),
245250
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
246251
return cty.StringVal(time.Now().UTC().Format(time.RFC3339)), nil
247252
},

docs/bake-reference.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,8 +1399,7 @@ $ docker buildx bake
13991399

14001400
## Function
14011401

1402-
A [set of general-purpose functions][bake_stdlib]
1403-
provided by [go-cty][go-cty]
1402+
A [set of general-purpose functions][bake_stdlib] provided by [go-cty][go-cty]
14041403
are available for use in HCL files:
14051404

14061405
```hcl
@@ -1440,7 +1439,7 @@ target "webapp-dev" {
14401439

14411440
[add-host]: https://docs.docker.com/reference/cli/docker/buildx/build/#add-host
14421441
[attestations]: https://docs.docker.com/build/attestations/
1443-
[bake_stdlib]: https://github.com/docker/buildx/blob/master/bake/hclparser/stdlib.go
1442+
[bake_stdlib]: https://github.com/docker/buildx/blob/master/docs/bake-stdlib.md
14441443
[build-arg]: https://docs.docker.com/reference/cli/docker/image/build/#build-arg
14451444
[build-context]: https://docs.docker.com/reference/cli/docker/buildx/build/#build-context
14461445
[cache-backends]: https://docs.docker.com/build/cache/backends/

0 commit comments

Comments
 (0)