Skip to content
Permalink
Browse files
fix(build): do not store images into final repo when --skip-build is set
Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Mar 18, 2022
1 parent 3b79173 commit 69e1bb0783700586fc902f4367a283fcdf391b6f
Showing with 12 additions and 3 deletions.
  1. +2 −1 pkg/build/build_phase.go
  2. +10 −2 pkg/storage/manager/storage_manager.go
@@ -25,6 +25,7 @@ import (
imagePkg "github.com/werf/werf/pkg/image"
"github.com/werf/werf/pkg/stapel"
"github.com/werf/werf/pkg/storage"
"github.com/werf/werf/pkg/storage/manager"
"github.com/werf/werf/pkg/util"
"github.com/werf/werf/pkg/werf"
)
@@ -248,7 +249,7 @@ func (phase *BuildPhase) AfterImageStages(ctx context.Context, img *Image) error
}

if phase.Conveyor.StorageManager.GetFinalStagesStorage() != nil {
if err := phase.Conveyor.StorageManager.CopyStageIntoFinalStorage(ctx, img.GetLastNonEmptyStage(), phase.Conveyor.ContainerRuntime); err != nil {
if err := phase.Conveyor.StorageManager.CopyStageIntoFinalStorage(ctx, img.GetLastNonEmptyStage(), phase.Conveyor.ContainerRuntime, manager.CopyStageIntoFinalStorageOptions{ShouldBeBuiltMode: phase.ShouldBeBuiltMode}); err != nil {
return err
}
}
@@ -72,7 +72,7 @@ type StorageManagerInterface interface {
SelectSuitableStage(ctx context.Context, c stage.Conveyor, stg stage.Interface, stages []*image.StageDescription) (*image.StageDescription, error)
CopySuitableByDigestStage(ctx context.Context, stageDesc *image.StageDescription, sourceStagesStorage, destinationStagesStorage storage.StagesStorage, containerRuntime container_runtime.ContainerRuntime) (*image.StageDescription, error)
CopyStageIntoCacheStorages(ctx context.Context, stg stage.Interface, containerRuntime container_runtime.ContainerRuntime) error
CopyStageIntoFinalStorage(ctx context.Context, stg stage.Interface, containerRuntime container_runtime.ContainerRuntime) error
CopyStageIntoFinalStorage(ctx context.Context, stg stage.Interface, containerRuntime container_runtime.ContainerRuntime, opts CopyStageIntoFinalStorageOptions) error

ForEachDeleteStage(ctx context.Context, options ForEachDeleteStageOptions, stagesDescriptions []*image.StageDescription, f func(ctx context.Context, stageDesc *image.StageDescription, err error) error) error
ForEachDeleteFinalStage(ctx context.Context, options ForEachDeleteStageOptions, stagesDescriptions []*image.StageDescription, f func(ctx context.Context, stageDesc *image.StageDescription, err error) error) error
@@ -610,7 +610,11 @@ func (m *StorageManager) getOrCreateFinalStagesListCache(ctx context.Context) (*
return m.FinalStagesListCache, nil
}

func (m *StorageManager) CopyStageIntoFinalStorage(ctx context.Context, stg stage.Interface, containerRuntime container_runtime.ContainerRuntime) error {
type CopyStageIntoFinalStorageOptions struct {
ShouldBeBuiltMode bool
}

func (m *StorageManager) CopyStageIntoFinalStorage(ctx context.Context, stg stage.Interface, containerRuntime container_runtime.ContainerRuntime, opts CopyStageIntoFinalStorageOptions) error {
existingStagesListCache, err := m.getOrCreateFinalStagesListCache(ctx)
if err != nil {
return fmt.Errorf("error getting existing stages list of final repo %s: %s", m.FinalStagesStorage.String(), err)
@@ -632,6 +636,10 @@ func (m *StorageManager) CopyStageIntoFinalStorage(ctx context.Context, stg stag
}
}

if opts.ShouldBeBuiltMode {
return fmt.Errorf("%s with digest %s is not exist in the final repo", stg.LogDetailedName(), stg.GetDigest())
}

if err := m.FetchStage(ctx, containerRuntime, stg); err != nil {
return fmt.Errorf("unable to fetch stage %s: %s", stg.LogDetailedName(), err)
}

0 comments on commit 69e1bb0

Please sign in to comment.