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

How to do optional Tags in bake? #427

Closed
AnthonyPoschen opened this issue Oct 26, 2020 · 2 comments · Fixed by #428
Closed

How to do optional Tags in bake? #427

AnthonyPoschen opened this issue Oct 26, 2020 · 2 comments · Fixed by #428

Comments

@AnthonyPoschen
Copy link
Contributor

I am trying to only add tags if a variable is none empty, primarily fetching if the git commit has a version tag and if so i would like to push that tag. below is an example bake file demonstrating where i am at.

variable "TAG" {default="" }

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

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

null type is not allowed in arrays. An empty string will throw an error in the docker build. Not sure how to implement optional entries into an array. I also could not find a way to do appending with the tags assign.

wonder if it would be wiser to have empty strings be ignored for tagging to allow empty string results.

@AnthonyPoschen
Copy link
Contributor Author

the following function should be able to resolve this

https://github.com/zclconf/go-cty/blob/main/cty/function/stdlib/collection.go#L265

resulting tags block would probably look like

tags = "${compact(["myimage",null,""])}"

is it easy to multi line?

@AnthonyPoschen
Copy link
Contributor Author

Raised a PR which offers 2 solutions in one to allow conditional tag inclusions. p.s i have really enjoyed using buildx to reduce build complexity :)

tonistiigi added a commit that referenced this issue Dec 8, 2020
fixes #427: Handle empty strings in elements enabling conditional logic
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 a pull request may close this issue.

1 participant