Skip to content

Commit 4df03f3

Browse files
authored
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
1 parent 94df38e commit 4df03f3

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- Docker-compose healthcheck configuration support ([1825](https://github.com/fabric8io/docker-maven-plugin/pull/1825))
55
- Docker container wait timeout default value made configurable using startContainerWaitTimeout configuration option ([1825](https://github.com/fabric8io/docker-maven-plugin/pull/1825))
66
- 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))
7-
7+
- 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))
88
* **0.45.1 (2024-09-29)**:
99
- Make copy docker-buildx binary to temporary config directory work on windows too ([1819](https://github.com/fabric8io/docker-maven-plugin/pull/1819))
1010
- Pull FROM images in relative path Dockerfiles ([1823](https://github.com/fabric8io/docker-maven-plugin/issues/1823))

src/main/java/io/fabric8/maven/docker/service/BuildXService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected String createBuilder(Path configPath, List<String> buildX, ImageConfig
280280
BuildXConfiguration buildXConfiguration = imageConfig.getBuildConfiguration().getBuildX();
281281
String builderName = Optional.ofNullable(buildXConfiguration.getBuilderName()).orElse("maven");
282282
String nodeName = buildXConfiguration.getNodeName();
283-
Path builderPath = configPath.resolve(Paths.get("buildx", "instances", builderName));
283+
Path builderPath = configPath.resolve(Paths.get("buildx", "instances", builderName.toLowerCase()));
284284
if(Files.notExists(builderPath)) {
285285
List<String> cmds = new ArrayList<>(buildX);
286286
append(cmds, "create", "--driver", "docker-container", "--name", builderName);

src/test/java/io/fabric8/maven/docker/service/BuildXServiceCreateBuilderTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.nio.file.Path;
20+
import java.nio.file.Paths;
2021
import java.util.Arrays;
2122
import java.util.Collections;
2223
import java.util.List;
@@ -25,6 +26,7 @@
2526
import static org.junit.jupiter.api.Assertions.assertFalse;
2627
import static org.junit.jupiter.api.Assertions.assertTrue;
2728
import static org.mockito.Mockito.mock;
29+
import static org.mockito.Mockito.verify;
2830

2931
class BuildXServiceCreateBuilderTest {
3032
private BuildXService buildXService;
@@ -60,6 +62,24 @@ void driverOptIsPresentIfProvided() throws Exception {
6062
verifyBuildXArgumentContains("--driver-opt", "network=foonet");
6163
}
6264

65+
66+
67+
@Test
68+
void builderPathWithLowerCasedBuilderName() throws Exception {
69+
String builderName = "myTestBuilder";
70+
Path configPathSpy = Mockito.spy(configPath);
71+
Path expectedPath = Paths.get("buildx","instances",builderName.toLowerCase());
72+
73+
//Given
74+
buildConfigUsingBuildX(temporaryFolder,(buildX, buildImage) -> buildX.builderName(builderName));
75+
76+
// When
77+
buildXService.createBuilder(configPathSpy, Arrays.asList("docker", "buildx"), imageConfig, buildDirs);
78+
79+
// Then
80+
verify(configPathSpy).resolve(expectedPath);
81+
}
82+
6383
@Test
6484
void driverOptIsAbsentIfNotProvided() throws Exception {
6585
//Given

0 commit comments

Comments
 (0)