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

Commit 72d2dd1

Browse files
authored
Merge pull request #124 from docker/tag-with-implicit-registry
Allow tag with implicit registry
2 parents c436f46 + 41972bf commit 72d2dd1

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/commands/completion"
78
"github.com/docker/model-cli/desktop"
@@ -35,20 +36,21 @@ func newTagCmd() *cobra.Command {
3536
}
3637

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

desktop/desktop.go

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

636-
func (c *Client) Tag(source, targetRepo, targetTag string) (string, error) {
636+
func (c *Client) Tag(source, targetRepo, targetTag string) error {
637637
source = normalizeHuggingFaceModelName(source)
638638
// Check if the source is a model ID, and expand it if necessary
639639
if !strings.Contains(strings.Trim(source, "/"), "/") {
@@ -653,19 +653,17 @@ func (c *Client) Tag(source, targetRepo, targetTag string) (string, error) {
653653

654654
resp, err := c.doRequest(http.MethodPost, tagPath, nil)
655655
if err != nil {
656-
return "", c.handleQueryError(err, tagPath)
656+
return c.handleQueryError(err, tagPath)
657657
}
658658
defer resp.Body.Close()
659-
660-
if resp.StatusCode != http.StatusCreated {
661-
body, _ := io.ReadAll(resp.Body)
662-
return "", fmt.Errorf("tagging failed with status %s: %s", resp.Status, string(body))
663-
}
664-
665659
body, err := io.ReadAll(resp.Body)
666660
if err != nil {
667-
return "", fmt.Errorf("failed to read response body: %w", err)
661+
return fmt.Errorf("failed to read response body: %w", err)
668662
}
669663

670-
return string(body), nil
664+
if resp.StatusCode != http.StatusCreated {
665+
return fmt.Errorf("tagging failed with status %s: %s", resp.Status, string(body))
666+
}
667+
668+
return nil
671669
}

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)