Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bake: support null arg and label value #1449

Merged
merged 2 commits into from
Dec 15, 2022

Conversation

crazy-max
Copy link
Member

follow-up #1362 (comment)

variable "GO_VERSION" {
  default = ""
}
target "default" {
  args = {
    GO_VERSION = GO_VERSION
  }
}
ARG GO_VERSION="1.18"
FROM golang:${GO_VERSION}
$ docker buildx bake --print
{
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "args": {
        "GO_VERSION": ""
      }
    }
  }
}

In this example, GO_VERSION arg will always be sent in the request and overwrites the one in the Dockerfile. Therefore build would fail as GO_VERSION will be empty.

With this PR, null type is now handled and will set the arg only if set:

variable "GO_VERSION" {
  default = null
}
target "default" {
  args = {
    GO_VERSION = GO_VERSION
  }
}
$ docker buildx bake --print
{
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile"
    }
  }
}
$ GO_VERSION=1.19 docker buildx bake --print
{
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "args": {
        "GO_VERSION": "1.19"
      }
    }
  }
}

Signed-off-by: CrazyMax [email protected]

@crazy-max
Copy link
Member Author

crazy-max commented Dec 3, 2022

Including a null value in a string template is not yet supported:

variable "GO_VERSION" {
  default = null
}
target "default" {
  args = {
    GO_VERSION = "${GO_VERSION}-alpine"
  }
}

This will lead to:

Invalid template interpolation value; The expression result is null. Cannot include a null value in a string template.

We could convert to the expected type.

bake/hclparser/expr.go Outdated Show resolved Hide resolved
@crazy-max crazy-max added area/bake kind/enhancement New feature or request labels Dec 3, 2022
@crazy-max crazy-max force-pushed the bake-var-null branch 2 times, most recently from deac246 to 2ad47c0 Compare December 5, 2022 21:33
@crazy-max crazy-max changed the title bake: support null args bake: support null arg and labels value Dec 5, 2022
@crazy-max crazy-max changed the title bake: support null arg and labels value bake: support null arg and label value Dec 5, 2022
@crazy-max crazy-max marked this pull request as ready for review December 5, 2022 21:34
@crazy-max crazy-max force-pushed the bake-var-null branch 2 times, most recently from 0eadb81 to 3ba3dc2 Compare December 8, 2022 19:06
@tonistiigi tonistiigi added this to the v0.10.0 milestone Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bake kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants