From b67627ed89ddae4c3b33ad0d90bc859a38bb3bac Mon Sep 17 00:00:00 2001 From: Suleiman Dibirov Date: Wed, 10 Jul 2024 07:40:07 +0300 Subject: [PATCH] a bit refactored hash.go Signed-off-by: Suleiman Dibirov --- pkg/compose/hash.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/compose/hash.go b/pkg/compose/hash.go index d75b67568de..b18232232f0 100644 --- a/pkg/compose/hash.go +++ b/pkg/compose/hash.go @@ -40,18 +40,21 @@ func ServiceHash(project *types.Project, o types.ServiceConfig) (string, error) } for _, serviceConfig := range o.Configs { - if projectConfig, ok := project.Configs[serviceConfig.Source]; ok { - if projectConfig.Content != "" { - bytes = append(bytes, []byte(projectConfig.Content)...) - } else if projectConfig.File != "" { - content, err := os.ReadFile(projectConfig.File) - if err != nil { - return "", err - } - bytes = append(bytes, content...) - } else if projectConfig.Environment != "" { - bytes = append(bytes, []byte(projectConfig.Environment)...) + projectConfig, ok := project.Configs[serviceConfig.Source] + if !ok { + continue + } + + if projectConfig.Content != "" { + bytes = append(bytes, []byte(projectConfig.Content)...) + } else if projectConfig.File != "" { + content, err := os.ReadFile(projectConfig.File) + if err != nil { + return "", err } + bytes = append(bytes, content...) + } else if projectConfig.Environment != "" { + bytes = append(bytes, []byte(projectConfig.Environment)...) } }