Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respects network configuration for buildx #1850

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# ChangeLog

* **0.46-SNAPSHOT**:
- 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))

* **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))
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ private static void verifyImageNames(List<ImageConfiguration> ret) {
}
}

public static String getNetwork(ImageConfiguration imageConfig) {
String network = imageConfig.getBuildConfiguration().getNetwork();
if (network == null) {
network = System.getProperty("docker.network.mode");
}
if (network == null) {
network = System.getProperty("docker.build.network");
}
if(network!=null && network.isEmpty()) {
network = null;
}
return network;
}

public static boolean isNoCache(ImageConfiguration imageConfig) {
String noCache = System.getProperty("docker.noCache");
if (noCache == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ protected void buildX(List<String> buildX, String builderName, BuildDirs buildDi
cmdLine.add("--no-cache");
}

String networkMode = ConfigHelper.getNetwork(imageConfig);
if (networkMode!=null) {
cmdLine.add("--network="+networkMode);
}

BuildXConfiguration buildXConfiguration = buildConfiguration.getBuildX();
AttestationConfiguration attestations = buildXConfiguration.getAttestations();
if (attestations != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ void testBuildNativePlatformWithForeign() throws Exception {
verifyBuildXPlatforms(NATIVE);
}

@Test
void testNetworkIsPropagatedToBuildx() throws Exception {

//Given
buildConfigUsingBuildx(temporaryFolder, (buildX, buildImage) -> buildImage.network("host"));

// When
buildx.build(projectPaths, imageConfig, configuredRegistry, authConfigList, buildArchive);

//Then
verifyBuildXArgumentPresentInExec("--network=host");
}

@Test
void testNoCacheIsPropagatedToBuildx() throws Exception {

Expand Down
Loading