From 86d03f3d37aff46af394fcccc6a0a7352e7e1120 Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Mon, 25 Nov 2024 11:36:22 +0100 Subject: [PATCH] fix: get container name and not tag Signed-off-by: Vincent Germain --- main.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index cbcc6cd..94b1e8c 100644 --- a/main.go +++ b/main.go @@ -91,24 +91,27 @@ func CreateClient(Region scw.Region) (*scw.Client, error) { } func GetContainerName(PathRegistry string) string { - const maxLength = 34 - var name string - // rg.fr-par.scw.cloud/testing/images:latest + // Split the path by "/" + pathSegments := strings.Split(PathRegistry, "/") + if len(pathSegments) < 2 { + // If the path doesn't have the expected format, return an empty string + return "" + } - // splitPath := strings.Split(PathRegistry, "/") - // name = splitPath[2] - // name = strings.ReplaceAll(name, ":", "") - // name = strings.ReplaceAll(name, "-", "") + // The last part before the colon contains the container name + lastSegment := pathSegments[len(pathSegments)-1] - // limitation of naming container with 20 characters - splitPath := strings.Split(PathRegistry, ":") - name = splitPath[1] + // Split by ":" to remove the tag (e.g., "latest") + nameParts := strings.Split(lastSegment, ":") + name := nameParts[0] + // Remove unwanted characters name = strings.ReplaceAll(name, "-", "") name = strings.ReplaceAll(name, "_", "") + // Truncate if it exceeds the max length if len(name) > maxLength { name = name[:maxLength] }