Skip to content

Commit

Permalink
no CopyIgnoreFile rule when copying from parent stage
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
  • Loading branch information
daghack committed Jul 10, 2024
1 parent f5ad057 commit c5f2f48
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ func dispatch(d *dispatchState, cmd command, opt dispatchOpt) error {
params: c.SourcesAndDest,
excludePatterns: c.ExcludePatterns,
source: l,
fromStage: c.From,
isAddCommand: false,
cmdToPrint: c,
chown: c.Chown,
Expand Down Expand Up @@ -1564,6 +1565,7 @@ type copyConfig struct {
cmdToPrint fmt.Stringer
chown string
chmod string
fromStage string
link bool
keepGitDir bool
checksum digest.Digest
Expand Down Expand Up @@ -1883,6 +1885,10 @@ func addReachableStages(s *dispatchState, stages map[*dispatchState]struct{}) {
}

func validateCopySourcePath(matcher *patternmatcher.PatternMatcher, src string, cfg *copyConfig, lint *linter.Linter) error {
if cfg.fromStage != "" {
return nil
}

cmd := "Copy"
if cfg.isAddCommand {
cmd = "Add"
Expand Down
6 changes: 6 additions & 0 deletions frontend/dockerui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ func (bc *Client) MainContext(ctx context.Context, opts ...llb.LocalOption) (*ll
}

excludes, err := bc.dockerIgnorePatterns(ctx, bctx)
if err != nil {
return nil, errors.Wrapf(err, "failed to read dockerignore patterns")
}

opts = append([]llb.LocalOption{
llb.SessionID(bc.bopts.SessionID),
Expand Down Expand Up @@ -460,6 +463,9 @@ func (bc *Client) DockerIgnorePatterns(ctx context.Context) ([]string, error) {
if err != nil {
return nil, err
}
if !bctx.localBuild {
return nil, nil
}

return bc.dockerIgnorePatterns(ctx, bctx)
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/dockerui/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type buildContext struct {
dockerfileLocalName string
filename string
forceLocalDockerfile bool
localBuild bool
}

func (bc *Client) marshalOpts() []llb.ConstraintsOpt {
Expand Down Expand Up @@ -113,6 +114,7 @@ func (bc *Client) initContext(ctx context.Context) (*buildContext, error) {
}
bctx.dockerfile = bctx.context
} else if (&gwcaps).Supports(gwpb.CapFrontendInputs) == nil {
bctx.localBuild = true
inputs, err := bc.client.Inputs(ctx)
if err != nil {
return nil, errors.Wrapf(err, "failed to get frontend inputs")
Expand Down

0 comments on commit c5f2f48

Please sign in to comment.