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

Inconsistent groups behaviour with "default" target #2859

Open
3 tasks done
klutchell opened this issue Dec 13, 2024 · 1 comment · May be fixed by #2863
Open
3 tasks done

Inconsistent groups behaviour with "default" target #2859

klutchell opened this issue Dec 13, 2024 · 1 comment · May be fixed by #2863
Labels
area/bake kind/bug Something isn't working
Milestone

Comments

@klutchell
Copy link

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

@crazy-max
Copy link
Member

docker buildx bake -f tests/docker-bake.hcl --print default multiarch

I agree that it should have both default and multiarch in targets. It seems related to this change 77b3326, I will take a look.

@crazy-max crazy-max added kind/bug Something isn't working area/bake and removed status/needs-investigation labels Dec 16, 2024
@crazy-max crazy-max modified the milestones: v0.20.0, v0.19.3 Dec 16, 2024
@tonistiigi tonistiigi modified the milestones: v0.19.3, v0.20.0 Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bake kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants