Skip to content

Commit d15d79f

Browse files
committed
feat(staged-dockerfile): refine dockerfile instructions digests calculations
Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
1 parent e558e1e commit d15d79f

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

pkg/build/stage/instruction/env.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ func (stg *Env) GetDependencies(ctx context.Context, c stage.Conveyor, cb contai
2727
}
2828

2929
args = append(args, "Instruction", stg.instruction.Data.Name())
30-
// FIXME(staged-dockerfile): sort envs
3130
if len(stg.instruction.Data.Envs) > 0 {
3231
args = append(args, "Envs")
33-
for k, v := range stg.instruction.Data.Envs {
34-
args = append(args, k, v)
32+
for _, k := range util.SortedStringKeys(stg.instruction.Data.Envs) {
33+
args = append(args, k, stg.instruction.Data.Envs[k])
3534
}
3635
}
3736
return util.Sha256Hash(args...), nil

pkg/build/stage/instruction/label.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ func (stg *Label) GetDependencies(ctx context.Context, c stage.Conveyor, cb cont
2727
}
2828

2929
args = append(args, "Instruction", stg.instruction.Data.Name())
30-
31-
// FIXME(staged-dockerfile): sort labels map
3230
if len(stg.instruction.Data.Labels) > 0 {
3331
args = append(args, "Labels")
34-
for k, v := range stg.instruction.Data.Labels {
35-
args = append(args, k, v)
32+
for _, k := range util.SortedStringKeys(stg.instruction.Data.Labels) {
33+
args = append(args, k, stg.instruction.Data.Labels[k])
3634
}
3735
}
38-
3936
return util.Sha256Hash(args...), nil
4037
}

pkg/build/stage/instruction/run.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package instruction
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/werf/werf/pkg/build/stage"
78
"github.com/werf/werf/pkg/config"
@@ -28,6 +29,32 @@ func (stg *Run) GetDependencies(ctx context.Context, c stage.Conveyor, cb contai
2829

2930
args = append(args, "Instruction", stg.instruction.Data.Name())
3031
args = append(args, append([]string{"Command"}, stg.instruction.Data.Command...)...)
32+
args = append(args, "PrependShell", fmt.Sprintf("%v", stg.instruction.Data.PrependShell))
33+
args = append(args, "Network", string(stg.instruction.Data.Network))
34+
args = append(args, "Security", string(stg.instruction.Data.Security))
35+
36+
if len(stg.instruction.Data.Mounts) > 0 {
37+
args = append(args, "Mounts")
38+
for _, mnt := range stg.instruction.Data.Mounts {
39+
args = append(args, "Type", mnt.Type)
40+
args = append(args, "From", mnt.From)
41+
args = append(args, "Source", mnt.Source)
42+
args = append(args, "Target", mnt.Target)
43+
args = append(args, "ReadOnly", fmt.Sprintf("%v", mnt.ReadOnly))
44+
args = append(args, "CacheID", mnt.CacheID)
45+
args = append(args, "CacheSharing", mnt.CacheSharing)
46+
args = append(args, "Required", fmt.Sprintf("%v", mnt.Required))
47+
if mnt.Mode != nil {
48+
args = append(args, "Mode", fmt.Sprintf("%d", *mnt.Mode))
49+
}
50+
if mnt.UID != nil {
51+
args = append(args, "UID", fmt.Sprintf("%d", *mnt.UID))
52+
}
53+
if mnt.GID != nil {
54+
args = append(args, "GID", fmt.Sprintf("%d", *mnt.GID))
55+
}
56+
}
57+
}
3158

3259
// TODO(ilya-lesikov): should bind mount with context as src be counted as dependency?
3360

pkg/util/map.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package util
22

3+
import (
4+
"sort"
5+
)
6+
37
// Dest has higher priority.
48
func MergeMaps[K comparable, V any](src, dest map[K]V) map[K]V {
59
result := make(map[K]V)
@@ -14,3 +18,12 @@ func MergeMaps[K comparable, V any](src, dest map[K]V) map[K]V {
1418

1519
return result
1620
}
21+
22+
func SortedStringKeys(m map[string]string) []string {
23+
var keys []string
24+
for k := range m {
25+
keys = append(keys, k)
26+
}
27+
sort.Strings(keys)
28+
return keys
29+
}

0 commit comments

Comments
 (0)