From 1f5796abbb971c1279a38e11456aa98c53c08e81 Mon Sep 17 00:00:00 2001 From: cezar-r <59450965+cezar-r@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:39:01 -0700 Subject: [PATCH] fix: truncate image id on publish tag event (#35) 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..e917936 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), // for docker compatibility 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 +}