Polish "Add network option for image building"

See gh-27486
This commit is contained in:
Scott Frederick
2021-08-12 17:07:49 -05:00
parent 8e6d03b221
commit 2178c281e9
13 changed files with 145 additions and 23 deletions

View File

@@ -265,6 +265,12 @@ public class BuildRequest {
this.network);
}
/**
* Return a new {@link BuildRequest} with an updated network setting.
* @param network the network the build container will connect to
* @return an updated build request
* @since 2.6.0
*/
public BuildRequest withNetwork(String network) {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
@@ -371,6 +377,11 @@ public class BuildRequest {
return this.bindings;
}
/**
* Return the network the build container will connect to.
* @return the network
* @since 2.6.0
*/
public String getNetwork() {
return this.network;
}

View File

@@ -148,7 +148,9 @@ class Lifecycle implements Closeable {
this.request.getBindings().forEach(phase::withBinding);
}
phase.withEnv(PLATFORM_API_VERSION_KEY, this.platformVersion.toString());
phase.withNetworkMode(this.request.getNetwork());
if (this.request.getNetwork() != null) {
phase.withNetworkMode(this.request.getNetwork());
}
return phase;
}

View File

@@ -104,6 +104,10 @@ class Phase {
this.env.put(name, value);
}
/**
* Update this phase with the network the build container will connect to.
* @param networkMode the network
*/
void withNetworkMode(String networkMode) {
this.networkMode = networkMode;
}
@@ -134,7 +138,9 @@ class Phase {
update.withLabel("author", "spring-boot");
this.bindings.forEach(update::withBinding);
this.env.forEach(update::withEnv);
update.withNetworkMode(this.networkMode);
if (this.networkMode != null) {
update.withNetworkMode(this.networkMode);
}
}
}

View File

@@ -188,6 +188,11 @@ public class ContainerConfig {
this.env.put(name, value);
}
/**
* Update the container config with the network that the build container will
* connect to.
* @param networkMode the network
*/
public void withNetworkMode(String networkMode) {
this.networkMode = networkMode;
}

View File

@@ -57,7 +57,6 @@ class PhaseTests {
phase.apply(update);
verify(update).withCommand("/cnb/lifecycle/test", NO_ARGS);
verify(update).withLabel("author", "spring-boot");
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}
@@ -71,7 +70,6 @@ class PhaseTests {
verify(update).withBinding(Binding.from("/var/run/docker.sock", "/var/run/docker.sock"));
verify(update).withCommand("/cnb/lifecycle/test", NO_ARGS);
verify(update).withLabel("author", "spring-boot");
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}
@@ -83,7 +81,6 @@ class PhaseTests {
phase.apply(update);
verify(update).withCommand("/cnb/lifecycle/test", "-log-level", "debug");
verify(update).withLabel("author", "spring-boot");
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}
@@ -95,7 +92,6 @@ class PhaseTests {
phase.apply(update);
verify(update).withCommand("/cnb/lifecycle/test");
verify(update).withLabel("author", "spring-boot");
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}
@@ -107,7 +103,6 @@ class PhaseTests {
phase.apply(update);
verify(update).withCommand("/cnb/lifecycle/test", "a", "b", "c");
verify(update).withLabel("author", "spring-boot");
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}
@@ -121,7 +116,6 @@ class PhaseTests {
verify(update).withCommand("/cnb/lifecycle/test");
verify(update).withLabel("author", "spring-boot");
verify(update).withBinding(Binding.from(volumeName, "/test"));
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}
@@ -136,7 +130,6 @@ class PhaseTests {
verify(update).withLabel("author", "spring-boot");
verify(update).withEnv("name1", "value1");
verify(update).withEnv("name2", "value2");
verify(update).withNetworkMode(null);
verifyNoMoreInteractions(update);
}