diff --git a/pkg/build/stage/instruction/env.go b/pkg/build/stage/instruction/env.go index 2612df410f..dbaac01c2c 100644 --- a/pkg/build/stage/instruction/env.go +++ b/pkg/build/stage/instruction/env.go @@ -27,11 +27,10 @@ func (stg *Env) GetDependencies(ctx context.Context, c stage.Conveyor, cb contai } args = append(args, "Instruction", stg.instruction.Data.Name()) - // FIXME(staged-dockerfile): sort envs if len(stg.instruction.Data.Envs) > 0 { args = append(args, "Envs") - for k, v := range stg.instruction.Data.Envs { - args = append(args, k, v) + for _, k := range util.SortedStringKeys(stg.instruction.Data.Envs) { + args = append(args, k, stg.instruction.Data.Envs[k]) } } return util.Sha256Hash(args...), nil diff --git a/pkg/build/stage/instruction/label.go b/pkg/build/stage/instruction/label.go index 9c890af2b8..2469d83ec6 100644 --- a/pkg/build/stage/instruction/label.go +++ b/pkg/build/stage/instruction/label.go @@ -27,14 +27,11 @@ func (stg *Label) GetDependencies(ctx context.Context, c stage.Conveyor, cb cont } args = append(args, "Instruction", stg.instruction.Data.Name()) - - // FIXME(staged-dockerfile): sort labels map if len(stg.instruction.Data.Labels) > 0 { args = append(args, "Labels") - for k, v := range stg.instruction.Data.Labels { - args = append(args, k, v) + for _, k := range util.SortedStringKeys(stg.instruction.Data.Labels) { + args = append(args, k, stg.instruction.Data.Labels[k]) } } - return util.Sha256Hash(args...), nil } diff --git a/pkg/build/stage/instruction/run.go b/pkg/build/stage/instruction/run.go index aee0c554a4..de7860790d 100644 --- a/pkg/build/stage/instruction/run.go +++ b/pkg/build/stage/instruction/run.go @@ -2,6 +2,7 @@ package instruction import ( "context" + "fmt" "github.com/werf/werf/pkg/build/stage" "github.com/werf/werf/pkg/config" @@ -28,6 +29,32 @@ func (stg *Run) GetDependencies(ctx context.Context, c stage.Conveyor, cb contai args = append(args, "Instruction", stg.instruction.Data.Name()) args = append(args, append([]string{"Command"}, stg.instruction.Data.Command...)...) + args = append(args, "PrependShell", fmt.Sprintf("%v", stg.instruction.Data.PrependShell)) + args = append(args, "Network", string(stg.instruction.Data.Network)) + args = append(args, "Security", string(stg.instruction.Data.Security)) + + if len(stg.instruction.Data.Mounts) > 0 { + args = append(args, "Mounts") + for _, mnt := range stg.instruction.Data.Mounts { + args = append(args, "Type", mnt.Type) + args = append(args, "From", mnt.From) + args = append(args, "Source", mnt.Source) + args = append(args, "Target", mnt.Target) + args = append(args, "ReadOnly", fmt.Sprintf("%v", mnt.ReadOnly)) + args = append(args, "CacheID", mnt.CacheID) + args = append(args, "CacheSharing", mnt.CacheSharing) + args = append(args, "Required", fmt.Sprintf("%v", mnt.Required)) + if mnt.Mode != nil { + args = append(args, "Mode", fmt.Sprintf("%d", *mnt.Mode)) + } + if mnt.UID != nil { + args = append(args, "UID", fmt.Sprintf("%d", *mnt.UID)) + } + if mnt.GID != nil { + args = append(args, "GID", fmt.Sprintf("%d", *mnt.GID)) + } + } + } // TODO(ilya-lesikov): should bind mount with context as src be counted as dependency? diff --git a/pkg/util/map.go b/pkg/util/map.go index cd3bcff17a..3d362b71d8 100644 --- a/pkg/util/map.go +++ b/pkg/util/map.go @@ -1,5 +1,9 @@ package util +import ( + "sort" +) + // Dest has higher priority. func MergeMaps[K comparable, V any](src, dest map[K]V) map[K]V { result := make(map[K]V) @@ -14,3 +18,12 @@ func MergeMaps[K comparable, V any](src, dest map[K]V) map[K]V { return result } + +func SortedStringKeys(m map[string]string) []string { + var keys []string + for k := range m { + keys = append(keys, k) + } + sort.Strings(keys) + return keys +}