diff --git a/airbyte-commons-with-dependencies/src/main/java/io/airbyte/commons/helper/DockerImageNameHelper.java b/airbyte-commons-with-dependencies/src/main/java/io/airbyte/commons/helper/DockerImageNameHelper.java index 5ad076b6318..e59dc7677a7 100644 --- a/airbyte-commons-with-dependencies/src/main/java/io/airbyte/commons/helper/DockerImageNameHelper.java +++ b/airbyte-commons-with-dependencies/src/main/java/io/airbyte/commons/helper/DockerImageNameHelper.java @@ -26,7 +26,8 @@ public class DockerImageNameHelper { /** * Docker image names are by convention separated by slashes. The last portion is the image's name. * This is followed by a colon and a version number. e.g. airbyte/scheduler:v1 or - * gcr.io/my-project/my-project:v2. + * gcr.io/my-project/image-name:v2. Registry name may also include port number, + * e.g. registry.internal:1234/my-project/image-name:v2 * * @param fullImagePath the image name with repository and version ex * gcr.io/my-project/image-name:v2 @@ -43,7 +44,7 @@ public static String extractShortImageName(final String fullImagePath) { * Extracts the image name without the version tag. * * @param fullImagePath the docker image name - * @return anything before ":" + * @return anything before last ":" */ public static String extractImageNameWithoutVersion(final String fullImagePath) { return extractPartFromFullPath(fullImagePath, NAME_PARTS_INDEX); @@ -53,7 +54,7 @@ public static String extractImageNameWithoutVersion(final String fullImagePath) * Extracts the image version label as a string. * * @param fullImagePath the docker image name - * @return anything after ":" + * @return anything after last ":" */ public static String extractImageVersionString(final String fullImagePath) { return extractPartFromFullPath(fullImagePath, VERSION_PART_INDEX); @@ -78,8 +79,15 @@ public static Optional extractImageVersion(final String fullImagePath) } private static String extractPartFromFullPath(final String fullImagePath, final int partIndex) { - final String[] parts = fullImagePath.split(VERSION_DELIMITER); - return parts.length > partIndex ? parts[partIndex] : null; + final int delimeterIndex = fullImagePath.lastIndexOf(VERSION_DELIMITER); + if (partIndex == NAME_PARTS_INDEX) { + return delimeterIndex >= 0 ? fullImagePath.substring(0, delimeterIndex) : fullImagePath; + } else if (partIndex == VERSION_PART_INDEX) { + return delimeterIndex >= 0 ? fullImagePath.substring(delimeterIndex + 1) : null; + } else { + LOGGER.warn("Invalid part index: {}", partIndex); + return null; + } } } diff --git a/airbyte-commons-worker/src/main/java/io/airbyte/workers/helper/ConnectorApmSupportHelper.java b/airbyte-commons-worker/src/main/java/io/airbyte/workers/helper/ConnectorApmSupportHelper.java index 7d89c7c279c..9fd7ed8e0e6 100644 --- a/airbyte-commons-worker/src/main/java/io/airbyte/workers/helper/ConnectorApmSupportHelper.java +++ b/airbyte-commons-worker/src/main/java/io/airbyte/workers/helper/ConnectorApmSupportHelper.java @@ -68,30 +68,38 @@ Map getEnv() { /** * Extracts the image name from the provided image string, if the image string uses the following * format: {@code :}. + * Image name may include registry and port number, which is also delimited by ":" * * @param image The image. * @return The name extracted from the image, or the originally provided string if blank. */ public static String getImageName(final String image) { if (StringUtils.isNotEmpty(image)) { - return image.split(IMAGE_DELIMITER)[0]; + final int delimeterIndex = image.lastIndexOf(IMAGE_DELIMITER); + if (delimeterIndex >= 0) { + return image.substring(0, delimeterIndex); + } } - + // If image is null, empty, or does not contain a delimiter, return the original string. return image; } /** * Extracts the image version from the provided image string, if the image string uses the following * format: {@code :}. + * Image name may include registry and port number, which is also delimited by ":" * * @param image The image. * @return The version extracted from the image, or the originally provided string if blank. */ public static String getImageVersion(final String image) { if (StringUtils.isNotEmpty(image)) { - return image.split(IMAGE_DELIMITER)[1]; + final int delimeterIndex = image.lastIndexOf(IMAGE_DELIMITER); + if (delimeterIndex >= 0 && image.length() > delimeterIndex + 1) { + return image.substring(delimeterIndex + 1); + } } - + // If image is null, empty, or does not contain a delimiter, return the original string. return image; } diff --git a/airbyte-commons-worker/src/main/java/io/airbyte/workers/process/ProcessFactory.java b/airbyte-commons-worker/src/main/java/io/airbyte/workers/process/ProcessFactory.java index 48628912699..c31c552c8e9 100644 --- a/airbyte-commons-worker/src/main/java/io/airbyte/workers/process/ProcessFactory.java +++ b/airbyte-commons-worker/src/main/java/io/airbyte/workers/process/ProcessFactory.java @@ -111,7 +111,8 @@ static String getShortImageName(final String fullImagePath) { /** * Docker image names are by convention separated by slashes. The last portion is the image's name. * This is followed by a colon and a version number. e.g. airbyte/scheduler:v1 or - * gcr.io/my-project/image-name:v2. + * gcr.io/my-project/image-name:v2. Registry name may also include port number, + * e.g. registry.internal:1234/my-project/image-name:v2 * * Get the image version by returning the substring following a colon. */ @@ -119,7 +120,8 @@ static String getImageVersion(final String fullImagePath) { if (fullImagePath == null || fullImagePath.length() < 1) { return null; } - int colonIndex = fullImagePath.indexOf(":"); + // Use the last colon to find the image tag + int colonIndex = fullImagePath.lastIndexOf(":"); if (colonIndex != -1 && fullImagePath.length() > colonIndex + 1) { return fullImagePath.substring(colonIndex + 1); }