diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index e1aa8e6aeec56..9fe96ef40bef0 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -596,15 +596,17 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS ctxPaths := map[string]struct{}{} var dockerIgnoreMatcher *patternmatcher.PatternMatcher - dockerIgnorePatterns, err := opt.Client.DockerIgnorePatterns(ctx) - if err != nil { - return nil, err - } - if len(dockerIgnorePatterns) > 0 { - dockerIgnoreMatcher, err = patternmatcher.New(dockerIgnorePatterns) + if opt.Client.CopyIgnoredCheckEnabled { + dockerIgnorePatterns, err := opt.Client.DockerIgnorePatterns(ctx) if err != nil { return nil, err } + if len(dockerIgnorePatterns) > 0 { + dockerIgnoreMatcher, err = patternmatcher.New(dockerIgnorePatterns) + if err != nil { + return nil, err + } + } } for _, d := range allDispatchStates.states { @@ -651,24 +653,23 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS d.state = d.state.Network(opt.NetworkMode) opt := dispatchOpt{ - allDispatchStates: allDispatchStates, - metaArgs: optMetaArgs, - buildArgValues: opt.BuildArgs, - shlex: shlex, - buildContext: llb.NewState(buildContext), - proxyEnv: proxyEnv, - cacheIDNamespace: opt.CacheIDNamespace, - buildPlatforms: platformOpt.buildPlatforms, - targetPlatform: platformOpt.targetPlatform, - extraHosts: opt.ExtraHosts, - shmSize: opt.ShmSize, - ulimit: opt.Ulimits, - cgroupParent: opt.CgroupParent, - llbCaps: opt.LLBCaps, - sourceMap: opt.SourceMap, - lint: lint, - dockerIgnoreMatcher: dockerIgnoreMatcher, - copyIgnoredCheckEnabled: opt.Client.CopyIgnoredCheckEnabled, + allDispatchStates: allDispatchStates, + metaArgs: optMetaArgs, + buildArgValues: opt.BuildArgs, + shlex: shlex, + buildContext: llb.NewState(buildContext), + proxyEnv: proxyEnv, + cacheIDNamespace: opt.CacheIDNamespace, + buildPlatforms: platformOpt.buildPlatforms, + targetPlatform: platformOpt.targetPlatform, + extraHosts: opt.ExtraHosts, + shmSize: opt.ShmSize, + ulimit: opt.Ulimits, + cgroupParent: opt.CgroupParent, + llbCaps: opt.LLBCaps, + sourceMap: opt.SourceMap, + lint: lint, + dockerIgnoreMatcher: dockerIgnoreMatcher, } if err = dispatchOnBuildTriggers(d, d.image.Config.OnBuild, opt); err != nil { @@ -827,24 +828,23 @@ func toCommand(ic instructions.Command, allDispatchStates *dispatchStates) (comm } type dispatchOpt struct { - allDispatchStates *dispatchStates - metaArgs []instructions.KeyValuePairOptional - buildArgValues map[string]string - shlex *shell.Lex - buildContext llb.State - proxyEnv *llb.ProxyEnv - cacheIDNamespace string - targetPlatform ocispecs.Platform - buildPlatforms []ocispecs.Platform - extraHosts []llb.HostIP - shmSize int64 - ulimit []pb.Ulimit - cgroupParent string - llbCaps *apicaps.CapSet - sourceMap *llb.SourceMap - lint *linter.Linter - dockerIgnoreMatcher *patternmatcher.PatternMatcher - copyIgnoredCheckEnabled bool + allDispatchStates *dispatchStates + metaArgs []instructions.KeyValuePairOptional + buildArgValues map[string]string + shlex *shell.Lex + buildContext llb.State + proxyEnv *llb.ProxyEnv + cacheIDNamespace string + targetPlatform ocispecs.Platform + buildPlatforms []ocispecs.Platform + extraHosts []llb.HostIP + shmSize int64 + ulimit []pb.Ulimit + cgroupParent string + llbCaps *apicaps.CapSet + sourceMap *llb.SourceMap + lint *linter.Linter + dockerIgnoreMatcher *patternmatcher.PatternMatcher } func getEnv(state llb.State) shell.EnvGetter { @@ -1898,7 +1898,7 @@ func addReachableStages(s *dispatchState, stages map[*dispatchState]struct{}) { } func validateCopySourcePath(src string, cfg *copyConfig) error { - if cfg.ignoreMatcher == nil || !cfg.opt.copyIgnoredCheckEnabled { + if cfg.ignoreMatcher == nil { return nil } cmd := "Copy" diff --git a/frontend/dockerfile/dockerfile_lint_test.go b/frontend/dockerfile/dockerfile_lint_test.go index 92660bb88a178..03c3c8e1a76c2 100644 --- a/frontend/dockerfile/dockerfile_lint_test.go +++ b/frontend/dockerfile/dockerfile_lint_test.go @@ -60,6 +60,8 @@ ADD Dockerfile /windy checkLinterWarnings(t, sb, &lintTestParams{ Dockerfile: dockerfile, DockerIgnore: dockerignore, + BuildErrLocation: 3, + StreamBuildErrRegexp: regexp.MustCompile(`failed to solve: failed to compute cache key: failed to calculate checksum of ref [^\s]+ "/Dockerfile": not found`), }) checkLinterWarnings(t, sb, &lintTestParams{ diff --git a/frontend/dockerui/config.go b/frontend/dockerui/config.go index 26f1d8835a53d..e0f9658aaa285 100644 --- a/frontend/dockerui/config.go +++ b/frontend/dockerui/config.go @@ -289,6 +289,9 @@ func (bc *Client) init() error { } } + // CopyIgnoredCheckEnabled is an experimental feature to check if COPY is ignored by .dockerignore, + // and it is disabled by default. It is expected that this feature will be enabled by default in a future + // release, and this build-arg will be removed. if v, ok := opts[keyCopyIgnoredCheckEnabled]; ok { bc.CopyIgnoredCheckEnabled, err = strconv.ParseBool(v) if err != nil {