Skip to content

Commit

Permalink
fix(build): werf does not reset stages storage cache when import sour…
Browse files Browse the repository at this point in the history
…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 262412a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/build/conveyor.go
Expand Up @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/stage/conveyor.go
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions pkg/build/stage/dependencies.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 262412a

Please sign in to comment.