Skip to content

Commit 5d32378

Browse files
committed
Merge branch 'main' into javisperez/sc-238/ui-blog-feed
2 parents 72e8f73 + 0cb1a56 commit 5d32378

32 files changed

+728
-751
lines changed

cmd/root.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"kitops/pkg/cmd/export"
1515
"kitops/pkg/cmd/list"
1616
"kitops/pkg/cmd/login"
17+
"kitops/pkg/cmd/logout"
1718
"kitops/pkg/cmd/pull"
1819
"kitops/pkg/cmd/push"
1920
"kitops/pkg/cmd/version"
@@ -28,28 +29,28 @@ var (
2829
longDesc = `KitOps is a tool to manage AI and ML models`
2930
)
3031

31-
type rootFlags struct {
32+
type rootOptions struct {
3233
configHome string
3334
verbose bool
3435
}
3536

3637
func RunCommand() *cobra.Command {
37-
flags := &rootFlags{}
38+
opts := &rootOptions{}
3839

3940
cmd := &cobra.Command{
4041
Use: "kit",
4142
Short: shortDesc,
4243
Long: longDesc,
4344
PersistentPreRun: func(cmd *cobra.Command, args []string) {
44-
configHome := flags.configHome
45+
configHome := opts.configHome
4546
if configHome == "" {
4647
currentUser, err := user.Current()
4748
if err != nil {
4849
output.Fatalf("Failed to resolve default storage path '$HOME/%s: could not get current user", constants.DefaultConfigSubdir)
4950
}
5051
configHome = filepath.Join(currentUser.HomeDir, constants.DefaultConfigSubdir)
5152
}
52-
if flags.verbose {
53+
if opts.verbose {
5354
output.SetDebug(true)
5455
}
5556
ctx := context.WithValue(cmd.Context(), constants.ConfigKey{}, configHome)
@@ -58,14 +59,15 @@ func RunCommand() *cobra.Command {
5859
}
5960

6061
addSubcommands(cmd)
61-
cmd.PersistentFlags().StringVar(&flags.configHome, "config", "", fmt.Sprintf("Config file (default $HOME/%s)", constants.DefaultConfigSubdir))
62-
cmd.PersistentFlags().BoolVarP(&flags.verbose, "verbose", "v", false, "Include additional information in output (default false)")
62+
cmd.PersistentFlags().StringVar(&opts.configHome, "config", "", fmt.Sprintf("Config file (default $HOME/%s)", constants.DefaultConfigSubdir))
63+
cmd.PersistentFlags().BoolVarP(&opts.verbose, "verbose", "v", false, "Include additional information in output (default false)")
6364
return cmd
6465
}
6566

6667
func addSubcommands(rootCmd *cobra.Command) {
6768
rootCmd.AddCommand(build.BuildCommand())
6869
rootCmd.AddCommand(login.LoginCommand())
70+
rootCmd.AddCommand(logout.LogoutCommand())
6971
rootCmd.AddCommand(pull.PullCommand())
7072
rootCmd.AddCommand(push.PushCommand())
7173
rootCmd.AddCommand(list.ListCommand())

examples/onnx/Kitfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package:
33
name: Densenet-ONNX
44
description: >-
55
Example using onnx.
6-
authors: [Gorkem]
6+
authors: [Gorkem]
7+
license: Apache-2.0
8+
model:
9+
name: onnx Model
10+
path: ./model
11+
framework: sklearn:1.3.0
12+
version: 1.2
13+
description: Example model using onnx
714
license: Apache-2.0
8-
models:
9-
- name: onnx Model
10-
path: ./model
11-
framework: sklearn:1.3.0
12-
version: 1.2
13-
description: Example model using onnx
14-
license: Apache-2.0

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/opencontainers/image-spec v1.1.0
88
github.com/spf13/cobra v1.8.0
99
github.com/stretchr/testify v1.8.4
10+
golang.org/x/term v0.17.0
1011
oras.land/oras-go/v2 v2.4.0
1112
sigs.k8s.io/yaml v1.4.0
1213
)
@@ -17,5 +18,6 @@ require (
1718
github.com/pmezard/go-difflib v1.0.0 // indirect
1819
github.com/spf13/pflag v1.0.5 // indirect
1920
golang.org/x/sync v0.6.0 // indirect
21+
golang.org/x/sys v0.17.0 // indirect
2022
gopkg.in/yaml.v3 v3.0.1 // indirect
2123
)

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
2020
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
2121
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
2222
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
23+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
24+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
25+
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
26+
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
2327
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2428
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2529
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

pkg/cmd/build/build.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package build
22

33
import (
44
"context"
5+
"fmt"
56
"kitops/pkg/artifact"
67
"kitops/pkg/lib/constants"
78
"kitops/pkg/lib/filesystem"
9+
"kitops/pkg/lib/repo"
810
"kitops/pkg/lib/storage"
911
"kitops/pkg/output"
1012
"os"
11-
"path"
1213
)
1314

1415
func RunBuild(ctx context.Context, options *buildOptions) error {
@@ -63,21 +64,23 @@ func RunBuild(ctx context.Context, options *buildOptions) error {
6364
}
6465
model.Layers = append(model.Layers, *layer)
6566

66-
modelStorePath := options.storageHome
67-
repo := ""
6867
tag := ""
6968
if options.modelRef != nil {
70-
repo = path.Join(options.modelRef.Registry, options.modelRef.Repository)
7169
tag = options.modelRef.Reference
7270
}
73-
store := storage.NewLocalStore(modelStorePath, repo)
74-
manifestDesc, err := store.SaveModel(ctx, model, tag)
71+
storageHome := constants.StoragePath(options.configHome)
72+
localStore, err := repo.NewLocalStore(storageHome, options.modelRef)
73+
if err != nil {
74+
return fmt.Errorf("failed to open local storage: %w", err)
75+
}
76+
77+
manifestDesc, err := storage.SaveModel(ctx, localStore, model, tag)
7578
if err != nil {
7679
return err
7780
}
7881

7982
for _, tag := range options.extraRefs {
80-
if err := store.TagModel(ctx, *manifestDesc, tag); err != nil {
83+
if err := localStore.Tag(ctx, *manifestDesc, tag); err != nil {
8184
return err
8285
}
8386
}

pkg/cmd/build/cmd.go

+13-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"kitops/pkg/lib/constants"
1212
"kitops/pkg/lib/filesystem"
13-
"kitops/pkg/lib/storage"
13+
"kitops/pkg/lib/repo"
1414
"kitops/pkg/output"
1515

1616
"github.com/spf13/cobra"
@@ -22,40 +22,35 @@ var (
2222
longDesc = `Build a model TODO`
2323
)
2424

25-
type buildFlags struct {
26-
modelFile string
27-
fullTagRef string
28-
}
29-
3025
type buildOptions struct {
3126
modelFile string
3227
contextDir string
3328
configHome string
3429
storageHome string
30+
fullTagRef string
3531
modelRef *registry.Reference
3632
extraRefs []string
3733
}
3834

3935
func BuildCommand() *cobra.Command {
40-
flags := &buildFlags{}
36+
opts := &buildOptions{}
4137

4238
cmd := &cobra.Command{
4339
Use: "build",
4440
Short: shortDesc,
4541
Long: longDesc,
46-
Run: runCommand(flags),
42+
Run: runCommand(opts),
4743
}
4844

49-
cmd.Flags().StringVarP(&flags.modelFile, "file", "f", "", "Path to the model file")
50-
cmd.Flags().StringVarP(&flags.fullTagRef, "tag", "t", "", "Tag for the model. Example: -t registry/repository:tag1,tag2")
45+
cmd.Flags().StringVarP(&opts.modelFile, "file", "f", "", "Path to the model file")
46+
cmd.Flags().StringVarP(&opts.fullTagRef, "tag", "t", "", "Tag for the model. Example: -t registry/repository:tag1,tag2")
5147
cmd.Args = cobra.ExactArgs(1)
5248
return cmd
5349
}
5450

55-
func runCommand(flags *buildFlags) func(cmd *cobra.Command, args []string) {
51+
func runCommand(opts *buildOptions) func(cmd *cobra.Command, args []string) {
5652
return func(cmd *cobra.Command, args []string) {
57-
opts := &buildOptions{}
58-
err := opts.complete(cmd.Context(), flags, args)
53+
err := opts.complete(cmd.Context(), args)
5954
if err != nil {
6055
output.Fatalf("Failed to process configuration: %s", err)
6156
return
@@ -68,10 +63,9 @@ func runCommand(flags *buildFlags) func(cmd *cobra.Command, args []string) {
6863
}
6964
}
7065

71-
func (opts *buildOptions) complete(ctx context.Context, flags *buildFlags, args []string) error {
66+
func (opts *buildOptions) complete(ctx context.Context, args []string) error {
7267
opts.contextDir = args[0]
7368

74-
opts.modelFile = flags.modelFile
7569
if opts.modelFile == "" {
7670
opts.modelFile = filesystem.FindKitfileInPath(opts.contextDir)
7771
}
@@ -81,12 +75,12 @@ func (opts *buildOptions) complete(ctx context.Context, flags *buildFlags, args
8175
return fmt.Errorf("default config path not set on command context")
8276
}
8377
opts.configHome = configHome
84-
opts.storageHome = storage.StorageHome(opts.configHome)
78+
opts.storageHome = constants.StoragePath(opts.configHome)
8579

86-
if flags.fullTagRef != "" {
87-
modelRef, extraRefs, err := storage.ParseReference(flags.fullTagRef)
80+
if opts.fullTagRef != "" {
81+
modelRef, extraRefs, err := repo.ParseReference(opts.fullTagRef)
8882
if err != nil {
89-
return fmt.Errorf("failed to parse reference %s: %w", flags.fullTagRef, err)
83+
return fmt.Errorf("failed to parse reference %s: %w", opts.fullTagRef, err)
9084
}
9185
opts.modelRef = modelRef
9286
opts.extraRefs = extraRefs

pkg/cmd/build/cmd_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ func TestNewCmdBuild(t *testing.T) {
2020

2121
func TestBuildOptions_Complete(t *testing.T) {
2222
options := &buildOptions{}
23-
flags := &buildFlags{}
2423
ctx := context.WithValue(context.Background(), constants.ConfigKey{}, "/home/user/.kitops")
2524
args := []string{"arg1"}
2625

27-
err := options.complete(ctx, flags, args)
26+
err := options.complete(ctx, args)
2827

2928
assert.NoError(t, err)
3029
assert.Equal(t, args[0], options.contextDir)

0 commit comments

Comments
 (0)