|
30 | 30 | import java.util.List; |
31 | 31 | import java.util.Map; |
32 | 32 | import java.util.Map.Entry; |
| 33 | +import java.util.Objects; |
33 | 34 | import java.util.Optional; |
34 | 35 | import java.util.Set; |
35 | 36 | import java.util.concurrent.CompletableFuture; |
@@ -96,6 +97,8 @@ public class AdvancedImageFromDockerFile |
96 | 97 | protected Optional<Path> baseDir = Optional.empty(); |
97 | 98 | protected Optional<Path> baseDirRelativeIgnoreFile = Optional.of(Paths.get(".gitignore")); |
98 | 99 | protected List<String> additionalIgnoreLines = new ArrayList<>(); |
| 100 | + protected boolean alwaysTransferDockerfilePath = true; |
| 101 | + protected Set<Path> alwaysTransferPaths = Set.of(); |
99 | 102 | protected Optional<String> target = Optional.empty(); |
100 | 103 | protected final Set<Consumer<BuildImageCmd>> buildImageCmdModifiers = new LinkedHashSet<>(); |
101 | 104 | protected Set<String> externalDependencyImageNames = Collections.emptySet(); |
@@ -326,7 +329,16 @@ protected void configure(final BuildImageCmd buildImageCmd) |
326 | 329 | final TransferFilesCreator tfc = |
327 | 330 | new TransferFilesCreator(this.baseDir.get(), this.baseDirRelativeIgnoreFile.orElse(null)); |
328 | 331 |
|
329 | | - final List<Path> filesToTransfer = tfc.getFilesToTransfer(this.additionalIgnoreLines); |
| 332 | + final Set<Path> alwaysIncludePaths = new HashSet<>(this.alwaysTransferPaths); |
| 333 | + if(this.alwaysTransferDockerfilePath) |
| 334 | + { |
| 335 | + final Path determinedDockerfilePath = this.dockerFilePath.orElse(Path.of("Dockerfile")); |
| 336 | + alwaysIncludePaths.add(this.baseDir |
| 337 | + .map(basePath -> basePath.relativize(determinedDockerfilePath)) |
| 338 | + .orElse(determinedDockerfilePath)); |
| 339 | + } |
| 340 | + |
| 341 | + final List<Path> filesToTransfer = tfc.getFilesToTransfer(this.additionalIgnoreLines, alwaysIncludePaths); |
330 | 342 |
|
331 | 343 | this.log().info("{}x files will be transferred", filesToTransfer.size()); |
332 | 344 | if(this.log().isDebugEnabled()) |
@@ -472,6 +484,18 @@ public AdvancedImageFromDockerFile withAdditionalIgnoreLines(final String... add |
472 | 484 | return this; |
473 | 485 | } |
474 | 486 |
|
| 487 | + public AdvancedImageFromDockerFile withAlwaysTransferPaths(final Set<Path> alwaysTransferPaths) |
| 488 | + { |
| 489 | + this.alwaysTransferPaths = new HashSet<>(Objects.requireNonNull(alwaysTransferPaths)); |
| 490 | + return this; |
| 491 | + } |
| 492 | + |
| 493 | + public AdvancedImageFromDockerFile withAlwaysTransferDockerfilePath(final boolean alwaysTransferDockerfilePath) |
| 494 | + { |
| 495 | + this.alwaysTransferDockerfilePath = alwaysTransferDockerfilePath; |
| 496 | + return this; |
| 497 | + } |
| 498 | + |
475 | 499 | public AdvancedImageFromDockerFile withTarget(final String target) |
476 | 500 | { |
477 | 501 | this.target = Optional.of(target); |
|
0 commit comments