Skip to content

Commit

Permalink
bake: additional test for print command and empty variable
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Nov 27, 2024
1 parent cd017e9 commit 402d86a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
20 changes: 20 additions & 0 deletions bake/bake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2008,3 +2008,23 @@ target "app" {
require.Contains(t, err.Error(), "FOO must be greater than 5.")
})
}

// https://github.com/docker/buildx/issues/2822
func TestVariableEmpty(t *testing.T) {
fp := File{
Name: "docker-bake.hcl",
Data: []byte(`
variable "FOO" {
default = ""
}
target "app" {
output = [FOO]
}
`),
}

ctx := context.TODO()

_, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
require.NoError(t, err)
}
31 changes: 30 additions & 1 deletion tests/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ target "build" {
args = {
HELLO = "foo"
}
cache-from = [
"type=gha,scope=build",
"type=s3,region=eu-west-1,bucket=mybucket",
"user/repo:cache",
]
cache-to = [
"type=gha,scope=build,mode=max",
"type=s3,region=eu-west-1,bucket=mybucket",
"type=inline"
]
output = [
"./release-out",
"type=registry,ref=user/app"
]
}
`)},
{
Expand Down Expand Up @@ -104,6 +118,7 @@ RUN echo "Hello ${HELLO}"
)

cmd := buildxCmd(sb, withDir(dir), withArgs("bake", "--print", "build"))
cmd.Env = append(cmd.Env, "AWS_ACCESS_KEY_ID=foo", "AWS_SECRET_ACCESS_KEY=bar")
stdout := bytes.Buffer{}
stderr := bytes.Buffer{}
cmd.Stdout = &stdout
Expand Down Expand Up @@ -140,7 +155,21 @@ RUN echo "Hello ${HELLO}"
"dockerfile": "Dockerfile",
"args": {
"HELLO": "foo"
}
},
"cache-from": [
"type=gha,scope=build",
"type=s3,region=eu-west-1,bucket=mybucket",
"type=inline"
],
"cache-to": [
"type=gha,scope=build,mode=max",
"type=s3,region=eu-west-1,bucket=mybucket",
"type=inline"
],
"output": [
"./release-out",
"type=registry,ref=user/app"
]
}
}
}
Expand Down

0 comments on commit 402d86a

Please sign in to comment.