Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(multiarch): managed images adding bug fix
Bug was introduced after moving managed-images-adding procedure into AfterImages phase hook.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Apr 5, 2023
1 parent 3b2a9b0 commit 285e5a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pkg/build/build_phase.go
Expand Up @@ -81,10 +81,8 @@ type BuildPhase struct {
BasePhase
BuildPhaseOptions

StagesIterator *StagesIterator
ShouldAddManagedImageRecord bool

ImagesReport *ImagesReport
StagesIterator *StagesIterator
ImagesReport *ImagesReport

buildContextArchive container_backend.BuildContextArchiver
}
Expand Down Expand Up @@ -473,7 +471,7 @@ func (phase *BuildPhase) AfterImageStages(ctx context.Context, img *image.Image)
}

func (phase *BuildPhase) addManagedImage(ctx context.Context, name string) error {
if phase.ShouldAddManagedImageRecord {
if phase.Conveyor.ShouldAddManagedImagesRecords() {
stagesStorage := phase.Conveyor.StorageManager.GetStagesStorage()
exist, err := stagesStorage.IsManagedImageExist(ctx, phase.Conveyor.ProjectName(), name, storage.WithCache())
if err != nil {
Expand Down Expand Up @@ -674,7 +672,7 @@ func (phase *BuildPhase) onImageStage(ctx context.Context, img *image.Image, stg
}

// Add managed image record only if there was at least one newly built stage
phase.ShouldAddManagedImageRecord = true
phase.Conveyor.SetShouldAddManagedImagesRecords()

return nil
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/build/conveyor.go
Expand Up @@ -45,6 +45,8 @@ type Conveyor struct {
giterminismManager giterminism_manager.Interface
remoteGitRepos map[string]*git_repo.Remote

shouldAddManagedImagesRecords bool

tmpDir string

ContainerBackend container_backend.ContainerBackend
Expand Down Expand Up @@ -337,6 +339,18 @@ func (c *Conveyor) GetRemoteGitRepo(key string) *git_repo.Remote {
return c.remoteGitRepos[key]
}

func (c *Conveyor) SetShouldAddManagedImagesRecords() {
c.GetServiceRWMutex("ShouldAddManagedImagesRecords").RLock()
defer c.GetServiceRWMutex("ShouldAddManagedImagesRecords").RUnlock()
c.shouldAddManagedImagesRecords = true
}

func (c *Conveyor) ShouldAddManagedImagesRecords() bool {
c.GetServiceRWMutex("ShouldAddManagedImagesRecords").RLock()
defer c.GetServiceRWMutex("ShouldAddManagedImagesRecords").RUnlock()
return c.shouldAddManagedImagesRecords
}

type ShouldBeBuiltOptions struct {
CustomTagFuncList []imagePkg.CustomTagFunc
}
Expand Down

0 comments on commit 285e5a6

Please sign in to comment.