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

bake: replace --list-targets and --list-variables flags with --list flag #2900

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

crazy-max
Copy link
Member

follow-up #2556 (review)

  • Replace --list-targets and --list-variables flags with --list flag and put it out of experimental.
  • --print and --list are now mutually exclusive.
  • Add json format support for --list flag.
$ docker buildx bake --list=targets
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 4.97kB / 4.97kB done
#1 DONE 0.0s
TARGET                          DESCRIPTION
binaries
binaries-cross
default                         binaries
govulncheck
image
image-cross
image-local
integration-test
integration-test-base
lint
lint-gopls
meta-helper
mod-outdated
release
test
update-authors
update-docs
update-generated-files
update-vendor
validate                        lint, lint-gopls, validate-docs, validate-golangci, validate-vendor
validate-authors
validate-docs
validate-generated-files
validate-golangci               Validate .golangci.yml schema (does not run Go linter)
validate-vendor
$ docker buildx bake --list=variables
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 4.97kB / 4.97kB done
#1 DONE 0.0s
VARIABLE                        VALUE   DESCRIPTION
DESTDIR                         ./bin
DOCS_FORMATS                    md
GOLANGCI_LINT_MULTIPLATFORM
GOVULNCHECK_FORMAT              <null>
GO_VERSION                      <null>
HTTPS_PROXY
HTTP_PROXY
NO_PROXY
TEST_BUILDKIT_TAG               <null>
TEST_COVERAGE                   <null>
$ docker buildx bake --list=type=targets,format=json
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 4.97kB / 4.97kB done
#1 DONE 0.0s
[
  {
    "name": "binaries"
  },
  {
    "name": "binaries-cross"
  },
  {
    "name": "default",
    "description": "binaries",
    "group": true
  },
  {
    "name": "govulncheck"
  },
  {
    "name": "image"
  },
  {
    "name": "image-cross"
  },
  {
    "name": "image-local"
  },
  {
    "name": "integration-test"
  },
  {
    "name": "integration-test-base"
  },
  {
    "name": "lint"
  },
  {
    "name": "lint-gopls"
  },
  {
    "name": "meta-helper"
  },
  {
    "name": "mod-outdated"
  },
  {
    "name": "release"
  },
  {
    "name": "test"
  },
  {
    "name": "update-authors"
  },
  {
    "name": "update-docs"
  },
  {
    "name": "update-generated-files"
  },
  {
    "name": "update-vendor"
  },
  {
    "name": "validate",
    "description": "lint, lint-gopls, validate-docs, validate-golangci, validate-vendor",
    "group": true
  },
  {
    "name": "validate-authors"
  },
  {
    "name": "validate-docs"
  },
  {
    "name": "validate-generated-files"
  },
  {
    "name": "validate-golangci",
    "description": "Validate .golangci.yml schema (does not run Go linter)"
  },
  {
    "name": "validate-vendor"
  }
]
$ docker buildx bake --list=type=variables,format=json
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 4.97kB / 4.97kB done
#1 DONE 0.0s
[
  {
    "name": "DESTDIR",
    "value": "./bin"
  },
  {
    "name": "DOCS_FORMATS",
    "value": "md"
  },
  {
    "name": "GOLANGCI_LINT_MULTIPLATFORM",
    "value": ""
  },
  {
    "name": "GOVULNCHECK_FORMAT"
  },
  {
    "name": "GO_VERSION"
  },
  {
    "name": "HTTPS_PROXY",
    "value": ""
  },
  {
    "name": "HTTP_PROXY",
    "value": ""
  },
  {
    "name": "NO_PROXY",
    "value": ""
  },
  {
    "name": "TEST_BUILDKIT_TAG"
  },
  {
    "name": "TEST_COVERAGE"
  }
]

@crazy-max crazy-max changed the title Bake list flag bake: replace --list-targets and --list-variables flags with --list flag Jan 9, 2025
Comment on lines +671 to +694
type targetList struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Group bool `json:"group,omitempty"`
}
Copy link
Member Author

@crazy-max crazy-max Jan 9, 2025

Choose a reason for hiding this comment

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

Was wondering if instead it would have been better to use groups and targets field:

$ docker buildx bake --list=type=targets,format=json
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 4.97kB / 4.97kB done
#1 DONE 0.0s
{
  "groups": [
    {
      "name": "default",
      "targets": ["binaries"]
    },
    {
      "name": "validate",
      "targets": ["lint", "lint-gopls", "validate-docs", "validate-golangci", "validate-vendor"]
    }
  ],
  "targets": [
    {
      "name": "binaries"
    },
    {
      "name": "binaries-cross"
    },
    {
      "name": "govulncheck"
    },
    {
      "name": "image"
    },
    {
      "name": "image-cross"
    },
    {
      "name": "image-local"
    },
    {
      "name": "integration-test"
    },
    {
      "name": "integration-test-base"
    },
    {
      "name": "lint"
    },
    {
      "name": "lint-gopls"
    },
    {
      "name": "meta-helper"
    },
    {
      "name": "mod-outdated"
    },
    {
      "name": "release"
    },
    {
      "name": "test"
    },
    {
      "name": "update-authors"
    },
    {
      "name": "update-docs"
    },
    {
      "name": "update-generated-files"
    },
    {
      "name": "update-vendor"
    },
    {
      "name": "validate-authors"
    },
    {
      "name": "validate-docs"
    },
    {
      "name": "validate-generated-files"
    },
    {
      "name": "validate-golangci",
      "description": "Validate .golangci.yml schema (does not run Go linter)"
    },
    {
      "name": "validate-vendor"
    }
  ]
}

It's a bit inconsistent with table format but more readable imo.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about completely separating this, but in JSON view I think separate fields for description and subtargets would make sense.

@crazy-max crazy-max marked this pull request as ready for review January 9, 2025 12:09
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.

2 participants