-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Make port arg optional in docker compose port
#11874
Conversation
9670fd8
to
c87db39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, I have some small suggestions to improve your changes
cmd/compose/port.go
Outdated
Short: "Print the public port for a port binding", | ||
Args: cobra.MinimumNArgs(2), | ||
Use: "port [OPTIONS] SERVICE [PRIVATE_PORT]", | ||
Short: "List port mappings or a specific mapping for the service", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short: "List port mappings or a specific mapping for the service", | |
Short: "List port mappings or print the public port for a specific mapping for the service", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just the same help used in docker/cli
357c13b
to
21c0a70
Compare
Thanks for the review, I have taken care of your observations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cmd/compose/port.go
Outdated
PreRunE: Adapt(func(ctx context.Context, args []string) error { | ||
if len(args) == 1 { | ||
opts.list = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incompatibility with --index
should be tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should --index
be prohibited if no specific port was provided?
cmd/compose/port.go
Outdated
func runPort(ctx context.Context, dockerCli command.Cli, backend api.Service, opts portOptions, service string) error { | ||
projectName, err := opts.toProjectName(ctx, dockerCli) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if opts.list { | ||
summaries, err := backend.Ps(ctx, projectName, api.PsOptions{Services: []string{service}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better update backend.Port
so it can manage multiple services. Could return PortPublishers
cmd/compose/port.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if len(summaries) <= opts.index { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]ContainerSummary index is unrelated to replica index in service set by --index
.
cmd/compose/port.go
Outdated
} | ||
|
||
var format string | ||
if strings.Contains(publisher.URL, ":") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would make sense to me PortPublisher
has a String()
method to handle this, aligned with docker/cli
while not strictly required, I think we should use this opportunity while revisiting this command to add support for app_protocol and port name (https://github.com/compose-spec/compose-spec/blob/master/05-services.md#long-syntax-3) |
Wow, did not even know those existed. How do you envision it? Allow filtering? Or just displaying the name and app_protocol if they exist for the given port? |
This comand no longer needs a mandatory port. If no port is provided it will instead list all published ports. This behavior falls in line with the behavior provided by `docker port`. Closes docker#11859. Signed-off-by: Antonio Aguilar <antonio@zoftko.com>
21c0a70
to
96514e4
Compare
Went ahead and changed I think the only thing left is the question about |
@@ -26,18 +26,40 @@ import ( | |||
moby "github.com/docker/docker/api/types" | |||
) | |||
|
|||
func (s *composeService) Port(ctx context.Context, projectName string, service string, port uint16, options api.PortOptions) (string, int, error) { | |||
func (s *composeService) Port(ctx context.Context, projectName string, service string, port uint16, options api.PortOptions) (api.PortPublishers, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as signature changes, and breaks compatibility, makes sense to also rename Ports
(plural)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to denote information about more than one port can be returned. However wouldn't it be weird since it breaks the pattern of backend methods having the same name as their CLI command? Also if we were to rename the method, I think we should also rename the file to ports.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ndeloof Sorry to bother but do you have any thoughts on my comments? Should we still perform the renaming?
|
What I did
This comand no longer needs a mandatory port. If no port is provided it will instead list all published ports. This behavior falls in line with the behavior provided by
docker port
.Related issue
Closes #11859.