Skip to content

Commit

Permalink
fix: error already existing instance due to case sensitive Path (#1847)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Amitrei authored Jan 10, 2025
1 parent 94df38e commit 4df03f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected String createBuilder(Path configPath, List<String> 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<String> cmds = new ArrayList<>(buildX);
append(cmds, "create", "--driver", "docker-container", "--name", builderName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4df03f3

Please sign in to comment.