11package convert
22
33import (
4- "fmt"
54 "os"
65 "sort"
76 "strings"
@@ -134,7 +133,7 @@ func Service(
134133 Hosts : convertExtraHosts (service .ExtraHosts ),
135134 DNSConfig : dnsConfig ,
136135 Healthcheck : healthcheck ,
137- Env : sortStrings ( convertEnvironment (service .Environment ) ),
136+ Env : convertEnvironment (service .Environment ),
138137 Labels : AddStackLabel (namespace , service .Labels ),
139138 Dir : service .WorkingDir ,
140139 User : service .User ,
@@ -200,11 +199,6 @@ func getPlacementPreference(preferences []composetypes.PlacementPreferences) []s
200199 return result
201200}
202201
203- func sortStrings (strs []string ) []string {
204- sort .Strings (strs )
205- return strs
206- }
207-
208202func convertServiceNetworks (
209203 networks map [string ]* composetypes.ServiceNetworkConfig ,
210204 networkConfigs networkMap ,
@@ -597,6 +591,8 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
597591 }
598592}
599593
594+ // convertEnvironment converts key/value mappings to a slice, and sorts
595+ // the results.
600596func convertEnvironment (source map [string ]* string ) []string {
601597 var output []string
602598
@@ -605,10 +601,10 @@ func convertEnvironment(source map[string]*string) []string {
605601 case nil :
606602 output = append (output , name )
607603 default :
608- output = append (output , fmt . Sprintf ( "%s=%s" , name , * value ) )
604+ output = append (output , name + "=" + * value )
609605 }
610606 }
611-
607+ sort . Strings ( output )
612608 return output
613609}
614610
0 commit comments