Browse code

cli: Preserve order of environment variables

Unless we are adding or removing environment variables, their order
shouldn't be changed. This makes it look like the service's TaskSpec has
changed relative to the old version of the service, and containers need
to be redeployed.

The existing code always rebuilds the list of environment variables by
converting them to a map and back, but there's no reason to do this if
no environment variables are being added.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2017/04/05 10:16:57
Showing 1 changed files
... ...
@@ -524,20 +524,21 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
524 524
 }
525 525
 
526 526
 func updateEnvironment(flags *pflag.FlagSet, field *[]string) {
527
-	envSet := map[string]string{}
528
-	for _, v := range *field {
529
-		envSet[envKey(v)] = v
530
-	}
531 527
 	if flags.Changed(flagEnvAdd) {
528
+		envSet := map[string]string{}
529
+		for _, v := range *field {
530
+			envSet[envKey(v)] = v
531
+		}
532
+
532 533
 		value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts)
533 534
 		for _, v := range value.GetAll() {
534 535
 			envSet[envKey(v)] = v
535 536
 		}
536
-	}
537 537
 
538
-	*field = []string{}
539
-	for _, v := range envSet {
540
-		*field = append(*field, v)
538
+		*field = []string{}
539
+		for _, v := range envSet {
540
+			*field = append(*field, v)
541
+		}
541 542
 	}
542 543
 
543 544
 	toRemove := buildToRemoveSet(flags, flagEnvRemove)