Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 9e64d2c

Browse files
author
Vincent Demeester
authored
Merge pull request #469 from Azure22/master
Fix GetServiceHash failed due to false hashing
2 parents aadc1f7 + f5c34b0 commit 9e64d2c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

config/hash.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ func GetServiceHash(name string, config *ServiceConfig) string {
8686
for _, sliceKey := range sliceKeys {
8787
io.WriteString(hash, fmt.Sprintf("%s, ", sliceKey))
8888
}
89+
case *yaml.Networks:
90+
io.WriteString(hash, fmt.Sprintf("%s, ", s.HashString()))
91+
case *yaml.Volumes:
92+
io.WriteString(hash, fmt.Sprintf("%s, ", s.HashString()))
8993
default:
90-
io.WriteString(hash, fmt.Sprintf("%v", serviceValue))
94+
io.WriteString(hash, fmt.Sprintf("%v, ", serviceValue))
9195
}
9296
}
9397

yaml/network.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package yaml
33
import (
44
"errors"
55
"fmt"
6+
"sort"
7+
"strings"
68
)
79

810
// Networks represents a list of service networks in compose file.
@@ -20,6 +22,35 @@ type Network struct {
2022
IPv6Address string `yaml:"ipv6_address,omitempty"`
2123
}
2224

25+
// Generate a hash string to detect service network config changes
26+
func (n *Networks) HashString() string {
27+
if n == nil {
28+
return ""
29+
}
30+
result := []string{}
31+
for _, net := range n.Networks {
32+
result = append(result, net.HashString())
33+
}
34+
sort.Strings(result)
35+
return strings.Join(result, ",")
36+
}
37+
38+
// Generate a hash string to detect service network config changes
39+
func (n *Network) HashString() string {
40+
if n == nil {
41+
return ""
42+
}
43+
result := []string{}
44+
result = append(result, n.Name)
45+
result = append(result, n.RealName)
46+
sort.Strings(n.Aliases)
47+
result = append(result, strings.Join(n.Aliases, ","))
48+
result = append(result, n.IPv4Address)
49+
result = append(result, n.IPv6Address)
50+
sort.Strings(result)
51+
return strings.Join(result, ",")
52+
}
53+
2354
// MarshalYAML implements the Marshaller interface.
2455
func (n Networks) MarshalYAML() (interface{}, error) {
2556
m := map[string]*Network{}

yaml/volume.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package yaml
33
import (
44
"errors"
55
"fmt"
6+
"sort"
67
"strings"
78
)
89

@@ -19,6 +20,19 @@ type Volume struct {
1920
AccessMode string `yaml:"-"`
2021
}
2122

23+
// Generate a hash string to detect service volume config changes
24+
func (v *Volumes) HashString() string {
25+
if v == nil {
26+
return ""
27+
}
28+
result := []string{}
29+
for _, vol := range v.Volumes {
30+
result = append(result, vol.String())
31+
}
32+
sort.Strings(result)
33+
return strings.Join(result, ",")
34+
}
35+
2236
// String implements the Stringer interface.
2337
func (v *Volume) String() string {
2438
var paths []string

0 commit comments

Comments
 (0)