Skip to content

Commit 157573e

Browse files
committed
Merge branch 'main' of github.com:CloudNativeAI/modctl into feature/modelfile
Signed-off-by: Gaius <[email protected]>
2 parents 1cba6e8 + b639231 commit 157573e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3078
-868
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
actions: read # To read the workflow path.
6767
id-token: write # To sign the provenance.
6868
contents: write # To add assets to a release.
69-
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
69+
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
7070
with:
7171
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
7272
upload-assets: true # upload to a new release

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ run:
44
skip-dirs:
55
- test/mocks
66

7-
87
linters-settings:
98
gocyclo:
109
min-complexity: 100

.mockery.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ packages:
1919
Modelfile:
2020
config:
2121
dir: test/mocks/modelfile
22+
github.com/CloudNativeAI/modctl/pkg/backend/build:
23+
interfaces:
24+
Builder:
25+
config:
26+
dir: test/mocks/backend/build
27+
OutputStrategy:
28+
config:
29+
dir: test/mocks/backend/build

Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ LOCALBIN ?= $(shell pwd)/bin
9898
$(LOCALBIN):
9999
mkdir -p $(LOCALBIN)
100100

101+
MOCKERY_VERSION=v2.52.1
102+
101103
.PHONY: gen
102104
gen: gen-mockery## Generate all we need!
103105

@@ -107,15 +109,15 @@ gen-mockery: check-mockery ## Generate mockery code
107109
@mockery
108110

109111
check-mockery:
110-
@which mockery > /dev/null || { echo "mockery not found. Trying to install via Homebrew..."; $(MAKE) install-mockery; }
111-
@mockery --version | grep -q "2.46.3" || { echo "mockery version is not v2.46.3. Trying to install the correct version..."; $(MAKE) install-mockery; }
112+
@which mockery > /dev/null || { echo "mockery not found. Trying to install via go install..."; $(MAKE) install-mockery; }
113+
@mockery --version | grep -q $(MOCKERY_VERSION) || { echo "mockery version is not $(MOCKERY_VERSION). Trying to install the correct version..."; $(MAKE) install-mockery; }
112114

113115
install-mockery:
114-
@if command -v brew > /dev/null; then \
115-
echo "Installing mockery via Homebrew"; \
116-
brew install mockery; \
116+
@if command -v go > /dev/null; then \
117+
echo "Installing mockery via go install"; \
118+
go install github.com/vektra/mockery/v2@$(MOCKERY_VERSION); \
117119
else \
118-
echo "Error: Homebrew is not installed. Please install Homebrew first and ensure it's in your PATH."; \
120+
echo "Error: Golang is not installed. Please install golang first and ensure it's in your PATH."; \
119121
exit 1; \
120122
fi
121123

cmd/build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ var buildCmd = &cobra.Command{
4949
// init initializes build command.
5050
func init() {
5151
flags := buildCmd.Flags()
52+
flags.IntVarP(&buildConfig.Concurrency, "concurrency", "c", buildConfig.Concurrency, "specify the number of concurrent build operations")
5253
flags.StringVarP(&buildConfig.Target, "target", "t", "", "target model artifact name")
5354
flags.StringVarP(&buildConfig.Modelfile, "modelfile", "f", "Modelfile", "model file path")
55+
flags.BoolVarP(&buildConfig.OutputRemote, "output-remote", "", false, "turning on this flag will output model artifact to remote registry directly")
56+
flags.BoolVarP(&buildConfig.PlainHTTP, "plain-http", "", false, "turning on this flag will use plain HTTP instead of HTTPS")
57+
flags.BoolVarP(&buildConfig.Insecure, "insecure", "", false, "turning on this flag will disable TLS verification")
5458

5559
if err := viper.BindPFlags(flags); err != nil {
5660
panic(fmt.Errorf("bind cache list flags to viper: %w", err))
@@ -64,7 +68,7 @@ func runBuild(ctx context.Context, workDir string) error {
6468
return err
6569
}
6670

67-
if err := b.Build(ctx, buildConfig.Modelfile, workDir, buildConfig.Target); err != nil {
71+
if err := b.Build(ctx, buildConfig.Modelfile, workDir, buildConfig.Target, buildConfig); err != nil {
6872
return err
6973
}
7074

cmd/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func runList(ctx context.Context) error {
6363
return err
6464
}
6565

66-
tw := tabwriter.NewWriter(os.Stderr, 0, 0, 4, ' ', 0)
66+
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
6767
defer tw.Flush()
6868
fmt.Fprintln(tw, "REPOSITORY\tTAG\tDIGEST\tCREATED\tSIZE")
6969

cmd/login.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ func runLogin(ctx context.Context, registry string) error {
8989

9090
fmt.Println("\nLogging In...")
9191

92-
opts := []backend.Option{
93-
backend.WithPlainHTTP(loginConfig.PlainHTTP),
94-
}
95-
96-
if err := b.Login(ctx, registry, loginConfig.Username, loginConfig.Password, opts...); err != nil {
92+
if err := b.Login(ctx, registry, loginConfig.Username, loginConfig.Password, loginConfig); err != nil {
9793
return err
9894
}
9995

cmd/pull.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func init() {
5454
flags.BoolVar(&pullConfig.Insecure, "insecure", false, "use insecure connection for the pull operation and skip TLS verification")
5555
flags.StringVar(&pullConfig.Proxy, "proxy", "", "use proxy for the pull operation")
5656
flags.StringVar(&pullConfig.ExtractDir, "extract-dir", "", "specify the extract dir for extracting the model artifact")
57+
flags.BoolVar(&pullConfig.ExtractFromRemote, "extract-from-remote", false, "turning on this flag will pull and extract the data from remote registry and no longer store model artifact locally, so user must specify extract-dir as the output directory")
5758

5859
if err := viper.BindPFlags(flags); err != nil {
5960
panic(fmt.Errorf("bind cache pull flags to viper: %w", err))
@@ -71,21 +72,7 @@ func runPull(ctx context.Context, target string) error {
7172
return fmt.Errorf("target is required")
7273
}
7374

74-
opts := []backend.Option{
75-
backend.WithInsecure(pullConfig.Insecure),
76-
backend.WithPlainHTTP(pullConfig.PlainHTTP),
77-
backend.WithConcurrency(pullConfig.Concurrency),
78-
}
79-
80-
if pullConfig.Proxy != "" {
81-
opts = append(opts, backend.WithProxy(pullConfig.Proxy))
82-
}
83-
84-
if pullConfig.ExtractDir != "" {
85-
opts = append(opts, backend.WithOutput(pullConfig.ExtractDir))
86-
}
87-
88-
if err := b.Pull(ctx, target, opts...); err != nil {
75+
if err := b.Pull(ctx, target, pullConfig); err != nil {
8976
return err
9077
}
9178

cmd/push.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ func runPush(ctx context.Context, target string) error {
6464
return err
6565
}
6666

67-
opts := []backend.Option{
68-
backend.WithPlainHTTP(pushConfig.PlainHTTP),
69-
backend.WithConcurrency(pushConfig.Concurrency),
70-
}
71-
72-
if err := b.Push(ctx, target, opts...); err != nil {
67+
if err := b.Push(ctx, target, pushConfig); err != nil {
7368
return err
7469
}
7570

cmd/root.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package cmd
1818

1919
import (
2020
"os"
21+
"os/signal"
22+
"syscall"
2123

2224
"github.com/CloudNativeAI/modctl/cmd/modelfile"
2325
"github.com/CloudNativeAI/modctl/pkg/config"
24-
"github.com/sirupsen/logrus"
26+
2527
"github.com/spf13/cobra"
2628
"github.com/spf13/viper"
2729
)
@@ -37,15 +39,21 @@ var rootCmd = &cobra.Command{
3739
SilenceUsage: true,
3840
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
3941
RunE: func(cmd *cobra.Command, args []string) error {
40-
logrus.Debug("modctl is running")
41-
4242
return nil
4343
},
4444
}
4545

4646
// Execute adds all child commands to the root command and sets flags appropriately.
4747
// This is called by main.main(). It only needs to happen once to the rootCmd.
4848
func Execute() {
49+
sig := make(chan os.Signal, 1)
50+
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
51+
52+
go func() {
53+
<-sig
54+
os.Exit(1)
55+
}()
56+
4957
if err := rootCmd.Execute(); err != nil {
5058
os.Exit(1)
5159
}
@@ -79,5 +87,6 @@ func init() {
7987
rootCmd.AddCommand(pruneCmd)
8088
rootCmd.AddCommand(inspectCmd)
8189
rootCmd.AddCommand(extractCmd)
90+
rootCmd.AddCommand(tagCmd)
8291
rootCmd.AddCommand(modelfile.RootCmd)
8392
}

0 commit comments

Comments
 (0)