From 303a6e4a728a5a19a40e342e90dd8eac1d7f1783 Mon Sep 17 00:00:00 2001 From: Alexey Igrychev Date: Thu, 22 Dec 2022 18:29:53 +0000 Subject: [PATCH] fix(giterminism): false warning about ignoring Dockerfile when using non-root project directory Signed-off-by: Alexey Igrychev --- pkg/build/image/dockerfile.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/build/image/dockerfile.go b/pkg/build/image/dockerfile.go index 65ce12d914..304e4820fd 100644 --- a/pkg/build/image/dockerfile.go +++ b/pkg/build/image/dockerfile.go @@ -285,21 +285,19 @@ func mapLegacyDockerfileToImage(ctx context.Context, dockerfileImageConfig *conf } func createDockerIgnorePathMatcher(ctx context.Context, giterminismMgr giterminism_manager.Interface, contextGitSubDir, dockerfileRelToContextPath string) (path_matcher.PathMatcher, error) { - dockerfileRelToGitPath := filepath.Join(contextGitSubDir, dockerfileRelToContextPath) - var dockerIgnorePatterns []string for _, dockerIgnoreRelToContextPath := range []string{ dockerfileRelToContextPath + ".dockerignore", ".dockerignore", } { - dockerIgnoreRelToGitPath := filepath.Join(contextGitSubDir, dockerIgnoreRelToContextPath) - if exist, err := giterminismMgr.FileReader().IsDockerignoreExistAnywhere(ctx, dockerIgnoreRelToGitPath); err != nil { + relDockerIgnorePath := filepath.Join(contextGitSubDir, dockerIgnoreRelToContextPath) + if exist, err := giterminismMgr.FileReader().IsDockerignoreExistAnywhere(ctx, relDockerIgnorePath); err != nil { return nil, err } else if !exist { continue } - dockerIgnore, err := giterminismMgr.FileReader().ReadDockerignore(ctx, dockerIgnoreRelToGitPath) + dockerIgnore, err := giterminismMgr.FileReader().ReadDockerignore(ctx, relDockerIgnorePath) if err != nil { return nil, err } @@ -318,6 +316,7 @@ func createDockerIgnorePathMatcher(ctx context.Context, giterminismMgr gitermini DockerignorePatterns: dockerIgnorePatterns, }) + dockerfileRelToGitPath := filepath.Join(giterminismMgr.RelativeToGitProjectDir(), contextGitSubDir, dockerfileRelToContextPath) if !dockerIgnorePathMatcher.IsPathMatched(dockerfileRelToGitPath) { logboek.Context(ctx).Warn().LogLn("WARNING: There is no way to ignore the Dockerfile due to docker limitation when building an image for a compressed context that reads from STDIN.") logboek.Context(ctx).Warn().LogF("WARNING: To hide this message, remove the Dockerfile ignore rule or add an exception rule.\n")