MCPcopy Create free account
hub / github.com/docker/cli / toServicePortConfigs

Function toServicePortConfigs

cli/compose/loader/loader.go:919–956  ·  view source on GitHub ↗
(value string)

Source from the content-addressed store, hash-verified

917}
918
919func toServicePortConfigs(value string) ([]any, error) {
920 // short syntax ([ip:]public:private[/proto])
921 //
922 // TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
923 ports, portBindings, err := nat.ParsePortSpecs([]string{value})
924 if err != nil {
925 return nil, err
926 }
927 // We need to sort the key of the ports to make sure it is consistent
928 keys := make([]string, 0, len(ports))
929 for port := range ports {
930 keys = append(keys, string(port))
931 }
932 sort.Strings(keys)
933
934 var portConfigs []any
935 for _, key := range keys {
936 // Reuse ConvertPortToPortConfig so that it is consistent
937 port, err := network.ParsePort(key)
938 if err != nil {
939 return nil, err
940 }
941 portConfig, err := swarmopts.ConvertPortToPortConfig(port, portBindings)
942 if err != nil {
943 return nil, err
944 }
945 for _, p := range portConfig {
946 portConfigs = append(portConfigs, types.ServicePortConfig{
947 Protocol: string(p.Protocol),
948 Target: p.TargetPort,
949 Published: p.PublishedPort,
950 Mode: string(p.PublishMode),
951 })
952 }
953 }
954
955 return portConfigs, nil
956}
957
958func toMapStringString(value map[string]any, allowNil bool) map[string]any {
959 output := make(map[string]any)

Callers 1

loader.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…