From 89e64a51918e8c1ecb15110b70959d776c2c2eba Mon Sep 17 00:00:00 2001 From: Cezar Rata Date: Wed, 11 Sep 2024 20:23:04 +0000 Subject: [PATCH] fix: truncate image id on publish tag event Signed-off-by: Cezar Rata --- internal/service/builder/build.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/service/builder/build.go b/internal/service/builder/build.go index d3dfe3d..950f93b 100644 --- a/internal/service/builder/build.go +++ b/internal/service/builder/build.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "io" + "strings" ncTypes "github.com/containerd/nerdctl/pkg/api/types" @@ -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 @@ -92,7 +94,7 @@ func tagTopic() string { func getTagEvent(digest, imgName string) *events.Event { return &events.Event{ - ID: digest, + ID: truncateID(digest), Status: tagEventAction, Type: "image", Action: tagEventAction, @@ -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 +}