Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
return nil, err
}

// short syntax ([ip:]public:private[/proto])
//
// TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
ports, natPortBindings, err := nat.ParsePortSpecs(convertedOpts)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions cli/compose/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,9 @@ var transformStringToDuration TransformerFunc = func(value any) (any, error) {
}

func toServicePortConfigs(value string) ([]any, error) {
var portConfigs []any

// short syntax ([ip:]public:private[/proto])
//
// TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
ports, portBindings, err := nat.ParsePortSpecs([]string{value})
if err != nil {
return nil, err
Expand All @@ -931,6 +932,7 @@ func toServicePortConfigs(value string) ([]any, error) {
}
sort.Strings(keys)

var portConfigs []any
for _, key := range keys {
// Reuse ConvertPortToPortConfig so that it is consistent
port, err := network.ParsePort(key)
Expand Down
11 changes: 6 additions & 5 deletions opts/swarmopts/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func (p *PortOpt) Set(value string) error {

p.ports = append(p.ports, pConfig)
} else {
// short syntax
// short syntax ([ip:]public:private[/proto])
//
// TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
ports, portBindingMap, err := nat.ParsePortSpecs([]string{value})
if err != nil {
return err
Expand Down Expand Up @@ -162,18 +164,17 @@ func ConvertPortToPortConfig(
logrus.Warnf("ignoring IP-address (%s:%s) service will listen on '0.0.0.0'", net.JoinHostPort(binding.HostIP, binding.HostPort), portProto.String())
}

startHostPort, endHostPort, err := nat.ParsePortRange(binding.HostPort)

pr, err := network.ParsePortRange(binding.HostPort)
if err != nil && binding.HostPort != "" {
return nil, fmt.Errorf("invalid hostport binding (%s) for port (%d)", binding.HostPort, portProto.Num())
}

for i := startHostPort; i <= endHostPort; i++ {
for p := range pr.All() {
ports = append(ports, swarm.PortConfig{
// TODO Name: ?
Protocol: portProto.Proto(),
TargetPort: uint32(portProto.Num()),
PublishedPort: uint32(i),
PublishedPort: uint32(p.Num()),
PublishMode: swarm.PortConfigPublishModeIngress,
})
}
Expand Down
Loading