/
stages_storage.go
89 lines (70 loc) · 4.2 KB
/
stages_storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package storage
import (
"context"
"errors"
"fmt"
"strings"
"github.com/werf/werf/pkg/container_backend"
"github.com/werf/werf/pkg/image"
)
const (
LocalStorageAddress = ":local"
DefaultKubernetesStorageAddress = "kubernetes://werf-synchronization"
DefaultHttpSynchronizationServer = "https://synchronization.werf.io"
NamelessImageRecordTag = "__nameless__"
)
var ErrBrokenImage = errors.New("broken image")
func IsErrBrokenImage(err error) bool {
return err != nil && strings.HasSuffix(err.Error(), ErrBrokenImage.Error())
}
type StagesStorage interface {
GetStagesIDs(ctx context.Context, projectName string, opts ...Option) ([]image.StageID, error)
GetStagesIDsByDigest(ctx context.Context, projectName, digest string, opts ...Option) ([]image.StageID, error)
GetStageDescription(ctx context.Context, projectName, digest string, uniqueID int64) (*image.StageDescription, error)
ExportStage(ctx context.Context, stageDescription *image.StageDescription, destinationReference string) error
DeleteStage(ctx context.Context, stageDescription *image.StageDescription, options DeleteImageOptions) error
AddStageCustomTag(ctx context.Context, stageDescription *image.StageDescription, tag string) error
CheckStageCustomTag(ctx context.Context, stageDescription *image.StageDescription, tag string) error
DeleteStageCustomTag(ctx context.Context, tag string) error
RejectStage(ctx context.Context, projectName, digest string, uniqueID int64) error
ConstructStageImageName(projectName, digest string, uniqueID int64) string
// FetchImage will create a local image in the container-runtime
FetchImage(ctx context.Context, img container_backend.LegacyImageInterface) error
// StoreImage will store a local image into the container-runtime, local built image should exist prior running store
StoreImage(ctx context.Context, img container_backend.LegacyImageInterface) error
ShouldFetchImage(ctx context.Context, img container_backend.LegacyImageInterface) (bool, error)
CreateRepo(ctx context.Context) error
DeleteRepo(ctx context.Context) error
// AddManagedImage adds managed image.
AddManagedImage(ctx context.Context, projectName, imageNameOrManagedImageName string) error
// RmManagedImage removes managed image by imageName or managedImageName.
// Typically, the managedImageName is the same as the imageName, but may be different
// if the name contains unsupported special characters, or
// if the name exceeds the docker tag limit.
RmManagedImage(ctx context.Context, projectName, imageNameOrManagedImageName string) error
IsManagedImageExist(ctx context.Context, projectName, imageNameOrManagedImageName string, opts ...Option) (bool, error)
// GetManagedImages returns the list of managedImageName.
GetManagedImages(ctx context.Context, projectName string, opts ...Option) ([]string, error)
PutImageMetadata(ctx context.Context, projectName, imageNameOrManagedImageName, commit, stageID string) error
RmImageMetadata(ctx context.Context, projectName, imageNameOrManagedImageNameOrImageMetadataID, commit, stageID string) error
IsImageMetadataExist(ctx context.Context, projectName, imageNameOrManagedImageName, commit, stageID string, opts ...Option) (bool, error)
GetAllAndGroupImageMetadataByImageName(ctx context.Context, projectName string, imageNameOrManagedImageList []string, opts ...Option) (map[string]map[string][]string, map[string]map[string][]string, error)
GetImportMetadata(ctx context.Context, projectName, id string) (*ImportMetadata, error)
PutImportMetadata(ctx context.Context, projectName string, metadata *ImportMetadata) error
RmImportMetadata(ctx context.Context, projectName, id string) error
GetImportMetadataIDs(ctx context.Context, projectName string, opts ...Option) ([]string, error)
GetClientIDRecords(ctx context.Context, projectName string, opts ...Option) ([]*ClientIDRecord, error)
PostClientIDRecord(ctx context.Context, projectName string, rec *ClientIDRecord) error
String() string
Address() string
}
type ClientIDRecord struct {
ClientID string
TimestampMillisec int64
}
func (rec *ClientIDRecord) String() string {
return fmt.Sprintf("clientID:%s tsMillisec:%d", rec.ClientID, rec.TimestampMillisec)
}
type ImageMetadata struct {
ContentDigest string
}