Skip to content

Inconsistent groups behaviour with "default" target #2859

@klutchell

Description

@klutchell

Contributing guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

If bake file contains a target named default the parsing behaviour is different for that target than other target names.

This is apparent when processing the files with the --print option, and a default group is generated if one is not defined in the bake file.

Expected behaviour

Versions v0.9.1 and earlier correctly include all named targets in the default group.

target "default" {
  dockerfile = "Dockerfile"
  platforms = [
    "linux/amd64"
  ]
}

target "multiarch" {
  dockerfile = "Dockerfile"
  platforms = [
    "linux/amd64",
    "linux/arm64",
    "linux/arm/v7",
    "linux/arm/v6"
  ]
}
docker buildx bake --print default multiarch -f docker-bake.hcl
{
  "group": {
    "default": {
      "targets": [
        "default",
        "multiarch"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "platforms": [
        "linux/amd64"
      ]
    },
    "multiarch": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "platforms": [
        "linux/amd64",
        "linux/arm64",
        "linux/arm/v7",
        "linux/arm/v6"
      ]
    }
  }
}

Actual behaviour

This inconsistent behaviour has actually been present since v0.10.0.

Depending on the title of the named targets, some may be omitted from the resulting group with no warning or error.

If default is not a valid name for a target, there should be a warning or error to that effect. Instead it silently ignores the target when processing bake files with multiple targets.

Buildx version

github.com/docker/buildx v0.19.1 5113f9e

Docker info

/usr/bin/docker version
  Client: Docker Engine - Community
   Version:           27.3.1
   API version:       1.47
   Go version:        go1.22.7
   Git commit:        ce12230
   Built:             Fri Sep 20 11:41:00 2024
   OS/Arch:           linux/amd64
   Context:           default
  
  Server: Docker Engine - Community
   Engine:
    Version:          27.3.1
    API version:      1.47 (minimum version 1.24)
    Go version:       go1.22.7
    Git commit:       41ca978
    Built:            Fri Sep 20 11:41:00 2024
    OS/Arch:          linux/amd64
    Experimental:     false
   containerd:
    Version:          1.7.24
    GitCommit:        88bf19b2105c8b17560993bee28a01ddc2f97182
   runc:
    Version:          1.2.2
    GitCommit:        v1.2.2-0-g7cb3632
   docker-init:
    Version:          0.19.0
    GitCommit:        de40ad0
  /usr/bin/docker info
  Client: Docker Engine - Community
   Version:    27.3.1
   Context:    default
   Debug Mode: false
   Plugins:
    buildx: Docker Buildx (Docker Inc.)
      Version:  v0.17.1
      Path:     /usr/libexec/docker/cli-plugins/docker-buildx
    compose: Docker Compose (Docker Inc.)
      Version:  v2.29.7
      Path:     /usr/libexec/docker/cli-plugins/docker-compose
  
  Server:
   Containers: 0
    Running: 0
    Paused: 0
    Stopped: 0
   Images: 0
   Server Version: 27.3.1
   Storage Driver: overlay2
    Backing Filesystem: extfs
    Supports d_type: true
    Using metacopy: false
    Native Overlay Diff: true
    userxattr: false
   Logging Driver: json-file
   Cgroup Driver: cgroupfs
   Cgroup Version: 1
   Plugins:
    Volume: local
    Network: bridge host ipvlan macvlan null overlay
    Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
   Swarm: inactive
   Runtimes: io.containerd.runc.v2 runc
   Default Runtime: runc
   Init Binary: docker-init
   containerd version: 88bf19b2105c8b17560993bee28a01ddc2f97182
   runc version: v1.2.2-0-g7cb3632
   init version: de40ad0
   Security Options:
    seccomp
     Profile: builtin
   Kernel Version: 5.10.0+
   Operating System: Ubuntu 22.04.5 LTS
   OSType: linux
   Architecture: x86_64
   CPUs: 4
   Total Memory: 7.773GiB
   Name: c87fae9-runner-jammy-3
   ID: f44196c7-eff5-4472-a2f2-c8d3c4fc9157
   Docker Root Dir: /var/lib/docker
   Debug Mode: false
   Experimental: false
   Insecure Registries:
    registry-cache:5000
    127.0.0.0/8
   Registry Mirrors:
    http://registry-cache:5000/
   Live Restore Enabled: false
   Default Address Pools:
     Base: 10.93.116.0/24, Size: 27

Builders list

{
    "nodes": [
      {
        "name": "builder-d2b90db5-8da7-4dd8-9611-0d2f61285df70",
        "endpoint": "unix:///var/run/docker.sock",
        "driver-opts": [
          "network=host"
        ],
        "status": "running",
        "buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
        "buildkit": "v0.18.1",
        "platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/386",
        "features": {
          "Automatically load images to the Docker Engine image store": true,
          "Cache export": true,
          "Docker exporter": true,
          "Multi-platform build": true,
          "OCI exporter": true
        },
        "labels": {
          "org.mobyproject.buildkit.worker.executor": "oci",
          "org.mobyproject.buildkit.worker.hostname": "c87fae9-runner-jammy-3",
          "org.mobyproject.buildkit.worker.network": "host",
          "org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
          "org.mobyproject.buildkit.worker.selinux.enabled": "false",
          "org.mobyproject.buildkit.worker.snapshotter": "overlayfs"
        },
        "gcPolicy": [
          {
            "all": false,
            "filter": [
              "type==source.local",
              "type==exec.cachemount",
              "type==source.git.checkout"
            ],
            "keepDuration": "48h0m0s"
          },
          {
            "all": false,
            "keepDuration": "1440h0m0s"
          },
          {
            "all": false
          },
          {
            "all": true
          }
        ]
      }
    ],
    "name": "builder-d2b90db5-8da7-4dd8-9611-0d2f61285df7",
    "driver": "docker-container",
    "lastActivity": "2024-12-13T19:08:37.000Z"
  }

Configuration

target "default" {
  dockerfile = "Dockerfile"
  platforms = [
    "linux/amd64"
  ]
}

target "multiarch" {
  dockerfile = "Dockerfile"
  platforms = [
    "linux/amd64",
    "linux/arm64",
    "linux/arm/v7",
    "linux/arm/v6"
  ]
}

For the multiarch target we see a default group is created including the named target.

docker buildx bake -f tests/docker-bake.hcl --print multiarch        
{
  "group": {
    "default": {
      "targets": [
        "multiarch"
      ]
    }
  },
  "target": {
    "multiarch": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "platforms": [
        "linux/amd64",
        "linux/arm64",
        "linux/arm/v7",
        "linux/arm/v6"
      ]
    }
  }
}

For the default target we do not see any group get created.

docker buildx bake -f tests/docker-bake.hcl --print default  
{
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "platforms": [
        "linux/amd64"
      ]
    }
  }
}

For the default and multiarch target in one command, we see the default group is created but the default target has been omitted.

docker buildx bake -f tests/docker-bake.hcl --print default multiarch
{
  "group": {
    "default": {
      "targets": [
        "multiarch"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "platforms": [
        "linux/amd64"
      ]
    },
    "multiarch": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "platforms": [
        "linux/amd64",
        "linux/arm64",
        "linux/arm/v7",
        "linux/arm/v6"
      ]
    }
  }
}

Build logs


Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions