Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: truncate image id on publish tag event #35

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion internal/service/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io"
"strings"

ncTypes "github.com/containerd/nerdctl/pkg/api/types"

Expand All @@ -18,6 +19,7 @@ import (
)

const tagEventAction = "tag"
const shortLen = 12

// setting publishTagEventFunc as a variable to allow mocking this function for unit testing.
var publishTagEventFunc = (*service).publishTagEvent
Expand Down Expand Up @@ -92,7 +94,7 @@ func tagTopic() string {

func getTagEvent(digest, imgName string) *events.Event {
return &events.Event{
ID: digest,
ID: truncateID(digest), // for docker compatibility
Status: tagEventAction,
Type: "image",
Action: tagEventAction,
Expand All @@ -104,3 +106,13 @@ func getTagEvent(digest, imgName string) *events.Event {
},
}
}

func truncateID(id string) string {
if i := strings.IndexRune(id, ':'); i >= 0 {
id = id[i+1:]
}
if len(id) > shortLen {
id = id[:shortLen]
}
return id
}
Loading