Skip to content

Null value for tags when using with docker/metadata-action bake file output #3540

Closed

Description

@tk-nguyen

Contributing guidelines

I've found a bug, and:

  • The documentation does not mention anything about my problem
  • There are no open or closed issues that are related to my problem

Description

Hello! I'm using this action together with docker/metadata-action bake file output. I'm using the tags from docker-metadata-action target to generate image name.

Expected behaviour

It should build normally, using the tags from meta action.

Actual behaviour

The action errors out:

Error: docker/bake-action#1 [internal] load local bake definitions
docker/bake-action#1 reading ./docker-bake.hcl 320B / 320B done
docker/bake-action#1 reading /home/runner/work/_temp/docker-actions-toolkit-ZPTkvi/docker-metadata-action-bake-tags.json 247B / 247B done
docker/bake-action#1 reading /home/runner/work/_temp/docker-actions-toolkit-ZPTkvi/docker-metadata-action-bake-labels.json 643B / 643B done
docker/bake-action#1 reading /home/runner/work/_temp/docker-actions-toolkit-ZPTkvi/docker-metadata-action-bake-annotations.json 696B / 696B done
docker/bake-action#1 DONE 0.0s
./docker-bake.hcl:14
--------------------
  12 |     target "test" {
  13 |       inherits = ["_common"]
  14 | >>>   tags = generate_tags("docker.io", target.docker-metadata-action.tags)
  15 |     }
  16 |     
--------------------
ERROR: ./docker-bake.hcl:14,37-71: Invalid function argument; Invalid value for "tags" parameter: argument must not be null., and 1 other diagnostic(s)

Repository URL

https://github.com/tk-nguyen/docker-bake-demo (master branch is after when I moved the bake file with the tags last)

Workflow run URL

https://github.com/tk-nguyen/docker-bake-demo/actions/runs/8098999772/job/22133738961

YAML workflow

on:
  push:
    tags:
      - v*.*.*

name: Docker bake test

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          tags: |
            type=semver,pattern=v{{version}}
            type=semver,pattern=v{{major}}
            type=semver,pattern=v{{major}}.{{minor}}

      - name: Build and push
        uses: docker/bake-action@v4
        with:
          files: |
            ./docker-bake.hcl
            ${{ steps.meta.outputs.bake-file }}
            ${{ steps.meta.outputs.bake-file-annotations }}
          targets: test

Additional info

When I put the bake file with the tags last (either ${{ steps.meta.outputs.bake-file }} or ${{ steps.meta.outputs.bake-file-tags }}), it works perfectly, as seen here: https://github.com/tk-nguyen/docker-bake-demo/actions/runs/8099076031/job/22133989604

Activity

  1. changed the title [-]Tags merging problem when using with docker/metadata-action[/-] [+]Null value for `tags` when using with `docker/metadata-action` bake file output[/+] on Feb 29, 2024
  2. austinhallett commented on Sep 23, 2025

    @austinhallett

    Same issue for me

  3. polarathene commented on Nov 26, 2025

    @polarathene
  4. crazy-max commented on Nov 26, 2025

    @crazy-max
    Member
    target "docker-metadata-action" {}
    
    target "_common" {
      platforms = ["linux/amd64", "linux/arm64"]
      inherits = ["docker-metadata-action"]
    }
    
    function "generate_tags" {
      params = [repo, tags]
      result = formatlist("%s/test:%s", repo, tags)
    }
    
    target "test" {
      inherits = ["_common"]
      tags = generate_tags("docker.io", target.docker-metadata-action.tags)
    }

    When referencing multiple bake definitions in your workflow with first ${{ steps.meta.outputs.bake-file-tags }} that just contains tags like:

    {
      "target":{
        "docker-metadata-action":{
          "tags":[
            "master"
          ],
          "args":{
            "DOCKER_META_IMAGES":"",
            "DOCKER_META_VERSION":"master"
          }
        }
      }
    }

    And then ${{ steps.meta.outputs.bake-file-labels }} that just contains labels like:

    {
      "target":{
        "docker-metadata-action":{
          "labels":{
            "org.opencontainers.image.created":"2025-11-26T09:01:38.877Z",
            "org.opencontainers.image.description":"Test \"Docker\" Actions",
            "org.opencontainers.image.licenses":"MIT",
            "org.opencontainers.image.revision":"d250fdf571ba0488a715302417e182779e92412e",
            "org.opencontainers.image.source":"https://github.com/docker/test-docker-action",
            "org.opencontainers.image.title":"test-docker-action",
            "org.opencontainers.image.url":"https://github.com/docker/test-docker-action",
            "org.opencontainers.image.version":"master"
          }
        }
      }
    }

    It will fail with:

    $ docker buildx bake -f docker-bake.hcl -f tags.json -f labels.json test --print
    docker/bake-action#1 [internal] load local bake definitions
    docker/bake-action#1 reading docker-bake.hcl 379B / 379B done
    docker/bake-action#1 reading tags.json 194B / 194B done
    docker/bake-action#1 reading labels.json 659B / 659B done
    docker/bake-action#1 DONE 0.0s
    docker-bake.hcl:17
    --------------------
      15 |     target "test" {
      16 |       inherits = ["_common"]
      17 | >>>   tags = generate_tags("docker.io", target.docker-metadata-action.tags)
      18 |     }
      19 |
    --------------------
    ERROR: docker-bake.hcl:17,37-71: Invalid function argument; Invalid value for "tags" parameter: argument must not be null., and 1 other diagnostic(s)
    

    But not if you're referencing that tags definition last:

    $ docker buildx bake -f docker-bake.hcl -f labels.json -f tags.json test --print
    docker/bake-action#1 [internal] load local bake definitions
    docker/bake-action#1 reading docker-bake.hcl 379B / 379B done
    docker/bake-action#1 reading labels.json 659B / 659B done
    docker/bake-action#1 reading tags.json 194B / 194B done
    docker/bake-action#1 DONE 0.0s
    {
      "group": {
        "default": {
          "targets": [
            "test"
          ]
        }
      },
      "target": {
        "test": {
          "context": ".",
          "dockerfile": "Dockerfile",
          "args": {
            "DOCKER_META_IMAGES": "",
            "DOCKER_META_VERSION": "master"
          },
          "labels": {
            "org.opencontainers.image.created": "2025-11-26T09:01:38.877Z",
            "org.opencontainers.image.description": "Test \"Docker\" Actions",
            "org.opencontainers.image.licenses": "MIT",
            "org.opencontainers.image.revision": "d250fdf571ba0488a715302417e182779e92412e",
            "org.opencontainers.image.source": "https://github.com/docker/test-docker-action",
            "org.opencontainers.image.title": "test-docker-action",
            "org.opencontainers.image.url": "https://github.com/docker/test-docker-action",
            "org.opencontainers.image.version": "master"
          },
          "tags": [
            "docker.io/test:master"
          ],
          "platforms": [
            "linux/amd64",
            "linux/arm64"
          ]
        }
      }
    }
    

    Looking at your hcl definition, you are inheriting the target.docker-metadata-action.tags attribute: https://docs.docker.com/build/bake/inheritance/#reusing-single-attributes-from-targets

    And it seems target.docker-metadata-action.tags is solved before merging and not after which make it fails when labels definition is the last one.

    Also when building this bake definition alone you also have the same issue as not tags are defined:

    $ docker buildx bake test --print
    docker/bake-action#1 [internal] load local bake definitions
    docker/bake-action#1 reading docker-bake.hcl 362B / 362B done
    docker/bake-action#1 DONE 0.0s
    docker-bake.hcl:16
    --------------------
      14 |     target "test" {
      15 |       inherits = ["_common"]
      16 | >>>   tags = generate_tags("docker.io", target.docker-metadata-action.tags)
      17 |     }
      18 |
    --------------------
    ERROR: docker-bake.hcl:16,37-71: Invalid function argument; Invalid value for "tags" parameter: argument must not be null., and 1 other diagnostic(s)
    

    I'm moving this issue to the Buildx repo to address this.

  5. crazy-max commented on Nov 26, 2025

    @crazy-max
    Member

    Ah this is actually already tracked in #3173

  6. polarathene commented on Nov 28, 2025

    @polarathene

    So to clarify:

    • The report here was using the standard bake output from docker/metadata-action with all fields, and used inherits = ["docker-metadata-action"] as instructed by the action docs.
    • They then added a targets.docker-metadata-action.tags reference in a target to pass the tags to a function call for post-processing. This would work fine too.
    • For some unknown reason the user additionally added a separate annotations override file from docker/metadata-action, and that caused the problem discussed/tracked in Bake: target override using file breaks references to its tags list from other target #3173 but beyond that this is misconfiguration as it's redundant? (EDIT: My mistake, annotations is always treated as a separate bake output(src, docs)

    Placing annotations as an earlier override resolves the issue (provided you don't also need access to it via target.docker-metadata-action.annotations like was done with tags) 👍


    Raised an issue at docker/metadata-action for that specific concern to be resolved (which doesn't need to be dependent upon #3173).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions