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

Proposal: flag to list bake targets #1072

Closed
crazy-max opened this issue Apr 14, 2022 · 7 comments
Closed

Proposal: flag to list bake targets #1072

crazy-max opened this issue Apr 14, 2022 · 7 comments
Assignees
Labels
area/bake kind/enhancement New feature or request
Milestone

Comments

@crazy-max
Copy link
Member

crazy-max commented Apr 14, 2022

Atm the bake definition needs to be opened to find out available targets. This is not practical and should be available through the cli.

Suggest to add a --targets or --list flag for bake cmd that would list the available targets.

Targets would need a description field to be displayed:

variable "GO_VERSION" {
  default = "1.17"
}

target "_common" {
  args = {
    GO_VERSION = GO_VERSION
  }
}

target "lint" {
  description = "Validate using golangci-lint and yamllint linters"
  inherits = ["_common"]
  dockerfile = "./hack/dockerfiles/lint.Dockerfile"
  output = ["type=cacheonly"]
}

target "test" {
  description = "Runs tests suite" 
  inherits = ["_common"]
  target = "test-coverage"
  output = ["./coverage"]
}

target "binaries" {
  description = "Build binaries for the current platform"
  inherits = ["_common"]
  target = "binaries"
  output = ["./bin"]
  platforms = ["local"]
}

target "binaries-cross" {
  description = "Build binaries for multi platform"
  inherits = ["binaries"]
  platforms = [
    "darwin/amd64",
    "darwin/arm64",
    "linux/amd64",
    "linux/arm/v6",
    "linux/arm/v7",
    "linux/arm64",
    "linux/ppc64le",
    "linux/riscv64",
    "linux/s390x",
    "windows/amd64",
    "windows/arm64"
  ]
}
$ docker buildx bake --list
lint:           Validate using golangci-lint and yamllint linters
test:           Runs tests suite
binaries:       Build binaries for the current platform
binaries-cross: Build binaries for multi platform

Targets that don't specify a description will not be displayed.

This flag cannot be used if a target is specified.

For compose it might be tricky as there is no such field in the compose spec that we could use. Maybe a comment can work in this case but not supported with JSON format:

# Build binaries for the current platform
target "binaries" {
  inherits = ["_common"]
  target = "binaries"
  output = ["./bin"]
  platforms = ["local"]
}
services:
  binaries: # Build binaries for the current platform
    build:
      target: binaries

Or an extra arg to target:

target "binaries" "Build binaries for the current platform" {
  inherits = ["_common"]
  target = "binaries"
  output = ["./bin"]
  platforms = ["local"]
}

But again not suitable for a JSON representation as well as a compose file.

Open to suggestions.

@crazy-max crazy-max added kind/enhancement New feature or request area/bake labels Apr 14, 2022
@thaJeztah
Copy link
Member

This looks useful, but wondering if we want to limit it to just targets; variables could be important as well (?) Perhaps a command that (pretty)prints information about the bake file?

@skaldesh
Copy link

Why exclude targets without a description? I think its useful to have them printed regardless

@crazy-max
Copy link
Member Author

We should also take a look at what is currently done in just: https://github.com/casey/just#command-line-options

@jedevc
Copy link
Collaborator

jedevc commented Apr 25, 2022

This looks useful, but wondering if we want to limit it to just targets; variables could be important as well (?) Perhaps a command that (pretty)prints information about the bake file?

I think this is a slightly different case than printing out the targets/groups, as far as I'm aware the variables are an hcl-level concept, and are removed upon parsing?

@thaJeztah
Copy link
Member

I think this is a slightly different case than printing out the targets/groups, as far as I'm aware the variables are an hcl-level concept, and are removed upon parsing?

Possibly, yes. My view on this was; "what information would I be looking for (as a user) that I can pass to buildx bake to control the build?"; one of that is the target to build, but other parameters can be variables that it takes.

@jedevc
Copy link
Collaborator

jedevc commented Feb 8, 2023

Is there anything blocking starting development on this? I'm happy to take a look.

I wonder if we could automagically extract descriptions from the Dockerfile using the new --print feature, if the target stage has a comment? And then allow overriding with the description bake field?

@jsternberg
Copy link
Collaborator

This seems to have already been done in #2556. I'm going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bake kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants