Skip to content
Permalink
Browse files
fix(build): werf does not reset stages storage cache when import sour…
…ce image not found

Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Feb 16, 2022
1 parent f1747f3 commit 262412ad3c908d900970cf428a1a454fc82e703c
Showing with 29 additions and 2 deletions.
  1. +14 −2 pkg/build/conveyor.go
  2. +2 −0 pkg/build/stage/conveyor.go
  3. +13 −0 pkg/build/stage/dependencies.go
@@ -714,11 +714,23 @@ func (c *Conveyor) getImageStage(imageName, stageName string) stage.Interface {
if stg := c.GetImage(imageName).GetStage(stage.StageName(stageName)); stg != nil {
return stg
} else {
// FIXME: find first existing stage after specified unexisting
return c.GetImage(imageName).GetLastNonEmptyStage()
return c.getLastNonEmptyImageStage(imageName)
}
}

func (c *Conveyor) getLastNonEmptyImageStage(imageName string) stage.Interface {
// FIXME: find first existing stage after specified unexisting
return c.GetImage(imageName).GetLastNonEmptyStage()
}

func (c *Conveyor) FetchImageStage(ctx context.Context, imageName, stageName string) error {
return c.StorageManager.FetchStage(ctx, c.ContainerRuntime, c.getImageStage(imageName, stageName))
}

func (c *Conveyor) FetchLastNonEmptyImageStage(ctx context.Context, imageName string) error {
return c.StorageManager.FetchStage(ctx, c.ContainerRuntime, c.getLastNonEmptyImageStage(imageName))
}

func (c *Conveyor) GetImageNameForLastImageStage(imageName string) string {
return c.GetImage(imageName).GetLastNonEmptyStage().GetImage().Name()
}
@@ -16,6 +16,8 @@ type Conveyor interface {
GetImageStageContentDigest(imageName, stageName string) string
GetImageContentDigest(imageName string) string

FetchImageStage(ctx context.Context, imageName, stageName string) error
FetchLastNonEmptyImageStage(ctx context.Context, imageName string) error
GetImageNameForLastImageStage(imageName string) string
GetImageIDForLastImageStage(imageName string) string

@@ -183,6 +183,10 @@ func (s *DependenciesStage) getImportSourceChecksum(ctx context.Context, c Conve
}

func (s *DependenciesStage) generateImportChecksum(ctx context.Context, c Conveyor, importElm *config.Import) (string, error) {
if err := fetchSourceImageDockerImage(ctx, c, importElm); err != nil {
return "", fmt.Errorf("unable to fetch source image: %w", err)
}

sourceImageDockerImageName := getSourceImageDockerImageName(c, importElm)
importSourceID := getImportSourceID(c, importElm)

@@ -323,6 +327,15 @@ func getImportSourceID(c Conveyor, importElm *config.Import) string {
)
}

func fetchSourceImageDockerImage(ctx context.Context, c Conveyor, importElm *config.Import) error {
sourceImageName := getSourceImageName(importElm)
if importElm.Stage == "" {
return c.FetchLastNonEmptyImageStage(ctx, sourceImageName)
} else {
return c.FetchImageStage(ctx, sourceImageName, importElm.Stage)
}
}

func getSourceImageDockerImageName(c Conveyor, importElm *config.Import) string {
sourceImageName := getSourceImageName(importElm)

0 comments on commit 262412a

Please sign in to comment.