From 69e1bb0783700586fc902f4367a283fcdf391b6f Mon Sep 17 00:00:00 2001 From: Timofey Kirillov Date: Mon, 14 Mar 2022 21:47:12 +0300 Subject: [PATCH] fix(build): do not store images into final repo when --skip-build is set Signed-off-by: Timofey Kirillov --- pkg/build/build_phase.go | 3 ++- pkg/storage/manager/storage_manager.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/build/build_phase.go b/pkg/build/build_phase.go index b1c2bddefd..6fe4e96cc2 100644 --- a/pkg/build/build_phase.go +++ b/pkg/build/build_phase.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 } } diff --git a/pkg/storage/manager/storage_manager.go b/pkg/storage/manager/storage_manager.go index d2a98b1ee8..e2c727fa16 100644 --- a/pkg/storage/manager/storage_manager.go +++ b/pkg/storage/manager/storage_manager.go @@ -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) }