Skip to content

Commit

Permalink
Copy resolved args and rearrange the code to silence the linter (revi…
Browse files Browse the repository at this point in the history
…ve#564)

Signed-off-by: Gregor Riepl <[email protected]>
  • Loading branch information
onitake committed Nov 23, 2024
1 parent d2f617d commit 5fea195
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,11 @@ func (b *Executor) waitForStage(ctx context.Context, name string, stages imagebu
}
}

// freezeArgs stores a copy of the argument map for further use in dependent stages
func (b *Executor) freezeArgs(name string, args map[string]string) {
copiedArgs := args.Clone()
b.stagesLock.Lock()
b.argResult[name] = args
b.argResult[name] = copiedArgs
b.stagesLock.Unlock()
}

Expand Down
12 changes: 7 additions & 5 deletions imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,13 +1151,14 @@ func (s *StageExecutor) Execute(ctx context.Context, base string) (imgID string,
// either in local storage, or one that we have to pull from a
// registry, subject to the passed-in pull policy.
// This helper will also return the final resolved argument list from
// the parent state.
if isStage, parentArgs, err := s.executor.waitForStage(ctx, base, s.stages[:s.index]); isStage && err != nil {
// the parent stage, if available.
isStage, parentArgs, err := s.executor.waitForStage(ctx, base, s.stages[:s.index])
if isStage && err != nil {
return "", nil, false, err
} else {
// Update the start args with those from the parent stage
maps.Copy(ib.Args, parentArgs)
}
// Update the start args with those from the parent stage
maps.Copy(ib.Args, parentArgs)

pullPolicy := s.executor.pullPolicy
s.executor.stagesLock.Lock()
var preserveBaseImageAnnotationsAtStageStart bool
Expand Down Expand Up @@ -1748,6 +1749,7 @@ func (s *StageExecutor) Execute(ctx context.Context, base string) (imgID string,
}
}

// store the final argument map for further use
s.executor.freezeArgs(s.name, ib.Args)

return imgID, ref, onlyBaseImage, nil
Expand Down

0 comments on commit 5fea195

Please sign in to comment.