From 390da30da8ab8db2adc559f50da6341e6589b98c Mon Sep 17 00:00:00 2001 From: zyzzmohit Date: Tue, 10 Mar 2026 11:15:35 +0530 Subject: [PATCH] bug(ecs): fix parseContainerImage to handle images with registry ports Signed-off-by: zyzzmohit --- pkg/app/piped/platformprovider/ecs/task.go | 16 ++++++--- .../piped/platformprovider/ecs/task_test.go | 36 +++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/pkg/app/piped/platformprovider/ecs/task.go b/pkg/app/piped/platformprovider/ecs/task.go index c75b38fe2c..2407a41f74 100644 --- a/pkg/app/piped/platformprovider/ecs/task.go +++ b/pkg/app/piped/platformprovider/ecs/task.go @@ -54,12 +54,18 @@ func FindImageTag(taskDefinition types.TaskDefinition) (string, error) { } func parseContainerImage(image string) (name, tag string) { - parts := strings.Split(image, ":") - if len(parts) == 2 { - tag = parts[1] + paths := strings.Split(image, "/") + lastSegment := paths[len(paths)-1] + + idx := strings.LastIndex(lastSegment, ":") + if idx == -1 { + name = lastSegment + tag = "" + return } - paths := strings.Split(parts[0], "/") - name = paths[len(paths)-1] + + name = lastSegment[:idx] + tag = lastSegment[idx+1:] return } diff --git a/pkg/app/piped/platformprovider/ecs/task_test.go b/pkg/app/piped/platformprovider/ecs/task_test.go index 68ae7bef4b..44759ddbd9 100644 --- a/pkg/app/piped/platformprovider/ecs/task_test.go +++ b/pkg/app/piped/platformprovider/ecs/task_test.go @@ -92,6 +92,42 @@ func TestFindArtifactVersions(t *testing.T) { expected []*model.ArtifactVersion expectedErr bool }{ + { + name: "image with registry port", + input: []byte(` +{ + "family": "nginx-canary-fam-1", + "compatibilities": [ + "FARGATE" + ], + "networkMode": "awsvpc", + "memory": 512, + "cpu": 256, + "containerDefinitions" : [ + { + "image": "localhost:5000/pipecd/helloworld:v1.0.0", + "name": "helloworld", + "portMappings": [ + { + "containerPort": 80, + "hostPort": 9085, + "protocol": "tcp" + } + ] + } + ] +} +`), + expected: []*model.ArtifactVersion{ + { + Kind: model.ArtifactVersion_CONTAINER_IMAGE, + Version: "v1.0.0", + Name: "helloworld", + Url: "localhost:5000/pipecd/helloworld:v1.0.0", + }, + }, + expectedErr: false, + }, { name: "ok", input: []byte(`