Skip to content

Commit

Permalink
Pull FROM images in relative path Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jrnorth authored and rohanKanojia committed Sep 22, 2024
1 parent bd80572 commit 25e61bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private String extractBaseFromConfiguration(BuildImageConfiguration buildConfig)
}

static List<String> extractBaseFromDockerfile(BuildImageConfiguration buildConfig, MojoParameters mojoParameters, Map<String, String> buildArgs) {
if (buildConfig.getDockerFile() == null || !buildConfig.getDockerFile().exists()) {
if (buildConfig.getDockerFile() == null || !buildConfig.getAbsoluteDockerFilePath(mojoParameters).exists()) {
if (buildConfig.getFrom() != null && !buildConfig.getFrom().isEmpty()) {
return Collections.singletonList(buildConfig.getFrom());
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/io/fabric8/maven/docker/MojoTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ protected void givenMavenProject(AbstractDockerMojo mojo) {
mojo.project = mavenProject;
mojo.log = ansiLogger;
mojo.outputDirectory= "target/docker";
mojo.sourceDirectory = "src/main/docker";
mojo.authConfigFactory= authConfigFactory;
mojo.session = session;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -224,6 +225,38 @@ void testDockerfileWithBuildArgsInBuildConfig_ShouldPullImage() throws Exception
verifyImagePull(buildConfig, pullManager, buildContext, "sample/base-image:latest");
}

@Test
void testRelativeDockerfile_ShouldPullImage() throws Exception {
final BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder()
.cleanup("false")
.dockerFile("Dockerfile_from_simple")
.filter("false")
.build();

Mockito.when(mavenProject.getBasedir()).thenReturn(new File(getClass().getResource("/").getPath()));
Mockito.when(mojoParameters.getSourceDirectory()).thenReturn("io/fabric8/maven/docker/util");

buildConfig.initAndValidate(logger);

imageConfig = new ImageConfiguration.Builder()
.name("build-image")
.alias("build-alias")
.buildConfig(buildConfig)
.build();

final ImagePullManager pullManager = new ImagePullManager(null, null, null);
final BuildService.BuildContext buildContext = new BuildService.BuildContext.Builder()
.mojoParameters(mojoParameters)
.build();

mockMavenProject();

final File buildArchive = buildService.buildArchive(imageConfig, buildContext, "");
buildService.buildImage(imageConfig, pullManager, buildContext, buildArchive);

verifyImagePull(buildConfig, pullManager, buildContext, "fabric8/s2i-java");
}

@Test
void testBuildImagePullsDefaultImageWhenNoFromImage() throws Exception {
BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder()
Expand Down

0 comments on commit 25e61bf

Please sign in to comment.