Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 4abe9e7

Browse files
committed
cleanup
Signed-off-by: Emily Casey <[email protected]>
1 parent 9400399 commit 4abe9e7

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

commands/package.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ func newPackagedCmd() *cobra.Command {
2424
var opts packageOptions
2525

2626
c := &cobra.Command{
27-
Use: "package --gguf <path> [--license <path>...] [--context-size <tokens>] [--push] TARGET",
27+
Use: "package --gguf <path> [--license <path>...] [--context-size <tokens>] [--push] [<tag>]",
2828
Short: "Package a GGUF file into a Docker model OCI artifact, with optional licenses. The package is sent to the model-runner, unless --push is specified",
2929
Args: func(cmd *cobra.Command, args []string) error {
30-
if len(args) != 1 {
30+
if len(args) < 1 && opts.push {
3131
return fmt.Errorf(
32-
"'docker model package' requires 1 argument.\n\n"+
32+
"1 positional argument with registry tag is required when used with `--push`.\n\n"+
3333
"Usage: %s\n\n"+
3434
"See 'docker model package --help' for more information",
3535
cmd.Use,
3636
)
37+
} else {
38+
opts.tag = args[0]
3739
}
3840
if opts.ggufPath == "" {
3941
return fmt.Errorf(
@@ -61,7 +63,7 @@ func newPackagedCmd() *cobra.Command {
6163
return nil
6264
},
6365
RunE: func(cmd *cobra.Command, args []string) error {
64-
if err := packageModel(cmd, args[0], opts); err != nil {
66+
if err := packageModel(cmd, opts); err != nil {
6567
cmd.PrintErrln("Failed to package model")
6668
return fmt.Errorf("package model: %w", err)
6769
}
@@ -72,7 +74,7 @@ func newPackagedCmd() *cobra.Command {
7274

7375
c.Flags().StringVar(&opts.ggufPath, "gguf", "", "absolute path to gguf file (required)")
7476
c.Flags().StringArrayVarP(&opts.licensePaths, "license", "l", nil, "absolute path to a license file")
75-
c.Flags().BoolVar(&opts.push, "push", false, "push to registry. If not set, the package is loaded into the Model Runner content store.")
77+
c.Flags().BoolVar(&opts.push, "push", false, "push to registry (if not set, the model is loaded into the Model Runner content store.")
7678
c.Flags().Uint64Var(&opts.contextSize, "context-size", 0, "context size in tokens")
7779
return c
7880
}
@@ -82,26 +84,20 @@ type packageOptions struct {
8284
licensePaths []string
8385
push bool
8486
contextSize uint64
87+
tag string
8588
}
8689

87-
func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
90+
func packageModel(cmd *cobra.Command, opts packageOptions) error {
8891
var (
8992
target builder.Target
9093
err error
9194
)
9295
if opts.push {
93-
cmd.PrintErrln("Pushing model...%q\n", tag)
94-
var err error
9596
target, err = registry.NewClient(
9697
registry.WithUserAgent("docker-model-cli/" + desktop.Version),
97-
).NewTarget(tag)
98-
if err != nil {
99-
return err
100-
}
101-
cmd.PrintErrln("Pushing to registry...")
98+
).NewTarget(opts.tag)
10299
} else {
103-
cmd.PrintErrln("Loading Model...")
104-
target, err = newModelRunnerTarget(desktopClient, tag)
100+
target, err = newModelRunnerTarget(desktopClient, opts.tag)
105101
}
106102
if err != nil {
107103
return err
@@ -129,6 +125,11 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
129125
}
130126
}
131127

128+
if opts.push {
129+
cmd.PrintErrln("Pushing model to registry...")
130+
} else {
131+
cmd.PrintErrln("Loading model to Model Runner...")
132+
}
132133
pr, pw := io.Pipe()
133134
done := make(chan error, 1)
134135
go func() {
@@ -159,9 +160,9 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
159160
}
160161
if err := <-done; err != nil {
161162
if opts.push {
162-
return fmt.Errorf("push: %w", err)
163+
return fmt.Errorf("failed to save packaged model: %w", err)
163164
}
164-
return fmt.Errorf("failed to load model: %w", err)
165+
return fmt.Errorf("failed to load packaged model: %w", err)
165166
}
166167

167168
if opts.push {
@@ -172,6 +173,7 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
172173
return nil
173174
}
174175

176+
// modelRunnerTarget loads model to Docker Model Runner via models/load endpoint
175177
type modelRunnerTarget struct {
176178
client *desktop.Client
177179
tag name.Tag
@@ -208,19 +210,19 @@ func (t *modelRunnerTarget) Write(ctx context.Context, mdl types.ModelArtifact,
208210
writeErr := <-errCh
209211

210212
if loadErr != nil {
211-
return loadErr
213+
return fmt.Errorf("loading model archive: %w", loadErr)
212214
}
213215
if writeErr != nil {
214-
return writeErr
216+
return fmt.Errorf("writing model archive: %w", writeErr)
215217
}
216218
id, err := mdl.ID()
217219
if err != nil {
218220
return fmt.Errorf("get model ID: %w", err)
219221
}
220222
if t.tag.String() != "" {
221223
if err := desktopClient.Tag(id, parseRepo(t.tag), t.tag.TagStr()); err != nil {
222-
return fmt.Errorf("failed to tag model: %w", err)
224+
return fmt.Errorf("tag model: %w", err)
223225
}
224226
}
225-
return writeErr
227+
return nil
226228
}

0 commit comments

Comments
 (0)