-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbackend.go
More file actions
89 lines (68 loc) · 2.91 KB
/
Copy pathbackend.go
File metadata and controls
89 lines (68 loc) · 2.91 KB
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
/*
* Copyright 2024 The CNAI Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package backend
import (
"context"
"github.com/CloudNativeAI/modctl/pkg/config"
"github.com/CloudNativeAI/modctl/pkg/storage"
)
// Backend is the interface to represent the backend.
type Backend interface {
// Login logs into a registry.
Login(ctx context.Context, registry, username, password string, cfg *config.Login) error
// Logout logs out from a registry.
Logout(ctx context.Context, registry string) error
// Attach attaches user materials into the model artifact which follows the Model Spec.
Attach(ctx context.Context, filepath string, cfg *config.Attach) error
// Build builds the user materials into the model artifact which follows the Model Spec.
Build(ctx context.Context, modelfilePath, workDir, target string, cfg *config.Build) error
// Pull pulls an artifact from a registry.
Pull(ctx context.Context, target string, cfg *config.Pull) error
// PullByDragonfly pulls an artifact from a registry by Dragonfly.
PullByDragonfly(ctx context.Context, target string, cfg *config.Pull) error
// Fetch fetches partial files to the output.
Fetch(ctx context.Context, target string, cfg *config.Fetch) error
// Push pushes the image to the registry.
Push(ctx context.Context, target string, cfg *config.Push) error
// List lists all the model artifacts.
List(ctx context.Context) ([]*ModelArtifact, error)
// Remove deletes the model artifact.
Remove(ctx context.Context, target string) (string, error)
// Prune prunes the unused blobs and clean up the storage.
Prune(ctx context.Context, dryRun, removeUntagged bool) error
// Inspect inspects the model artifact.
Inspect(ctx context.Context, target string, cfg *config.Inspect) (*InspectedModelArtifact, error)
// Extract extracts the model artifact.
Extract(ctx context.Context, target string, cfg *config.Extract) error
// Tag creates a new tag that refers to the source model artifact.
Tag(ctx context.Context, source, target string) error
// Nydusify converts the model artifact to nydus format.
Nydusify(ctx context.Context, target string) (string, error)
}
// backend is the implementation of Backend.
type backend struct {
store storage.Storage
}
// New creates a new backend.
func New(storageDir string) (Backend, error) {
store, err := storage.New("", storageDir)
if err != nil {
return nil, err
}
return &backend{
store: store,
}, nil
}