Skip to content

Conversation

@crazy-max
Copy link
Member

@crazy-max crazy-max commented Jan 5, 2026

variable "ALPINE_VERSION" {
  default = "3.23"
}

target "default" {
  dockerfile = "Dockerfile.webapp"
  platforms = semvercmp(ALPINE_VERSION, ">= 3.20") ? [
    "linux/amd64",
    "linux/arm64",
    "linux/riscv64"
  ] : [
    "linux/amd64",
    "linux/arm64"
  ]
}
$ docker buildx bake --print
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 275B / 275B done
#1 DONE 0.0s
{
  "group": {
    "default": {
      "targets": [
        "default"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile.webapp",
      "platforms": [
        "linux/amd64",
        "linux/arm64",
        "linux/riscv64"
      ]
    }
  }
}
$ ALPINE_VERSION=3.19 docker buildx bake --print
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 275B / 275B done
#1 DONE 0.0s
{
  "group": {
    "default": {
      "targets": [
        "default"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile.webapp",
      "platforms": [
        "linux/amd64",
        "linux/arm64"
      ]
    }
  }
}
$ ALPINE_VERSION=latest docker buildx bake --print
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 275B / 275B done
#1 DONE 0.0s
docker-bake.hcl:7
--------------------
   5 |     target "default" {
   6 |       dockerfile = "Dockerfile.webapp"
   7 | >>>   platforms = semvercmp(ALPINE_VERSION, ">= 3.20") ? [
   8 |         "linux/amd64",
   9 |         "linux/arm64",
--------------------
ERROR: docker-bake.hcl:7,15-32: Error in function call; Call to function "semvercmp" failed: invalid semantic version., and 1 other diagnostic(s)

@crazy-max crazy-max added this to the v0.31.0 milestone Jan 5, 2026
@crazy-max crazy-max marked this pull request as ready for review January 5, 2026 09:18
}
```

## `versionsatisfies`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe drop a link to https://github.com/Masterminds/semver here, for the constraint syntax reference.

(I know this doc is pretty bare atm, need to do a pass on this at some point.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link to docs

Copy link
Contributor

@dvdksn dvdksn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tonistiigi
Copy link
Member

What about smth like semvercmp, semvercheck?

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max crazy-max changed the title bake: add versionsatisfies func to stdlib bake: add semvercmp func to stdlib Jan 6, 2026
@tonistiigi tonistiigi merged commit 5546d17 into docker:master Jan 6, 2026
140 checks passed
@crazy-max crazy-max deleted the bake-semver-stdlib branch January 6, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants