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

Commit 41972bf

Browse files
committed
Allow tag with implicit registry
Signed-off-by: Emily Casey <[email protected]>
1 parent ff2ef18 commit 41972bf

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

commands/tag.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/docker/model-cli/desktop"
78
"github.com/google/go-containerregistry/pkg/name"
@@ -33,20 +34,21 @@ func newTagCmd() *cobra.Command {
3334
}
3435

3536
func tagModel(cmd *cobra.Command, desktopClient *desktop.Client, source, target string) error {
36-
// Parse the target to extract repo and tag
37+
// Ensure tag is valid
3738
tag, err := name.NewTag(target)
3839
if err != nil {
3940
return fmt.Errorf("invalid tag: %w", err)
4041
}
41-
targetRepo := tag.Repository.String()
42-
targetTag := tag.TagStr()
43-
44-
// Make the POST request
45-
resp, err := desktopClient.Tag(source, targetRepo, targetTag)
46-
if err != nil {
42+
// Make tag request with model runner client
43+
if err := desktopClient.Tag(source, parseRepo(tag), tag.TagStr()); err != nil {
4744
return fmt.Errorf("failed to tag model: %w", err)
4845
}
49-
50-
cmd.Println(resp)
46+
cmd.Printf("Model %q tagged successfully with %q\n", source, target)
5147
return nil
5248
}
49+
50+
// parseRepo returns the repo portion of the original target string. It does not include implicit
51+
// index.docker.io when the registry is omitted.
52+
func parseRepo(tag name.Tag) string {
53+
return strings.TrimSuffix(tag.String(), ":"+tag.TagStr())
54+
}

desktop/desktop.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ func (c *Client) handleQueryError(err error, path string) error {
605605
return fmt.Errorf("error querying %s: %w", path, err)
606606
}
607607

608-
func (c *Client) Tag(source, targetRepo, targetTag string) (string, error) {
608+
func (c *Client) Tag(source, targetRepo, targetTag string) error {
609609
source = normalizeHuggingFaceModelName(source)
610610
// Check if the source is a model ID, and expand it if necessary
611611
if !strings.Contains(strings.Trim(source, "/"), "/") {
@@ -625,19 +625,17 @@ func (c *Client) Tag(source, targetRepo, targetTag string) (string, error) {
625625

626626
resp, err := c.doRequest(http.MethodPost, tagPath, nil)
627627
if err != nil {
628-
return "", c.handleQueryError(err, tagPath)
628+
return c.handleQueryError(err, tagPath)
629629
}
630630
defer resp.Body.Close()
631-
632-
if resp.StatusCode != http.StatusCreated {
633-
body, _ := io.ReadAll(resp.Body)
634-
return "", fmt.Errorf("tagging failed with status %s: %s", resp.Status, string(body))
635-
}
636-
637631
body, err := io.ReadAll(resp.Body)
638632
if err != nil {
639-
return "", fmt.Errorf("failed to read response body: %w", err)
633+
return fmt.Errorf("failed to read response body: %w", err)
640634
}
641635

642-
return string(body), nil
636+
if resp.StatusCode != http.StatusCreated {
637+
return fmt.Errorf("tagging failed with status %s: %s", resp.Status, string(body))
638+
}
639+
640+
return nil
643641
}

desktop/desktop_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ func TestTagHuggingFaceModel(t *testing.T) {
193193
Body: io.NopCloser(bytes.NewBufferString("Tag created successfully")),
194194
}, nil)
195195

196-
_, err := client.Tag(sourceModel, targetRepo, targetTag)
197-
assert.NoError(t, err)
196+
assert.NoError(t, client.Tag(sourceModel, targetRepo, targetTag))
198197
}
199198

200199
func TestInspectOpenAIHuggingFaceModel(t *testing.T) {

0 commit comments

Comments
 (0)