diff --git a/cli/command/config/formatter.go b/cli/command/config/formatter.go index 4aebdb61ac..ee8bc23467 100644 --- a/cli/command/config/formatter.go +++ b/cli/command/config/formatter.go @@ -103,7 +103,7 @@ func (c *configContext) Labels() string { } var joinLabels []string for k, v := range mapLabels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) + joinLabels = append(joinLabels, k+"="+v) } return strings.Join(joinLabels, ",") } diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 1ad4ba6c52..bd594124d0 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -91,7 +91,7 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio if v == nil { newEnv = append(newEnv, k) } else { - newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, *v)) + newEnv = append(newEnv, k+"="+*v) } } copts.env = *opts.NewListOptsRef(&newEnv, nil) diff --git a/cli/command/container/run.go b/cli/command/container/run.go index fe4969cd0b..b171450c91 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -101,7 +101,7 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt if v == nil { newEnv = append(newEnv, k) } else { - newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, *v)) + newEnv = append(newEnv, k+"="+*v) } } copts.env = *opts.NewListOptsRef(&newEnv, nil) diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index 60ad2fa40b..22b144f98f 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -247,7 +247,7 @@ func (c *ContainerContext) Labels() string { var joinLabels []string for k, v := range c.c.Labels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) + joinLabels = append(joinLabels, k+"="+v) } return strings.Join(joinLabels, ",") } diff --git a/cli/command/network/formatter.go b/cli/command/network/formatter.go index ed8ac257a0..3229dfdd0a 100644 --- a/cli/command/network/formatter.go +++ b/cli/command/network/formatter.go @@ -103,7 +103,7 @@ func (c *networkContext) Labels() string { var joinLabels []string for k, v := range c.n.Labels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) + joinLabels = append(joinLabels, k+"="+v) } return strings.Join(joinLabels, ",") } diff --git a/cli/command/secret/formatter.go b/cli/command/secret/formatter.go index 9102f28856..33c1451249 100644 --- a/cli/command/secret/formatter.go +++ b/cli/command/secret/formatter.go @@ -110,7 +110,7 @@ func (c *secretContext) Labels() string { } var joinLabels []string for k, v := range mapLabels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) + joinLabels = append(joinLabels, k+"="+v) } return strings.Join(joinLabels, ",") } diff --git a/cli/command/system/events.go b/cli/command/system/events.go index ddac0fa0a0..08b0e47992 100644 --- a/cli/command/system/events.go +++ b/cli/command/system/events.go @@ -133,7 +133,7 @@ func prettyPrintEvent(out io.Writer, event eventtypes.Message) error { sort.Strings(keys) for _, k := range keys { v := event.Actor.Attributes[k] - attrs = append(attrs, fmt.Sprintf("%s=%s", k, v)) + attrs = append(attrs, k+"="+v) } fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", ")) } diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 7e0b8cfc99..bb9255d581 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -1,7 +1,6 @@ package convert import ( - "fmt" "os" "sort" "strings" @@ -134,7 +133,7 @@ func Service( Hosts: convertExtraHosts(service.ExtraHosts), DNSConfig: dnsConfig, Healthcheck: healthcheck, - Env: sortStrings(convertEnvironment(service.Environment)), + Env: convertEnvironment(service.Environment), Labels: AddStackLabel(namespace, service.Labels), Dir: service.WorkingDir, User: service.User, @@ -200,11 +199,6 @@ func getPlacementPreference(preferences []composetypes.PlacementPreferences) []s return result } -func sortStrings(strs []string) []string { - sort.Strings(strs) - return strs -} - func convertServiceNetworks( networks map[string]*composetypes.ServiceNetworkConfig, networkConfigs networkMap, @@ -597,6 +591,8 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC } } +// convertEnvironment converts key/value mappings to a slice, and sorts +// the results. func convertEnvironment(source map[string]*string) []string { var output []string @@ -605,10 +601,10 @@ func convertEnvironment(source map[string]*string) []string { case nil: output = append(output, name) default: - output = append(output, fmt.Sprintf("%s=%s", name, *value)) + output = append(output, name+"="+*value) } } - + sort.Strings(output) return output } diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 7a23548e9e..4d48acc3ea 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -3,7 +3,6 @@ package convert import ( "context" "os" - "sort" "strings" "testing" "time" @@ -59,7 +58,6 @@ func TestConvertEnvironment(t *testing.T) { "key": strPtr("value"), } env := convertEnvironment(source) - sort.Strings(env) assert.Check(t, is.DeepEqual([]string{"foo=bar", "key=value"}, env)) }