From 4df03f35a8a74560e1eba2ed603823649f93f011 Mon Sep 17 00:00:00 2001 From: Amit reinich Date: Fri, 10 Jan 2025 18:06:23 +0200 Subject: [PATCH] fix: error already existing instance due to case sensitive Path (#1847) * fix: Fixed error already existing instance due to case sensitive Path.resolve() * added test for verify builder config is looked up by builder name lower cased. * fix: Removed unnecessary eq on verify method Removed unnecessary eq on verify method due to SonarQube issue * added changelog * added changelog * added changelog --- doc/changelog.md | 2 +- .../maven/docker/service/BuildXService.java | 2 +- .../BuildXServiceCreateBuilderTest.java | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 311ae42df..1726c19f6 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -4,7 +4,7 @@ - Docker-compose healthcheck configuration support ([1825](https://github.com/fabric8io/docker-maven-plugin/pull/1825)) - Docker container wait timeout default value made configurable using startContainerWaitTimeout configuration option ([1825](https://github.com/fabric8io/docker-maven-plugin/pull/1825)) - Respect `network` configuration in POM and with property `docker.build.network` or system property `docker.network.mode` in docker buildx [1850](https://github.com/fabric8io/docker-maven-plugin/pull/1850)) - + - Fix case sensitivity issue in builder name lookup by converting builderName to lowercase, ensuring compatibility across file systems ([1847](https://github.com/fabric8io/docker-maven-plugin/pull/1847)) * **0.45.1 (2024-09-29)**: - Make copy docker-buildx binary to temporary config directory work on windows too ([1819](https://github.com/fabric8io/docker-maven-plugin/pull/1819)) - Pull FROM images in relative path Dockerfiles ([1823](https://github.com/fabric8io/docker-maven-plugin/issues/1823)) diff --git a/src/main/java/io/fabric8/maven/docker/service/BuildXService.java b/src/main/java/io/fabric8/maven/docker/service/BuildXService.java index f1b077582..545690caa 100644 --- a/src/main/java/io/fabric8/maven/docker/service/BuildXService.java +++ b/src/main/java/io/fabric8/maven/docker/service/BuildXService.java @@ -280,7 +280,7 @@ protected String createBuilder(Path configPath, List buildX, ImageConfig BuildXConfiguration buildXConfiguration = imageConfig.getBuildConfiguration().getBuildX(); String builderName = Optional.ofNullable(buildXConfiguration.getBuilderName()).orElse("maven"); String nodeName = buildXConfiguration.getNodeName(); - Path builderPath = configPath.resolve(Paths.get("buildx", "instances", builderName)); + Path builderPath = configPath.resolve(Paths.get("buildx", "instances", builderName.toLowerCase())); if(Files.notExists(builderPath)) { List cmds = new ArrayList<>(buildX); append(cmds, "create", "--driver", "docker-container", "--name", builderName); diff --git a/src/test/java/io/fabric8/maven/docker/service/BuildXServiceCreateBuilderTest.java b/src/test/java/io/fabric8/maven/docker/service/BuildXServiceCreateBuilderTest.java index 56b62e2a8..987ac5652 100644 --- a/src/test/java/io/fabric8/maven/docker/service/BuildXServiceCreateBuilderTest.java +++ b/src/test/java/io/fabric8/maven/docker/service/BuildXServiceCreateBuilderTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -25,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; class BuildXServiceCreateBuilderTest { private BuildXService buildXService; @@ -60,6 +62,24 @@ void driverOptIsPresentIfProvided() throws Exception { verifyBuildXArgumentContains("--driver-opt", "network=foonet"); } + + + @Test + void builderPathWithLowerCasedBuilderName() throws Exception { + String builderName = "myTestBuilder"; + Path configPathSpy = Mockito.spy(configPath); + Path expectedPath = Paths.get("buildx","instances",builderName.toLowerCase()); + + //Given + buildConfigUsingBuildX(temporaryFolder,(buildX, buildImage) -> buildX.builderName(builderName)); + + // When + buildXService.createBuilder(configPathSpy, Arrays.asList("docker", "buildx"), imageConfig, buildDirs); + + // Then + verify(configPathSpy).resolve(expectedPath); + } + @Test void driverOptIsAbsentIfNotProvided() throws Exception { //Given