diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 6935c61968..bb9255d581 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -133,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, @@ -199,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, @@ -596,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 @@ -607,7 +604,7 @@ func convertEnvironment(source map[string]*string) []string { 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)) }