Skip to content

Commit 986bc44

Browse files
committed
service hash MUST exclude replicas
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 24f8327 commit 986bc44

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

pkg/compose/hash.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func ServiceHash(o types.ServiceConfig) (string, error) {
2929
o.Build = nil
3030
o.PullPolicy = ""
3131
o.Scale = 1
32+
if o.Deploy != nil {
33+
var one uint64 = 1
34+
o.Deploy.Replicas = &one
35+
}
3236
bytes, err := json.Marshal(o)
3337
if err != nil {
3438
return "", err

pkg/compose/hash_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package compose
18+
19+
import (
20+
"testing"
21+
22+
"github.com/compose-spec/compose-go/types"
23+
"gotest.tools/v3/assert"
24+
)
25+
26+
func TestServiceHash(t *testing.T) {
27+
hash1, err := ServiceHash(serviceConfig(1))
28+
assert.NilError(t, err)
29+
hash2, err := ServiceHash(serviceConfig(2))
30+
assert.NilError(t, err)
31+
assert.Equal(t, hash1, hash2)
32+
}
33+
34+
func serviceConfig(replicas uint64) types.ServiceConfig {
35+
return types.ServiceConfig{
36+
Scale: int(replicas),
37+
Deploy: &types.DeployConfig{
38+
Replicas: &replicas,
39+
},
40+
Name: "foo",
41+
Image: "bar",
42+
}
43+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
22
ping:
33
image: alpine
4-
command: "sh -c 'ping -c 1 localhost && exit 1'"
4+
command: "sh -c 'ping -c 2 localhost && exit 1'"
55
restart: "on-failure:2"

0 commit comments

Comments
 (0)