From 5fea19566010e0559615f94c465a3df3295f742a Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Sat, 23 Nov 2024 12:36:59 +0100 Subject: [PATCH] Copy resolved args and rearrange the code to silence the linter (revive#564) Signed-off-by: Gregor Riepl --- imagebuildah/executor.go | 4 +++- imagebuildah/stage_executor.go | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/imagebuildah/executor.go b/imagebuildah/executor.go index 5012ee50bd5..1b740e898ba 100644 --- a/imagebuildah/executor.go +++ b/imagebuildah/executor.go @@ -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() } diff --git a/imagebuildah/stage_executor.go b/imagebuildah/stage_executor.go index daf72c9097d..76cfb8b12b4 100644 --- a/imagebuildah/stage_executor.go +++ b/imagebuildah/stage_executor.go @@ -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 @@ -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