-
Notifications
You must be signed in to change notification settings - Fork 198
/
storage.go
64 lines (52 loc) · 2.45 KB
/
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
package utils
import (
"context"
. "github.com/onsi/gomega"
"github.com/werf/werf/pkg/container_backend"
"github.com/werf/werf/pkg/docker_registry"
"github.com/werf/werf/pkg/storage"
)
func NewStagesStorage(stagesStorageAddress, implementationName string, dockerRegistryOptions docker_registry.DockerRegistryOptions) storage.PrimaryStagesStorage {
if stagesStorageAddress == storage.LocalStorageAddress {
return storage.NewDockerServerStagesStorage(&container_backend.DockerServerBackend{})
} else {
dockerRegistry, err := docker_registry.NewDockerRegistry(stagesStorageAddress, implementationName, dockerRegistryOptions)
Expect(err).ShouldNot(HaveOccurred())
return storage.NewRepoStagesStorage(stagesStorageAddress, &container_backend.DockerServerBackend{}, dockerRegistry)
}
}
func StagesCount(ctx context.Context, stagesStorage storage.StagesStorage) int {
repoImages, err := stagesStorage.GetStagesIDs(ctx, ProjectName())
Ω(err).ShouldNot(HaveOccurred())
return len(repoImages)
}
func ManagedImagesCount(ctx context.Context, stagesStorage storage.StagesStorage) int {
managedImages, err := stagesStorage.GetManagedImages(ctx, ProjectName())
Ω(err).ShouldNot(HaveOccurred())
return len(managedImages)
}
func CustomTagsMetadataList(ctx context.Context, stagesStorage storage.PrimaryStagesStorage) []*storage.CustomTagMetadata {
customTagMetadataIDs, err := stagesStorage.GetStageCustomTagMetadataIDs(ctx)
Ω(err).ShouldNot(HaveOccurred())
var result []*storage.CustomTagMetadata
for _, metadataID := range customTagMetadataIDs {
customTagMetadata, err := stagesStorage.GetStageCustomTagMetadata(ctx, metadataID)
Ω(err).ShouldNot(HaveOccurred())
result = append(result, customTagMetadata)
}
return result
}
func ImageMetadata(ctx context.Context, stagesStorage storage.StagesStorage, imageName string) map[string][]string {
imageMetadataByImageName, _, err := stagesStorage.GetAllAndGroupImageMetadataByImageName(ctx, ProjectName(), []string{imageName})
Ω(err).ShouldNot(HaveOccurred())
return imageMetadataByImageName[imageName]
}
func ImportMetadataIDs(ctx context.Context, stagesStorage storage.StagesStorage) []string {
ids, err := stagesStorage.GetImportMetadataIDs(ctx, ProjectName())
Ω(err).ShouldNot(HaveOccurred())
return ids
}
func RmImportMetadata(ctx context.Context, stagesStorage storage.StagesStorage, importSourceID string) {
err := stagesStorage.RmImportMetadata(ctx, ProjectName(), importSourceID)
Ω(err).ShouldNot(HaveOccurred())
}