Skip to content

How to do optional Tags in bake? #427

@AnthonyPoschen

Description

@AnthonyPoschen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions