Skip to content

Commit

Permalink
sort secrets and configs to ensure idempotence
Browse files Browse the repository at this point in the history
`docker stack deploy` keeps restarting services it doesn't need to (no changes)
because the entries' order gets randomized at some previous (de)serialization.
Maybe it would be worth looking into this at a higher level and ensure
all (de)serialization happens in an ordered collection.

This quick fix sorts secrets and configs (in place, mutably) which ensures the
same order for each run.

Based on
moby/moby#30506

Fixes
moby/moby#34746
  • Loading branch information
pnagy committed Sep 7, 2017
1 parent af94015 commit f0f8ef6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/compose/convert/service.go
Expand Up @@ -122,6 +122,10 @@ func Service(
}
}

// sort to ensure idempotence (don't restart services just because the entries are in different order)
sort.SliceStable(secrets, func(i, j int) bool { return secrets[i].SecretName < secrets[j].SecretName })
sort.SliceStable(configs, func(i, j int) bool { return configs[i].ConfigName < configs[j].ConfigName })

serviceSpec := swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: name,
Expand Down

0 comments on commit f0f8ef6

Please sign in to comment.