Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 69e1bb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/build/build_phase.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/storage/manager/storage_manager.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 69e1bb0

Please sign in to comment.