|
26 | 26 | import java.time.Duration; |
27 | 27 | import java.util.Arrays; |
28 | 28 | import java.util.List; |
| 29 | +import java.util.Objects; |
29 | 30 | import java.util.Optional; |
30 | 31 | import java.util.concurrent.TimeUnit; |
31 | 32 |
|
32 | 33 | import com.github.dockerjava.api.command.ListImagesCmd; |
33 | 34 | import com.github.dockerjava.api.command.PullImageCmd; |
34 | 35 | import com.github.dockerjava.api.command.SaveImageCmd; |
| 36 | +import com.github.dockerjava.api.model.Bind; |
| 37 | +import com.github.dockerjava.api.model.HostConfig; |
35 | 38 | import com.github.dockerjava.api.model.Image; |
36 | 39 | import org.apache.commons.logging.Log; |
37 | 40 | import org.apache.commons.logging.LogFactory; |
@@ -90,9 +93,8 @@ private Commons() { |
90 | 93 | public static final String TEMP_FOLDER = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath(); |
91 | 94 |
|
92 | 95 | private static final K3sContainer CONTAINER = new FixedPortsK3sContainer(DockerImageName.parse(Commons.RANCHER)) |
93 | | - .configureFixedPorts(EXPOSED_PORTS) |
94 | | - .withFileSystemBind(TEMP_FOLDER, TEMP_FOLDER) |
95 | | - .withFileSystemBind(TMP_IMAGES, TMP_IMAGES) |
| 96 | + .configureFixedPorts() |
| 97 | + .addBinds() |
96 | 98 | .withCommand(Commons.RANCHER_COMMAND) |
97 | 99 | .withReuse(true); |
98 | 100 |
|
@@ -331,13 +333,23 @@ private FixedPortsK3sContainer(DockerImageName dockerImageName) { |
331 | 333 | super(dockerImageName); |
332 | 334 | } |
333 | 335 |
|
334 | | - private FixedPortsK3sContainer configureFixedPorts(int[] ports) { |
335 | | - for (int port : ports) { |
| 336 | + private FixedPortsK3sContainer configureFixedPorts() { |
| 337 | + for (int port : Commons.EXPOSED_PORTS) { |
336 | 338 | super.addFixedExposedPort(port, port); |
337 | 339 | } |
338 | 340 | return this; |
339 | 341 | } |
340 | 342 |
|
| 343 | + private FixedPortsK3sContainer addBinds() { |
| 344 | + super.withCreateContainerCmdModifier(cmd -> { |
| 345 | + HostConfig hostConfig = Objects.requireNonNull(cmd.getHostConfig()); |
| 346 | + hostConfig.withBinds(Bind.parse(TEMP_FOLDER + ":" + TEMP_FOLDER), |
| 347 | + Bind.parse(TMP_IMAGES + ":" + TMP_IMAGES)); |
| 348 | + }); |
| 349 | + |
| 350 | + return this; |
| 351 | + } |
| 352 | + |
341 | 353 | } |
342 | 354 |
|
343 | 355 | } |
0 commit comments