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

fixes #427: Handle empty strings in elements enabling conditional logic #428

Merged
merged 3 commits into from
Dec 8, 2020

Conversation

AnthonyPoschen
Copy link
Contributor

this change aims to resolve #427 by allowing either the compact function to be used and also allowing empty strings to be present in the resulting bake file and stripping them out of the final file before actioning.

example file 1 with compact.

variable "TAG" {default="" }

group "default" {
	targets = [
    "app",
  ]
}

target "app" {
  context="."
  dockerfile="Dockerfile"
  tags = "${compact([
      "my-image:latest",
      notequal("",TAG) ? "my-image:${TAG}-1": "",
      notequal("",TAG) ? "my-image:${TAG}-2": null,
      null,
    ])}"
}

Example 2 with allowing empty strings in arrays will no longer cause any issues with docker push as they are stripped.


group "default" {
	targets = [
    "app",
  ]
}

target "app" {
  context="."
  dockerfile="Dockerfile"
  tags = [
      "my-image:latest",
      notequal("",TAG) ? "my-image:${TAG}-1": "",
      notequal("",TAG) ? "my-image:${TAG}-2": "",
  ]
}

the above two config files results in the below print

❯ docker buildx bake --print
{
   "target": {
      "app": {
         "context": ".",
         "dockerfile": "Dockerfile",
         "tags": [
            "my-image:latest"
         ]
      }
   }
}

❯ TAG="ok" docker buildx bake --print
{
   "target": {
      "app": {
         "context": ".",
         "dockerfile": "Dockerfile",
         "tags": [
            "my-image:latest",
            "my-image:ok-1",
            "my-image:ok-2"
         ]
      }
   }
}```

@AnthonyPoschen AnthonyPoschen changed the title Handle empty strings in elements enabling conditional logic fixes #427: Handle empty strings in elements enabling conditional logic Oct 26, 2020
@AnthonyPoschen
Copy link
Contributor Author

Hi @tonistiigi i would really like to get this into the next release if possible, if anything needs to be changed or modified please let me know.

Signed-off-by: Tonis Tiigi <[email protected]>
@tonistiigi tonistiigi merged commit 0360668 into docker:master Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to do optional Tags in bake?
2 participants