|
| 1 | +/* |
| 2 | + * Copyright 2024 The CNAI Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package backend |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + |
| 22 | + "github.com/CloudNativeAI/modctl/pkg/storage" |
| 23 | +) |
| 24 | + |
| 25 | +// Backend is the interface to represent the backend. |
| 26 | +type Backend interface { |
| 27 | + // Login logs into a registry. |
| 28 | + Login(ctx context.Context, registry, username, password string) error |
| 29 | + |
| 30 | + // Logout logs out from a registry. |
| 31 | + Logout(ctx context.Context, registry string) error |
| 32 | + |
| 33 | + // Build builds the user materials into the OCI image which follows the Model Spec. |
| 34 | + Build(ctx context.Context, modelfilePath, workDir, target string) error |
| 35 | + |
| 36 | + // Pull pulls an artifact from a registry. |
| 37 | + Pull(ctx context.Context, target string, opts ...Option) error |
| 38 | + |
| 39 | + // Push pushes the image to the registry. |
| 40 | + Push(ctx context.Context, target string, opts ...Option) error |
| 41 | + |
| 42 | + // List lists all the model artifacts. |
| 43 | + List(ctx context.Context) ([]*ModelArtifact, error) |
| 44 | + |
| 45 | + // Remove deletes the model artifact. |
| 46 | + Remove(ctx context.Context, target string) (string, error) |
| 47 | + |
| 48 | + // Prune prunes the unused blobs and clean up the storage. |
| 49 | + Prune(ctx context.Context) ([]string, error) |
| 50 | +} |
| 51 | + |
| 52 | +// backend is the implementation of Backend. |
| 53 | +type backend struct { |
| 54 | + store storage.Storage |
| 55 | +} |
| 56 | + |
| 57 | +// New creates a new backend. |
| 58 | +func New() (Backend, error) { |
| 59 | + store, err := storage.New("") |
| 60 | + if err != nil { |
| 61 | + return nil, err |
| 62 | + } |
| 63 | + |
| 64 | + return &backend{ |
| 65 | + store: store, |
| 66 | + }, nil |
| 67 | +} |
0 commit comments