Skip to content

Commit

Permalink
fix: truncate image id on publish tag event (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Rata <[email protected]>
  • Loading branch information
cezar-r authored Sep 12, 2024
1 parent 5ee657b commit 6aa5b7c
Showing 1 changed file with 13 additions and 1 deletion.
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
}

0 comments on commit 6aa5b7c

Please sign in to comment.