@@ -24,12 +24,12 @@ 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 ,
@@ -72,7 +72,7 @@ func newPackagedCmd() *cobra.Command {
7272
7373 c .Flags ().StringVar (& opts .ggufPath , "gguf" , "" , "absolute path to gguf file (required)" )
7474 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." )
75+ c .Flags ().BoolVar (& opts .push , "push" , false , "push to registry (if not set, the model is loaded into the Model Runner content store." )
7676 c .Flags ().Uint64Var (& opts .contextSize , "context-size" , 0 , "context size in tokens" )
7777 return c
7878}
@@ -90,17 +90,10 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
9090 err error
9191 )
9292 if opts .push {
93- cmd .PrintErrln ("Pushing model...%q\n " , tag )
94- var err error
9593 target , err = registry .NewClient (
9694 registry .WithUserAgent ("docker-model-cli/" + desktop .Version ),
9795 ).NewTarget (tag )
98- if err != nil {
99- return err
100- }
101- cmd .PrintErrln ("Pushing to registry..." )
10296 } else {
103- cmd .PrintErrln ("Loading Model..." )
10497 target , err = newModelRunnerTarget (desktopClient , tag )
10598 }
10699 if err != nil {
@@ -129,6 +122,11 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
129122 }
130123 }
131124
125+ if opts .push {
126+ cmd .PrintErrln ("Pushing model to registry..." )
127+ } else {
128+ cmd .PrintErrln ("Loading model to Model Runner..." )
129+ }
132130 pr , pw := io .Pipe ()
133131 done := make (chan error , 1 )
134132 go func () {
@@ -159,9 +157,9 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
159157 }
160158 if err := <- done ; err != nil {
161159 if opts .push {
162- return fmt .Errorf ("push : %w" , err )
160+ return fmt .Errorf ("failed to save packaged model : %w" , err )
163161 }
164- return fmt .Errorf ("failed to load model: %w" , err )
162+ return fmt .Errorf ("failed to load packaged model: %w" , err )
165163 }
166164
167165 if opts .push {
@@ -172,6 +170,7 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
172170 return nil
173171}
174172
173+ // modelRunnerTarget loads model to Docker Model Runner via models/load endpoint
175174type modelRunnerTarget struct {
176175 client * desktop.Client
177176 tag name.Tag
@@ -208,19 +207,19 @@ func (t *modelRunnerTarget) Write(ctx context.Context, mdl types.ModelArtifact,
208207 writeErr := <- errCh
209208
210209 if loadErr != nil {
211- return loadErr
210+ return fmt . Errorf ( "loading model archive: %w" , loadErr )
212211 }
213212 if writeErr != nil {
214- return writeErr
213+ return fmt . Errorf ( "writing model archive: %w" , writeErr )
215214 }
216215 id , err := mdl .ID ()
217216 if err != nil {
218217 return fmt .Errorf ("get model ID: %w" , err )
219218 }
220219 if t .tag .String () != "" {
221220 if err := desktopClient .Tag (id , parseRepo (t .tag ), t .tag .TagStr ()); err != nil {
222- return fmt .Errorf ("failed to tag model: %w" , err )
221+ return fmt .Errorf ("tag model: %w" , err )
223222 }
224223 }
225- return writeErr
224+ return nil
226225}
0 commit comments